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

Multiple flags

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



Joined: 25 Apr 2011
Posts: 296

View user's profile Send private message

Multiple flags
PostPosted: Mon Jul 14, 2014 3:53 pm     Reply with quote

Dear all,

In my project i have series of flags (about 14) which i need to check (not simultaneously). I am creating a boolean for each one but i am suspecting that there might be an easier and more practical way. Can someone give me a hint how i can improve this concept?
temtronic



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

View user's profile Send private message

PostPosted: Mon Jul 14, 2014 4:58 pm     Reply with quote

Most PICs these days have LOTS of RAM , so why not just use 1 Byte / flag? yes, overkill and 'wasteful' but easier to implement,potentially faster to process.
In your case it's just 14 bytes... shouldn't be a big deal.

It could be done in 2 bytes but there could be more 'processing' required.

jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19258

View user's profile Send private message

PostPosted: Mon Jul 14, 2014 11:38 pm     Reply with quote

There is nothing wrong with using the separate int1's though (technically they are not 'boolean' - pedantic here!...). The PIC has an efficient bit test operation which accesses these. You could just create a structure of 14 one bit fields in a single variable, which is in some ways 'tidier'.
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Tue Jul 15, 2014 10:53 am     Reply with quote

to make and manage 16 flags there is this method:
Code:

unsigned int16 myword=0;
#bit fmw0 myword.0
#bit fmw1 myword.1
........
#bit fmw15 myword.15

// if your flags default to zero then this test below  is efficient
........
if (myword) // at least one flag is set , so go sort it out


Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Jul 15, 2014 11:03 am     Reply with quote

OR

Look for any change in 'myword' to detect flag activity in either direction.

Mike

You're not giving us much to work on.
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