|
|
View previous topic :: View next topic |
Author |
Message |
Manu59114
Joined: 22 Jan 2018 Posts: 34 Location: North of France
|
Array bit manipulation |
Posted: Tue Sep 04, 2018 1:16 am |
|
|
Hello,
I encounter a problem with bit manipulation in a array.
Can we change directly an bit in a array?
Can we do this LEDSTATUS[0.0]= 1 or 0 ?
I would like to do that:
I have one array of 128 int8:
Code: |
unsigned int8 LEDSTATUS[128]=0; |
At LEDSTATUS[0] bit 0
I would like to have
the bit 0 of an INT8 called X
At LEDSTATUS[0] bit 1
I would like to have
the bit 0 of an INT8 called Y
At LEDSTATUS[0] bit 2
I would like to have
the bit 0 of an INT8 called Z
At LEDSTATUS[1] bit 0
I would like to have
the bit 1 of an INT8 called X
At LEDSTATUS[1] bit 1
I would like to have
the bit 1 of an INT8 called Y
At LEDSTATUS[1] bit 2
I would like to have
the bit 1 of an INT8 called Z
........>
At LEDSTATUS[7] bit 0
I would like to have
the bit 7 of an INT8 called X
At LEDSTATUS[7] bit 1
I would like to have
the bit 7 of an INT8 called Y
At LEDSTATUS[7] bit 2
I would like to have
the bit 7 of an INT8 called Z
until bit 7 of X, Y, Z.....And LEDSTATUS[7].
until bit 7 of X1, Y1, Z1.....And LEDSTATUS[15].
until bit 7 of Xx, Yx, Zx.....And LEDSTATUS[120].
What is the best approach to do that?
i don't know if i clear......
Could you help me?
I'm a little confused at this moment.
Wish you a great day to all.
MAnu _________________ CCS + ICD3 + PIC18F46K80 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Tue Sep 04, 2018 5:19 am |
|
|
One possible was is to create a Union or Structure to represent the array of bits. 128 bytes is 1024 bits and each bit could have a unique name, thus you can set or clear any bit, anywhere in the array.
Not being a C schooled programmer I can only tell you the CCS manual does show they are allowed, and some examples are in teh examples folder as well as in the FAQ section of the manual.
I'm sure other who code CCS for a living will show you some easy ways to setup your code. The though of typing in 1024 entries for the array makes my fingers ache. something like...
Code: |
struct led_array
{int led_0_0 : 1;
int led_0_1 : 1;
int led_0_2 : 1;
int led_127_7 : 1 };
struct led_array leds; |
might work?
led_x_y is a unique variable name where the 'x' refers to the byte and the 'y' the bit of that byte. the :1 says the varibale is 1 bit in length.
If you can code like this using 'copy/paste/edit' you should be able to reduce the number of hours on the kbd typing and minimize typing errors.
Jay |
|
|
|
|
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
|