The C51 microcontroller external interrupt calls P3_2 and P3_3 ports.
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); } }
Previous article:Interrupts and timers of 51 single-chip microcomputer (STC89C52)
Next article:C-51 single chip dynamic display 01234567
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Experience in solving audio signal ground noise based on BA3121
- ESP32S3 ubuntu+vscode environment construction and use internal USB-JTAG (builtin) debugging program
- 【GD32L233C-START review】+P9813_RGBLED test【3】
- Liquid Level Measurement System Based on Single Chip Microcomputer
- UART emulation LIN problem
- Floating point issues with MicroPython
- Apple allows employees to discuss salaries publicly, sparking heated debate. Do you know how much your colleagues earn?
- Current control circuit
- Review summary: TI LAUNCHXL-CC1352P-4
- DE1-SOC development board usage learning