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

Struct question

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



Joined: 28 Feb 2006
Posts: 151

View user's profile Send private message

Struct question
PostPosted: Thu Oct 06, 2011 11:47 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Oct 06, 2011 2:28 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Oct 09, 2011 8:09 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Oct 09, 2011 8:48 am     Reply with quote

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: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Oct 09, 2011 9:51 am     Reply with quote

It's always a GREAT feeling to figure out where you went wrong and to fix it! You'll learn more by doing .
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