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

BIIIIIG PROBLEM. Help please.

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







BIIIIIG PROBLEM. Help please.
PostPosted: Fri Jul 15, 2005 1:31 pm     Reply with quote

Hi. I need your help. I really have a big problem.
I only want to know how can I access to a variable's bit?

I will be grateful with you all my life

Thank you. Don`t forget me

Alvaro
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Jul 15, 2005 1:48 pm     Reply with quote

That's a little problem Very Happy

There are a couple of ways but here is method:

bit_test(my_var,0)
bit_set(my_var,1)
bit_clear(my_var,2)


Last edited by Mark on Fri Jul 15, 2005 2:07 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 15, 2005 1:50 pm     Reply with quote

Quote:
I only want to know how can I access to a variable's bit?

Here are several ways to use bit variables in CCS:

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)

// Method 1:
// In CCS, the "short" data type is 1 bit.
// The compiler will handle assigning a RAM byte address
// to hold it.  The compiler will put up to 8 "short"
// variables in that byte.
short my_short;

// Method 2:
// You can declare the byte variable yourself, and then
// declare bit variables within it, by using the #bit
// statement.
int8 my_var;
#bit my_bit0 = my_var.0
#bit my_bit1 = my_var.1
#bit my_bit2 = my_var.2
#bit my_bit3 = my_var.3
#bit my_bit4 = my_var.4
#bit my_bit5 = my_var.5
#bit my_bit6 = my_var.6
#bit my_bit7 = my_var.7

// Method 3:
// You can create a structure of bitfields that are 1 bit wide.
struct
{
short Bit0 : 1;
short Bit1 : 1;
short Bit2 : 1;
short Bit3 : 1;
short Bit4 : 1;
short Bit5 : 1;
short Bit6 : 1;
short Bit7 : 1;
}my_bits;


//======================
void main()
{

my_short = 1;
printf("my_short = %u \n\r", my_short);

my_bit0 = 1;
printf("my_bit0 = %u \n\r", my_bit0);

my_bits.Bit0 = 1;
printf("my_bits.Bit0 = %u \n\r", my_bits.Bit0);


while(1);
}
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