Hello everyone
I want to understand programming of external interrupts in 8051. I want use external interrupt for LED .Whenever interrupt occur the LED should be On/ off, depending upon the input switch at pin P3.2.if switch is high the LED should be turn ON, when switch is low LED should be off.
I have written this program. what should be in main function for proper working ?
I want to understand programming of external interrupts in 8051. I want use external interrupt for LED .Whenever interrupt occur the LED should be On/ off, depending upon the input switch at pin P3.2.if switch is high the LED should be turn ON, when switch is low LED should be off.
I have written this program. what should be in main function for proper working ?
C:
#include<reg51.h>
// LED Pin
sbit LED = P1^0; // Pin P1.0 is named as LED
//Function declarations
void init(void);
void InitINT0(void);
// Init function
void init(void)
{
P0 = 0x00; // Make all pins zero
P1 = 0x00; // Make all pins zero
P2 = 0x00; // Make all pins zero
P3 = 0x04; // Make P3.2 (INT0) pin high only
}
// External INT0 pin interrupt init function
void InitINT0(void)
{
IT0 = 1; //Edge triggered interrupt mode (Neg Edge)
EX0 = 1; //Enable external interrupt INT0
EA = 1; //Enable global interrupts
}
// INT0 ISR
void external0_isr(void) interrupt 0
{
LED = ~LED; // Toggle LED pin
}
// Main function
void main(void)
{
while(1)
{
}
}