CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Need Help understanding CCS Example (EX_WAKUP.C)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
haxan7



Joined: 27 Jul 2013
Posts: 79

View user's profile Send private message

Need Help understanding CCS Example (EX_WAKUP.C)
PostPosted: Sat Jul 27, 2013 6:25 am     Reply with quote

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.

Forum Rules:
http://www.ccsinfo.com/forum/viewtopic.php?t=26245

- Forum Moderator
+++++++++++++++
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jul 27, 2013 10:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 27, 2013 11:02 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group