CCS :: View topic - Using Hardware Interrupt (INT0)
FAQ
Forum Help Profile
Official CCS Support
http://ccsinfo.com/forum/viewtopic.php?t=18610&highlight=int0...
Search
Log in to check your private messages
Register Log in
Using Hardware Interrupt (INT0) CCS Forum Index -> General CCS C Discussion View previous topic :: View next topic Author ericzuki
Message Using Hardware Interrupt (INT0) Posted: Mon Mar 08, 2004 9:41 am
Joined: 24 Feb 2004 Posts: 3
Hi All 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().
Code: #include <18F458.h> #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(clock=20000000) // 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; }
1 от 2
27.2.2007 г. 09:48
CCS :: View topic - Using Hardware Interrupt (INT0)
http://ccsinfo.com/forum/viewtopic.php?t=18610&highlight=int0...
Thanks jds-pic
Re: Using Hardware Interrupt (INT0) Posted: Mon Mar 08, 2004 9:09 pm
Joined: 17 Sep 2003 Posts: 168
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. jds-pic Display posts from previous: All Posts
Oldest First
CCS Forum Index -> General CCS C Discussion
Go All times are GMT - 6 Hours
Page 1 of 1 Jump to: General CCS C Discussion You can post new topics You can reply to topics You cannot edit your posts You cannot delete your posts You cannot vote in polls
Go in in in in in
this this this this this
forum forum forum forum forum
Powered by phpBB © 2001, 2005 phpBB Group
2 от 2
27.2.2007 г. 09:48