AT89C51 MCU external interrupt

Publisher:meilidaowlLatest update time:2022-06-07 Source: eefocusKeywords:AT89C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The C51 microcontroller external interrupt calls P3_2 and P3_3 ports.

insert image description here

There are two interrupt modes: level mode and pulse mode.

The interrupt request has 0 and 1. The interrupt is always enabled when EA=1.

IE0: external interrupt request 0 flag;

IT0: External interrupt 0 trigger mode setting bit, IT0=1 falling edge trigger, IT0=0 low level trigger;

IE1: External interrupt request 1 flag;

IT1: External interrupt 1 trigger mode setting bit, IT1=1 falling edge trigger, IT1=0 low level trigger;

Writing of external interrupt 0 interrupt service program:


void function name () interrupt 0

{


}


Writing of external interrupt 1 interrupt service program:


void function name () interrupt 2

{


}


Refer to the experimental program (the main program is the P1 port output marquee program), write an interrupt subroutine so that when external interrupt 0 occurs and it is triggered at a low level, all LED lights are on. After the interrupt ends, the LED continues to flash in the last state.


#include

#include

sbit P3_2=P3^2;

void delay(unsigned char i);

void main()

{

unsigned char ii;

P1=0xFE;

P3_2=1;

EA=1;

EX0=1;

IT0=0;

while(1)

{

P1=0xFE;

for(ii=0;ii<8;ii++)

{

P1=_crol_(P1,1);

delay(200);

}

}

}

void delay(unsigned char i) //delay function, unsigned character type variable i is the formal parameter

{

unsigned char j,k; //define unsigned character type variables j and k

for(k=0;k for(j=0;j<255;j++);

}

void int_0() interrupt 0

{

P1=0x00;

}


Refer to the experimental program (the main program is the P1 port output marquee program). When external interrupt 1 occurs and it is triggered by a low level, the LED flashes 5 times. After the interrupt ends, the LED continues to flash as in the last state.


#include

#include

sbit P3_3=P3^3;

void delay(unsigned char i);

void main()

{

unsigned char ii;

P1=0xFE;

P3_2=1;

EA=1;

EX1=1;

IT1=0;

while(1)

{

P1=0xFE;

for(ii=0;ii<8;ii++)

{

P1=_crol_(P1,1);

delay(200);

}

}

}


void delay(unsigned char i) //delay function, unsigned character type variable i is the formal parameter

{

unsigned char j,k; //define unsigned character type variables j and k

for(k=0;k for(j=0;j<255;j++);

}

void int_1() interrupt 2

{

unsigned char a;

for(a=0;a<5;a++)

{

P1=0x00;

delay(200);

P1=0xff;

delay(200);

}

}


Refer to the experimental program (the main program is the P1 port output marquee program), and write an interrupt subroutine so that when external interrupt 0 occurs and is triggered by a low level, all LED lights are on. After the interrupt ends, the LED continues to flash as in the last state with a marquee; when external interrupt 1 occurs and is triggered by a low level, the LED lights flash 5 times. After the interrupt ends, the LED continues to flash as in the last state with a marquee.


#include

#include

sbit P3_2=P3^2;

sbit P3_3=P3^3;

void delay(unsigned char i);

void main()

{

unsigned char ii;

P1=0xFE;

P3_2=1;

EA=1;

EX0=1;

IT0=0;

EX1=1;

IT1=0;

while(1)

{

P1=0xFE;

for(ii=0;ii<8;ii++)

{

P1=_crol_(P1,1);

delay(200);

}

}

}


void delay(unsigned char i) //delay function, unsigned character type variable i is the formal parameter

{

unsigned char j,k; //define unsigned character type variables j and k

for(k=0;k for(j=0;j<255;j++);

}

void int_0() interrupt 0 //0 trigger

{

P1=0x00;

}

void int_1() interrupt 2 //1 trigger

{

unsigned char a;

for(a=0;a<5;a++)

{

P1=0x00;

delay(200);

P1=0xff;

delay(200);

}

}

insert image description here

Keywords:AT89C51 Reference address:AT89C51 MCU external interrupt

Previous article:Interrupts and timers of 51 single-chip microcomputer (STC89C52)
Next article:C-51 single chip dynamic display 01234567

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号