I have written a test program on INT0 but I am not able to test it out on the hardware yet due to unavalibility. Can someone be kind enough to tell me whether the code will works.
A push button is connected to Pin B0 which when pushed will caused the chip to go into SLEEP mode. A second push on the pushbutton will bring the chip active and reset via reset_cpu().
// global flag to send processor into sleep mode
short sleep_mode;
// external interrupt when button pushed and released
#INT_EXT
void ext_isr()
{
if(button_pressed_once) // if button action and was not
// pressed
{
button_pressed_once=FALSE; //to activate the next button pressed
// which is to reset the thing
sleep();
}
else
{
button_pressed_once=TRUE; // the button is now up
reset_cpu();
}
}
void main()
{
ext_int_edge(H_TO_L); // init interrupt triggering for button press
enable_interrupts(INT_EXT);// turn on interrupts
enable_interrupts(GLOBAL);
static short button_pressed_once=TRUE;
}
Thanks
jds-pic
Joined: 17 Sep 2003 Posts: 205
Re: Using Hardware Interrupt (INT0)
Posted: Mon Mar 08, 2004 9:09 pm
ericzuki wrote:
Code:
#INT_EXT
void ext_isr()
{
if(button_pressed_once) // if button action and was not
// pressed
{
button_pressed_once=FALSE; //to activate the next button pressed
// which is to reset the thing
sleep();
}
else
{
button_pressed_once=TRUE; // the button is now up
reset_cpu();
}
}
void main()
{
ext_int_edge(H_TO_L); // init interrupt triggering for button press
enable_interrupts(INT_EXT);// turn on interrupts
enable_interrupts(GLOBAL);
static short button_pressed_once=TRUE;
}
it may just be me but i don't like the idea of going to sleep inside an interrupt handler function. i believe that this is asking for debugging troubles and it's just not good programming practice. why not just set a flag in #int_ext and test it in main()? keep your inerrupt handlers simple.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum