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

assigning bits to arrays

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







assigning bits to arrays
PostPosted: Tue Apr 22, 2008 9:45 pm     Reply with quote

my code

Code:
static unsigned int16   reg_event[2];
         
#bit   bit_event1_1      = reg_event[0].0
#bit   bit_event1_2      = reg_event[0].1
#bit   bit_event1_3      = reg_event[0].2
#bit   bit_event1_4      = reg_event[0].3
#bit   bit_event1_5      = reg_event[0].4
#bit   bit_event1_6      = reg_event[0].5
#bit   bit_event1_7      = reg_event[0].6
#bit   bit_event1_8      = reg_event[0].7
#bit   bit_event1_9      = reg_event[0].8

#bit   bit_event2_1      = reg_event[1].0
#bit   bit_event2_2      = reg_event[1].1
#bit   bit_event2_3      = reg_event[1].2
#bit   bit_event2_4      = reg_event[1].3
#bit   bit_event2_5      = reg_event[1].4
#bit   bit_event2_6      = reg_event[1].5
#bit   bit_event2_7      = reg_event[1].6
#bit   bit_event2_8      = reg_event[1].7
#bit   bit_event2_9      = reg_event[1].8


received error when compiled. please explain what i do wrong?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 22, 2008 10:08 pm     Reply with quote

If you have version 4 of the compiler, then you can do arrays of bits.
See the example program below. It displays this as the output:
Quote:
10101010

Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

int1 array_of_bits[20] = {0};

//====================================
void main()
{
int8 i;

array_of_bits[0] = 1;
array_of_bits[1] = 0;
array_of_bits[2] = 1;
array_of_bits[3] = 0;
array_of_bits[4] = 1;
array_of_bits[5] = 0;
array_of_bits[6] = 1;
array_of_bits[7] = 0;

for(i = 0; i < 8; i++)
    printf("%u", array_of_bits[i]);

while(1);
}
guestplanet
Guest







PostPosted: Tue Apr 22, 2008 10:38 pm     Reply with quote

found a way to fix this

Code:
static unsigned int16   reg_event[2];
         
#bit   bit_event1_1      = reg_event+0.0
#bit   bit_event1_2      = reg_event+0.1
#bit   bit_event1_3      = reg_event+0.2
#bit   bit_event1_4      = reg_event+0.3
#bit   bit_event1_5      = reg_event+0.4
#bit   bit_event1_6      = reg_event+0.5
#bit   bit_event1_7      = reg_event+0.6
#bit   bit_event1_8      = reg_event+0.7
#bit   bit_event1_9      = reg_event+0.8

#bit   bit_event2_1      = reg_event+2.0
#bit   bit_event2_2      = reg_event+2.1
#bit   bit_event2_3      = reg_event+2.2
#bit   bit_event2_4      = reg_event+2.3
#bit   bit_event2_5      = reg_event+2.4
#bit   bit_event2_6      = reg_event+2.5
#bit   bit_event2_7      = reg_event+2.6
#bit   bit_event2_8      = reg_event+2.7
#bit   bit_event2_9      = reg_event+2.8


p.s. wanted to individually assign names to bit variables within a defined array of words
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