Department of Computer Science and Information EngineeringNational Cheng Kung University, TAIWAN
HANEL
PROGRAMMINGTIMERSMode 1 Programming Steps to Mode 1 Program(cont’)
Example 9-6In Example 9-5, calculate the frequency of the square wave generated on pin P1.5.Solution:In the timer delay calculation of Ex
ample 9-5, we did not include theoverhead due to instruction in the loop. To get a more accurate timing, we need to add clock cycles due tothis instructions in the loop. To dothat, we use the machine cycle from Table A-1 in Appendix A, as shown below.CyclesHERE: MOV TL0,#0F2H 2MOV TH0,#0FFH 2CPL P1.5 1ACALL DELAY 2SJMP HERE 2
DELAY:SETB TR0 1
AGAIN: JNB TF0,AGAIN 14CLR TR0 1CLR TF0 1RET 2Total28T = 2×^28
×1.085 us = 60.76 us and F = 16458.2 Hz