Department of Computer Science and Information EngineeringNational Cheng Kung University, TAIWAN
HANEL
PROGRAMMINGTIMERSMode 1 Programming Steps to Mode 1 Program(cont’)
Example 9-4 (cont’)DELAY:
SETB TR0 ;start the timer 0
AGAIN: JNB TF0,AGAIN ;monitor timer flag 0;until it rolls overCLR TR0 ;stop timer 0CLR TF0 ;clear timer 0 flagRET- The DELAY subroutine using the timer is called.5. In the DELAY subroutine, timer 0 is started by the
SETB TR0instruction.- Timer 0 counts up with the passing of
each clock, which is provided by thecrystal oscillator. As the timer counts up, it goes through the states of FFF3, FFF4, FFF5, FFF6,FFF7, FFF8, FFF9, FFFA, FFFB,and so on until itreaches FFFFH. One more clock rolls itto 0, raising the timer flag (TF0=1).At that point, the JNB instruction falls through.- Timer 0 is stopped by the instruction
CLR TR0. The DELAY subroutine
ends, and the process is repeated.Notice that to repeat the process, we must reload the TL and TH registers, andstart the process is repeated...FFF2FFFFFFF4
FFF30000TF=0TF=0TF=0
TF=0TF=1