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

Array bit manipulation

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



Joined: 22 Jan 2018
Posts: 34
Location: North of France

View user's profile Send private message

Array bit manipulation
PostPosted: Tue Sep 04, 2018 1:16 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Sep 04, 2018 5:19 am     Reply with quote

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