Timer/Counter 0 (Counter)

Publisher:Huayu8888Latest update time:2024-08-15 Source: elecfansKeywords:Timer Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*

Effect description:

Counter interrupt: program execution through external count

Press the interrupt button once, the upper four bits will light up when the interrupt occurs, and the program will return to the main program after the interrupt occurs.


*/

#include

#include

unsigned int i;

void delay()//delay sub-function

{

i=50000;

while(i--);

}

//unsigned char TCOM;


//Interrupt initialization

void center1()

{

ET0 = 1; //Start the counter interrupt switch

EA = 1; // Main switch

/*

The core of the counter is here

*/

TH0 = 255; // press once to interrupt

TL0 = 255;

TMOD = 0x05; //0000 0101 in counter mode

TR0 = 1; //Start the timer

}

void main()//main function

{

zhongduan1(); //Interrupt initialization

while(1) //while infinite loop, the main program keeps executing, that is, the lower four bits are always on, when an interrupt occurs, the interrupt function program is executed, and after the interrupt occurs, it returns to the main program

{

P0 = 0xf0; //light up the lower four bits

}

}

//The interrupt program is the program to be executed after the interrupt

void zhongduan() interrupt 1

{

P0 = ~0xf0; //high four bits are bright

delay(); //delay sub-function call is converted into the time to execute the program when the interrupt occurs

TH0 = 255;

TL0 = 255;

}

57cbf0b222068081f1b1f05b4c07d17c_1047760-20170523152739382-374665970.png


52baa0cea7a7e9a2c5c6f7178bfd8561_1047760-20170523152755288-1356039775.png

Keywords:Timer Reference address:Timer/Counter 0 (Counter)

Previous article:Timer/Counter 0 (Timer)
Next article:80C31 MCU external interrupt 0

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号