You are on page 1of 2

CCS :: View topic - Using Hardware Interrupt (INT0) http://ccsinfo.com/forum/viewtopic.php?t=18610&highlight=int0...

FAQ Forum Help Official CCS Support Search Register

Profile Log in to check your private messages Log in

Using Hardware Interrupt (INT0)

CCS Forum Index -> General CCS C Discussion

View previous topic :: View next topic

Author Message

ericzuki Using Hardware Interrupt (INT0)


Posted: Mon Mar 08, 2004 9:41 am

Joined: 24 Feb 2004 Hi All


Posts: 3

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 ericzuki wrote:


Posts: 168

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 Go

All times are GMT - 6 Hours


CCS Forum Index -> General CCS C Discussion

Page 1 of 1

Jump to: General CCS C Discussion Go

You can post new topics in this forum


You can 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

Powered by phpBB © 2001, 2005 phpBB Group

2 от 2 27.2.2007 г. 09:48

You might also like