View previous topic :: View next topic |
Author |
Message |
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
Multiple flags |
Posted: Mon Jul 14, 2014 3:53 pm |
|
|
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: 9246 Location: Greensville,Ontario
|
|
Posted: Mon Jul 14, 2014 4:58 pm |
|
|
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: 19552
|
|
Posted: Mon Jul 14, 2014 11:38 pm |
|
|
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
|
|
Posted: Tue Jul 15, 2014 10:53 am |
|
|
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
|
|
Posted: Tue Jul 15, 2014 11:03 am |
|
|
OR
Look for any change in 'myword' to detect flag activity in either direction.
Mike
You're not giving us much to work on. |
|
|
|