View previous topic :: View next topic |
Author |
Message |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
static? SLEEP MODE |
Posted: Thu May 19, 2005 5:16 am |
|
|
Code: | #INT_EXT
void ext_isr() {
static short button_pressed=FALSE;
if(!button_pressed) // if button action and was not pressed
{
button_pressed=TRUE; // the button is now down
sleep_mode=TRUE; // activate sleep
printf("The processor is now sleeping.\r\n");
ext_int_edge(L_TO_H); // change so interrupts on release
}
else // if button action and was pressed
{
button_pressed=FALSE; // the button is now up
sleep_mode=FALSE; // reset sleep flag
ext_int_edge(H_TO_L); // change so interrupts on press
}
if(!input(PIN_B0)) // keep button action sychronized wth button flag
button_pressed=TRUE;
delay_ms(100); // debounce button
} |
Hello again,
this question is about the variable button_pressed. It gets initialised in the isr() as FALSE. How can it ever get TRUE when isr() is called? Shouldn't it be declared outsite the function?
In main:
Code: | while(TRUE)
{
if(sleep_mode) // if sleep flag set
sleep(); // make processor sleep
printf("The count value is: %5ld \r\n",counter);
counter++; // display count value and increment
delay_ms(1000); // every second
} |
What is the processor doing after sleep(); ? Is he still able to poll i/o, to do instructions in general?
-what is sleep mode- |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu May 19, 2005 6:20 am |
|
|
How can it get set to TRUE? Did you look at the code that you posted?
Code: | if(!button_pressed) // if button action and was not pressed
{
button_pressed=TRUE; // the button is now down
sleep_mode=TRUE; // activate sleep
printf("The processor is now sleeping.\r\n");
ext_int_edge(L_TO_H); // change so interrupts on release
}
|
maybe this will make it clearer
Code: | if(button_pressed==FALSE) // if button action and was not pressed
{
button_pressed=TRUE; // the button is now down
sleep_mode=TRUE; // activate sleep
printf("The processor is now sleeping.\r\n");
ext_int_edge(L_TO_H); // change so interrupts on release
}
|
|
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Thu May 19, 2005 6:43 am |
|
|
Mark,
I mean when ENTERING the isr(); the variable is set FALSE!
So it will never get to the else statement.. no? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu May 19, 2005 6:44 am |
|
|
Not when it is declared as "static" |
|
|
|