Timing counter T0 is used as timing technology

Publisher:巳午未Latest update time:2021-04-21 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Circuit diagram



Figure 4.16.1


2. System board hardware connection


(1. Connect P1.0-P1.3 in the "MCU System" area to L1-L4 in the "Eight-way LED Indicator Module" area with wires.


3. Programming content


(1. Since the interrupt method is used, the interrupt source must have its interrupt entry address. For the timer/counter T0, the interrupt entry address is 000BH, so a long jump instruction is added to the interrupt entry to execute the interrupt service program. The format of writing the assembly source program is as follows:


ORG00H


LJMPSTART


ORG0BH ;Timer/Counter T0 interrupt entry address


LJMP INT_T0


START: NOP ; Main program starts


.


.




INT_T0: PUSH ACC; Timer/Counter T0 interrupt service routine


PUSH PSW


.


.


POP PSW


POP ACC


RETI ;Interrupt service routine returns


END


(2. Timing for 2 seconds, using 16-bit timing of 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, for a timing of 0.2 seconds, 4 times are required 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


4. Flowchart


T0 interrupt service program block diagram



  



















Main program block diagram

 









































Figure 4.16.2


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


6. C language source program


#include




unsigned char tcount2s;


unsigned char tcount02s;


unsigned char ID;




void main(void)


{


TMOD=0x01;


TH0=(65536-50000)/256;


TL0=(65536-50000)%6;


TR0=1;


ET0=1;


EA=1;




while(1);


}


void t0(void) interrupt 1 using 0


{


tcount2s++;


if(tcount2s==40)


{


tcount2s=0;


ID++;


if(ID==4)


{


ID=0;


}


}


tcount02s++;


if(tcount02s==4)


{


tcount02s=0;


switch(ID)


{


case 0:


P1_0=~P1_0;


break;


case 1:


P1_1=~P1_1;


break;


case 2:


P1_2=~P1_2;


break;


case 3:


P1_3=~P1_3;


break;


}


}


Reference address:Timing counter T0 is used as timing technology

Previous article:Resistance-temperature measurement system of carbon black composite conductive material based on 51 single chip microcomputer
Next article:Circuit module design of intelligent transformer temperature monitoring instrument

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号