Wrote a half-day off the line ...
Not written on the definition ...
What is interrupt interrupt means that the CPU in the process of executing the current program, because of some random peripheral request or internal CPU abnormal events, so that the CPU suspends the executing program and go to execute the corresponding service handler; When the service handler finishes running, the CPU returns to the halt and resumes execution of the original program. 51 single-Chip interrupt 80c51 provides 5 interrupt sources, respectively: 2 external interrupts, 2 Timer/Counter interrupts, and 1 serial port Send/Receive interrupts. and has 2 interrupt priority level, can achieve Level 2 Interrupt service program nesting.
The first thing to do is interrupt the setup, the interrupt schematic is as follows:
To set INT0 as an example: it0=1;ex0=1;
Finally open the total interrupt ea=1;
:
2 external interrupts are connected p3.2 p3.3 namely Switch K3 K4, that is, press switch K3 to external interrupt 0 program, press switch K4 go to external interrupt 1 program
/******************************************************************************** Experiment Name: External interrupt experiment * IO used: External interrupt 0 using P3.2 External interrupt 1 using the P3.3 led using the p2* experiment effect: Press K3 led left to shift K4 LED right Shift * Note: *********************************************************** /#include <reg52.h> #include <intrins.h> #define gpio_led p2#define gpio_dig p0#define Gpio_key p1#define UINT unsigned int#define uchar unsigned charvoid delay10ms (); void Intconfiguration (); Sbit k3=p3^2; Sbit k4=p3^3;sbit lsa=p2^2;sbit lsb=p2^3;sbit lsc=p2^4;uchar code dig_code[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};uchar value=0;void Main () {uint n=10;intconfiguration (); Gpio_led=0xfe;while (1) {if (Value) Gpio_led=_crol_ (gpio_led,1); Elsegpio_led=_cror_ (gpio_led,1); while (n--) Delay10ms (); n=10;}} void Delay10ms () {Uchar i=38,j=130; while (i--) while (j--);} void Intconfiguration () {//set int0it0=1; ex0=1;//setting int1it1=1; ex1=1;//Open total interrupt ea=1;} void Int0 () interrupt 0{delay10ms ();if (k3==0) value=1;} void Int1 () interrupt 2{delay10ms (); if (k4==0) value=0;}
51 single-chip computer fifth bullet---external interrupt