8051: External interrupt on IO pins
Page 1 of 1
8051: External interrupt on IO pins
Example for external interrupt 0 for falling edge on /INT0 (P3.2). The variable ex0_isr_counter will increment each time the interrupt occur.
#include <REG52.H>
/*=============================================================================
=============================================================================*/
unsigned char ex0_isr_counter = 0;
void ex0_isr (void) interrupt 0
{
ex0_isr_counter++; // Increment the count
}
/*=============================================================================
=============================================================================*/
void main (void)
{
/*-----------------------------------------------
Configure INT0 (external interrupt 0) to generate
an interrupt on the falling-edge of /INT0 (P3.2).
Enable the EX0 interrupt and then enable the
global interrupt flag.
-----------------------------------------------*/
IT0 = 1; // Configure interrupt 0 for falling edge on /INT0 (P3.2)
EX0 = 1; // Enable EX0 Interrupt
EA = 1; // Enable Global Interrupt Flag
/*-----------------------------------------------
Wait forever.
-----------------------------------------------*/
while (1)
{
}
}
/*=============================================================================
=============================================================================*/
#include <REG52.H>
/*=============================================================================
=============================================================================*/
unsigned char ex0_isr_counter = 0;
void ex0_isr (void) interrupt 0
{
ex0_isr_counter++; // Increment the count
}
/*=============================================================================
=============================================================================*/
void main (void)
{
/*-----------------------------------------------
Configure INT0 (external interrupt 0) to generate
an interrupt on the falling-edge of /INT0 (P3.2).
Enable the EX0 interrupt and then enable the
global interrupt flag.
-----------------------------------------------*/
IT0 = 1; // Configure interrupt 0 for falling edge on /INT0 (P3.2)
EX0 = 1; // Enable EX0 Interrupt
EA = 1; // Enable Global Interrupt Flag
/*-----------------------------------------------
Wait forever.
-----------------------------------------------*/
while (1)
{
}
}
/*=============================================================================
=============================================================================*/
Similar topics
» 8051 : 8 bit Timer0 overflow using Interrupt
» 8051: 16 bit timer0 overflow using Interrupt service routine.
» interrupt-driven button code in CCS C
» 8051 read write port
» interfacing 8051 with JHD12864 and samsung ks0108b glcd 128x64
» 8051: 16 bit timer0 overflow using Interrupt service routine.
» interrupt-driven button code in CCS C
» 8051 read write port
» interfacing 8051 with JHD12864 and samsung ks0108b glcd 128x64
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum