Timing Counter T0 Timing Application Technology (Part 2)
[Copy link]
1. Experimental tasks The AT89S51 timer/counter T0 generates a 2-second timer. When the 2-second timer comes, the indicator light flashes. The frequency of each indicator flashing is 0.2 seconds. That is to say, the L1 indicator light flashes at a rate of 0.2 seconds at the beginning. When the 2-second timer comes, L2 starts to flash at a rate of 0.2 seconds, and so on. The flashing rate of 0.2 seconds is also completed by the timer/counter T0. 2. Circuit diagram
3. System board hardware connection (1) The hardware settings are the same as in many previous tests. Please set them yourself . (2) Pay attention to whether the I/O ports in the program are consistent with the hardware settings. 4. Program design content (1. Since the interrupt method is used, the interrupt source must have its interrupt entry address. For timer/counter T0, the interrupt entry address is 000BH, so a long jump instruction is added at the interrupt entry to execute the interrupt service program. The format of writing the assembly source program is as follows: ORG 00H LJMP START ORG 0BH; Timer/counter T0 interrupt entry address LJMP INT_T0 START: NOP; Main program starts . . INT_T0: PUSH ACC; Timer/counter T0 interrupt service program PUSH PSW . . POP PSW POP ACC RETI; Interrupt service program returns END (2. Timing for 2 seconds, using 16-bit timing for 50ms, a total of 40 times of timing can reach 2 seconds, an interrupt is generated every 50ms, and the 40 times of timing are completed in the interrupt service program. Similarly, 0.2 seconds of timing requires 4 times to reach 0.2 seconds. For the interrupt program, the interrupt must be disconnected in the main program. (3. Since each 2-second timer expires, L1-L4 flash alternately. Use ID to identify. When ID = 0, L1 flashes; when ID = 1, L2 flashes; when ID = 2, L3 flashes; when ID = 3, L4 flashes 5. Assembly source program TCOUNT2S EQU 30H TCNT02S EQU 31H ID EQU 32H ORG 00H LJMP START ORG 0BH LJMP INT_T0 START: MOV TCOUNT2S,#00H MOV TCNT02S,#00H MOV ID,#00H MOV TMOD,#01H MOV TH0,#(65536-50000) / 256 MOV TL0,#(65536-50000) MOD 256 SETB TR0 SETB ET0 SETB EA SJMP $ INT_T0: MOV TH0,#(65536-50000) / 256 MOV TL0,#(65536-50000) MOD 256 INC TCOUNT2S MOV A,TCOUNT2S CJNE A,#40,NEXT MOV TCOUNT2S,#00H INC ID MOV A,ID CJNE A,#04H,NEXT MOV ID,#00H NEXT: INC TCNT02S MOV A,TCNT02S CJNE A,#4,DONE MOV TCNT02S,#00H MOV A,ID CJNE A,#00H,SID1 CPL P1.0 SJMP DONE SID1: CJNE A,#01H,SID2 CPL P1.1 SJMP DONE SID2: CJNE A,#02H,SID3 CPL P1.2 SJMP DONE SID3: CJNE A,#03H,SID4 CPL P1.3 SID4: SJMP DONE DONE: RETI END
|