How to Use External Interrupt-1 in AT89C1051

The following code demonstrate, how to configure INT1 (external interrupt 1) to generate an interrupt on the falling-edge of INT1 (P3.3). Each time port 3.3 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 ConfigExInterrupt1(void);
void ConfigUART(void);
void Delayms(unsigned int x_time);
// port and pin labling
sfr COUNT_PORT = 0x90;
sbit LED = P3^0;
// external interrupt-1 isr
unsigned char ex1_isr_counter = 0;
void ex1_isr(void) interrupt 2
{
// Increment the count
COUNT_PORT = ++ex1_isr_counter;
}
void main(void)
{
// make port as output
COUNT_PORT = 0x00;
// make pin as output
LED = 0;
// config interrupt-1
ConfigExInterrupt1();
while(1)
{
LED = ~LED;
Delayms(300);
}
}
void ConfigExInterrupt1(void)
{
// Configure interrupt 1 for falling edge on /INT1 (P3.3)
IT1 = 1;
// Enable EX1 Interrupt
EX1 = 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

Popular posts from this blog

How to Program Parallel Slave Port (PSP) in PIC16F877A

How to Program Interrupts in PIC16F877A

How to Program SPI in PIC16F877A (Slave Mode)