First line of interrupt function ext_isr declares a static variable and sets it false. So every time there is an external interrupt the function get called and every time button_pressed is false. How do the if conditions work if the variable is reinitialized everytime.
Can someone please explain to me how this code works?
Here is EX_WAKUP.C for your convenience.
Code:
// global flag to send processor into sleep mode
short sleep_mode;
// external interrupt when button pushed and released
#INT_EXT
void ext_isr() {
static short button_pressed=FALSE;
if(!button_pressed) // if button action and was not pressed
{
}
+++++++++++++++
Most code deleted.
Reason: Forum rule #10 -
10. Don't post the CCS example code or drivers.
You need to learn the C languange. It's initialized only once.
Go to the Wikipedia article on static variables:
http://en.wikipedia.org/wiki/Static_variable#Example
Look at the sample code in this section and read the comments:
Quote:
An example of static local variable in C
haxan7
Joined: 27 Jul 2013 Posts: 79
Posted: Sat Jul 27, 2013 11:02 am
PCM programmer wrote:
You need to learn the C languange. It's initialized only once.
Go to the Wikipedia article on static variables:
http://en.wikipedia.org/wiki/Static_variable#Example
Look at the sample code in this section and read the comments:
Quote:
An example of static local variable in C
Thanks a million, i was confusing the static in c++ with static keyword in java.
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