EMBEDDED FOR US
Would you like to react to this message? Create an account in a few clicks or log in to continue.

8051: External interrupt on IO pins

Go down

8051: External interrupt on IO pins Empty 8051: External interrupt on IO pins

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

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




Admin
Admin
Admin

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

http://embeddedforus.com

Back to top Go down

Back to top

- Similar topics

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