.equ frqflg,0fh freq: .org 000h mov sp,#30h sjmp over ; ;T1 will overflow and the T1 Interrupt flag will cause the program ;to vector to this address. R0 and R1 of register bank 1 are used to ;count from 0000d to 1,000d. R0 is the least significant byte ;counter, R1 the most significant byte counter. When the count ;reaches 1,000d, or 03E8H, then "frqflg", the main program flag, is ;set, and the timers stopped. 12 cycles (12 usec for this example) ;are required to stop T0, or from 1 additional count at 83,333Hz ;to 6 false counts at 500,000 Hz. ; usec .org 001bh ;T1 overflow flag interrupt to here 3 setb psw.3 ;switch to register bank 1 1 inc r0 ;count R0 up until overflow at 00h 1 cjne r0,#00h,checktime ;check to see if time is up 2 inc r1 ;or increment R1 when R0 rolls over ; checktime: cjne r1,#03h,goback ;check R1 for terminal count 2 cjne r0,#0e8h,goback ;check R0 for terminal count 2 clr tr0 ;stop T0 ; clr tr1 ;stop T1 Time before T0 stopped = 12 setb frqflg ;signal main program that T0 = frequency ; goback: clr psw.3 ;return to bank 0 registers reti ;return to main program ; ;The main program sets up T0 to count external pulses, and T1 to ;count 100 microseconds in the autoreload mode 2. The main program ;flag, frqflg, is then monitored by the main program until it is ;set. When frqflg is set, the main program displays the unknown ;frequency (divided by 10) on P1 (LSB) and P2 (MSB). ; over: mov tcon,#00h ;All timers stopped - flags reset setb psw.3 ;select register bank1 and reset R0, R1 mov r0,#00h mov r1,#00h clr psw.3 ;return to bank 0 mov tmod,#25h ;T1 a mode 2 timer; T0 a mode 1 counter mov tl1,#9ch ;start TL1 at 9CH mov th1,#9ch ;TH1 = 156d, overflows in 100 clocks mov tl0,#00h ;zero T0 mov th0,#00h clr frqflg ;reset the frequency measured flag mov tcon,#50h ;start timer T1 and counter T0 mov ie,#88h ;enable global and T1 overflow interrupts simulate: jbc frqflg,getfrq ;have main program test "frqflg" sjmp simulate ;loop here until frequency is measured getfrq: mov p1,tl0 ;show frequency count (in hex) on P1 & P2 mov p2,th0 sjmp over ;make next measurement .end