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 support@ccsinfo.com

Main function knows, if it was an interrupt

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



Joined: 09 Mar 2013
Posts: 20

View user's profile Send private message

Main function knows, if it was an interrupt
PostPosted: Fri Apr 12, 2013 6:23 am     Reply with quote

Hello everybody!
I use interrupt in my program like this
Code:
#INT_EXT
void ext_isr(void)
{

}

void main()
{

}

In interrupt function I save settings to EEPROM.
How can main function know, if it was an interrupt?
Main function must read settings from EEPROM once, because read it every second is a bad idea.
Maybe something like a global variable?
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Apr 12, 2013 8:07 am     Reply with quote

Code:

int1 flag=0; //gobal inited to zero
#INT_EXT
void ext_isr(void)
{

flag=1;

}

void main()
{

if (flag) {  write_eeprom(whatever); flag=0; }
}


NEVER write_eeprom inside an ISR - takes too much time


Last edited by asmboy on Fri Apr 12, 2013 11:21 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9174
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 12, 2013 8:09 am     Reply with quote

general comment...
normally, you'll set a 'flag' within the ISR to tell 'main' that an 'action' has been done (if done within the ISR), or to be done by 'main'.

common practice is to just set 'flags', maybe write a byte or read 'registers' inside the ISR. Never try to do printf(...), math operations, etc. inside the ISR.

ISRs need to be small and fast! Let 'main' look at the flags and act accordingly.

hth
jay
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