How to Use External Interrupt-0 in AT89C1051
The following code demonstrate, how to configure INT0 (external interrupt 0) to generate an interrupt on the falling-edge of INT0 (P3.2). Each time port 3.2 goes low, the port-1 is incremented by 1. The code is written in Keil uVision2 IDE and simulation is done with Proteus 8.0. At the end of code, you can find complete project files for download.
Code Using Keil uVision2
#include
#include
// proto-types
void ConfigExInterrupt0(void);
void ConfigUART(void);
void Delayms(unsigned int x_time);
// port and pin labling
sfr COUNT_PORT = 0x90;
sbit LED = P3^0;
// external interrupt-0 isr
unsigned char ex0_isr_counter = 0;
#include
// proto-types
void ConfigExInterrupt0(void);
void ConfigUART(void);
void Delayms(unsigned int x_time);
// port and pin labling
sfr COUNT_PORT = 0x90;
sbit LED = P3^0;
// external interrupt-0 isr
unsigned char ex0_isr_counter = 0;
void ex0_isr(void) interrupt 0
{
// Increment the count
COUNT_PORT = ++ex0_isr_counter;
}
{
// Increment the count
COUNT_PORT = ++ex0_isr_counter;
}
void main(void)
{
// make port as output
COUNT_PORT = 0x00;
// make pin as output
LED = 0;
// config interrupt-0
ConfigExInterrupt0();
while(1)
{
LED = ~LED;
Delayms(300);
}
}
void ConfigExInterrupt0(void)
{
// Configure interrupt 0 for falling edge on /INT0 (P3.2)
IT0 = 1;
// Enable EX0 Interrupt
EX0 = 1;
// Enable Global Interrupt Flag
EA = 1;
}
void Delayms(unsigned int x_time)
{
unsigned int x,y;
for(x=0;x<x_time;x++)
for(y=0;y<122;y++);
}
{
// make port as output
COUNT_PORT = 0x00;
// make pin as output
LED = 0;
// config interrupt-0
ConfigExInterrupt0();
while(1)
{
LED = ~LED;
Delayms(300);
}
}
void ConfigExInterrupt0(void)
{
// Configure interrupt 0 for falling edge on /INT0 (P3.2)
IT0 = 1;
// Enable EX0 Interrupt
EX0 = 1;
// Enable Global Interrupt Flag
EA = 1;
}
void Delayms(unsigned int x_time)
{
unsigned int x,y;
for(x=0;x<x_time;x++)
for(y=0;y<122;y++);
}
Download Files
For download Keil project and Proteus 8.0 simulation files, click here.
Comments
Post a Comment