8051: External interrupt on IO pins

View previous topic View next topic Go down

8051: External interrupt on IO pins

Post  Admin on Wed Jul 31, 2013 1:56 am

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)
{
}
}

/*=============================================================================
=============================================================================*/




avatar
Admin
Admin

Posts : 49
Join date : 2012-08-15
Location : Mumbai,INDIA

View user profile http://embeddedforus.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum