External interrupt 0/1

Publisher:平静宁静Latest update time:2024-08-15 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

External interrupt 0 or 1 is essentially the same, only EX and IT are changed to 0 or 1.

Q: So the question is: Why do we have two very similar external interrupts 0 or 1?

A: When there are two external interrupts, if there is only one external interrupt,

Then when one interrupt handles two external interrupts, its CPU processing is not accurate enough.

Therefore, we need to open another channel to handle external interrupts.

Q: What if there are three external interrupts?

A: This is the limitation of the microcontroller. Haha~~ But the flight control has many interrupts


#include

/*

* External interrupt 0

*/

sbit LED = P2^0; //bit declaration

//Register initialization function

void kinson()

{

EX0 = 1; // External interrupt 0 switch

EA = 1; //Interrupt the main switch

IT0 = 1; //External interrupt 0 trigger mode: 0 is level, 1 is falling edge //The timer is to be started

}

//Main function

void main(void)

{

kinson(); //Calling the register initialization function

while(1); //Let the program loop infinitely here

}


//Interrupt

void xjx() interrupt 0 //The interrupt number of external interrupt 0 is 0, and the interrupt number of external interrupt 1 is 2

{

LED = ~LED; //The LED turns on and off because of each interrupt

}


#include

/*

* External interrupt 1

*/

sbit LED = P2^0; //bit declaration

//Register initialization function

void kinson()

{

EX1 = 1; // External interrupt 0 switch

EA = 1; //Interrupt the main switch

IT1 = 1; //External interrupt 0 trigger mode: 0 is level, 1 is falling edge //The timer is to be started

}

//Main function

void main(void)

{

kinson(); //Calling the register initialization function

while(1); //Let the program loop infinitely here

}


//Interrupt

void xjx() interrupt 2 //The interrupt number of external interrupt 0 is 0, and the interrupt number of external interrupt 1 is 2

{

LED = ~LED; //The LED turns on and off because of each interrupt

}


Reference address:External interrupt 0/1

Previous article:LCD with character display I LOVE YOU
Next article:Digital tube buttons plus or minus one

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号