View previous topic :: View next topic |
Author |
Message |
championx
Joined: 28 Feb 2006 Posts: 151
|
Struct question |
Posted: Thu Oct 06, 2011 11:47 am |
|
|
Hi, I'm trying to define a structure type, but i have some questions.
Could i define some 10 bits vars?
like:
Code: |
typedef struct report_min
{
int VAR1:6;
int16 VAR2:8;
int16 VAR3:10;
}report;
|
But i get "number of bits is out of range" on VAR2.
thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Thu Oct 06, 2011 2:28 pm |
|
|
In CCS, the default int size, is 8bits, and bit fields in structures have to fit inside this. Hence the complaint.
It complains because you are using int16, and it won't accept this.
So, no 10bit variables.
Best Wishes |
|
|
zasi80
Joined: 03 Oct 2011 Posts: 4 Location: London
|
|
Posted: Sun Oct 09, 2011 8:09 am |
|
|
I have also problem with struct. I'm using it for first time. I'm trying to shift in data into structure but it doesn't work. Value of aaa is always 0.
I based my code on sample code from CCS help (for SHIFT_RIGHT() ).
Code: |
#include <16f690.h>
#FUSES NOWDT,INTRC, NOPUT, NOPROTECT, NOBROWNOUT, NOMCLR
#use delay(clock=4000000)
#USE RS232(BAUD=4800, XMIT=PIN_B7, RCV=PIN_B6)
main()
{
int i, data111=0b11111111, carrybit=0, aaa=0;
struct ddd
{
byte aaa :8 ; //only one byte in structure for debugging
} msg111 ;
delay_ms(100);
putc(254); //for LCD
putc(1);
for(i=0; i<=8; ++i)
{
carrybit=shift_right(&data111,1,0); //it is supposed to shift in "data111" into struct "msg111"
shift_right(&msg111,1,carrybit);
Printf("%u ", aaa);
}
}
|
|
|
|
zasi80
Joined: 03 Oct 2011 Posts: 4 Location: London
|
|
Posted: Sun Oct 09, 2011 8:48 am |
|
|
I found answer!
aaa in structure is not the same as aaa declared as integer in my program.
To get access to aaa from structure I have to use:
Code: |
Printf("%u ", msg111.aaa);
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sun Oct 09, 2011 9:51 am |
|
|
It's always a GREAT feeling to figure out where you went wrong and to fix it! You'll learn more by doing . |
|
|
|