|
|
View previous topic :: View next topic |
Author |
Message |
yayodiaz44 Guest
|
BIIIIIG PROBLEM. Help please. |
Posted: Fri Jul 15, 2005 1:31 pm |
|
|
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
|
|
Posted: Fri Jul 15, 2005 1:48 pm |
|
|
That's a little problem
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
|
|
Posted: Fri Jul 15, 2005 1:50 pm |
|
|
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);
} |
|
|
|
|
|
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
|