51 MCU Experiment 10: Timer Interrupt

Publisher:ikfnpoLatest update time:2020-04-26 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Purpose: To control the delay through the timer interrupt to reverse the state of the first LED


The circuit diagram of the development board MUC and LED module is as follows:

For the key points about timers and counters, please refer to: https://blog.csdn.net/cax1165/article/details/86659302


For the key points about interruption, please refer to: https://blog.csdn.net/cax1165/article/details/86633086


#include

#define uc unsigned char

sbit led=P2^0;

void timeint0()

{

TMOD=0X01; //Working mode

TH0=0XFC; //Timing 1ms

TL0=0X18; //timing 1ms

TR0=1;//control

ET0=1; //Timer 0 interrupt request

EA=1; //Total interrupt

}

void time0int () interrupt 1 //Note the interrupt number

{

static int i=0;//Note the use of static variables!

TH0=0XFC; //Timer reset

TL0=0X18; //Timer reset

i++;

if(i==1000) //1000 1ms make up 1s

{

i=0;

led=~led; //led state inversion

}

}

void main()

{

timeint0();

while(1);

}

Reference address:51 MCU Experiment 10: Timer Interrupt

Previous article:51 MCU Experiment 11: Serial Communication
Next article:51 MCU resources - EEPROM (IIC bus)

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号