External Interrupt 1 in 8051/At 89c51
External interrupt 1 interfacing program using 8051/AT89c51 .Here I am explaining in this program how to handle external interrupt 1 in 8051/AT89c51 .The main file of program is shown in image below :-
In hardware I have connected a button at PIN number 13 of controller because that pin is assigned to external interrupt 1.i also connected a LED at Pin number 21 of controller to indicate that external interrupt is working fine. Here one side of switch is connected to pin number 13 and the other side is connected to ground so whenever you press the switch the voltage at pin number 13 becomes 0 and a falling edge will occur.
So in above program if you pressed switch which is connected to external interrupt PIN 13 of micro controller then a falling edge will capture by controller and external interrupt 1 occur which is taken care by the interrupt function “void EXT_1_ISR (void) interrupt 2”and variable i will gets incremented. If you pressed it 5 times then LED which is connected to pin 21 of controller goes ON and again if you pressed it for 5 times then LED will goes off. To configure the external 1 interrupt I have called a function named “EXT_INT1_INI()” . Complete function explanation is given in below image:-
In this function firstly I have configure the falling edge capturing by setting IT1 bit high in TCON register and then after I have enable the interrupt by setting EA bit and EX1 bit high in IE register which is given below.
IE Register
Bit 7
|
Bit 6
|
Bit 5
|
Bit 4
|
Bit 3
|
Bit 2
|
Bit 1
|
Bit 0
|
EA
|
Reserved
|
Reserved
|
ES
|
ET1
|
EX1
|
ET0
|
EX0
|
In while loop I have define a logic that, if interrupt occur 5 times then LED will toggle.
Also “ext1_ini.h” file is explained in image below which is included in main file.
Download Link
For downloading complete code click here. it is free of cost.
No comments:
Post a Comment