|
|
View previous topic :: View next topic |
Author |
Message |
guest Guest
|
what does int data:4 means |
Posted: Wed Jun 30, 2004 6:27 am |
|
|
int data define a integer, what 4 means, does 4 is the default value? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
data:4 |
Posted: Wed Jun 30, 2004 7:10 am |
|
|
No, a default value is assigned with int data=4;
It is a bit width definition normally used in a struct.
For more information see page 64 of the CCS C manual where it is shown. |
|
|
Ttelmah Guest
|
Re: what does int data:4 means |
Posted: Wed Jun 30, 2004 10:12 am |
|
|
guest wrote: | int data define a integer, what 4 means, does 4 is the default value? |
This is the standard C declaration for a '4bit' value. You can store sizes smaller than an integer 'inside' an integer, using the ':' to specify the number of bits required. This can be very useful to access multiple 'parts' of a register for instance, so if you declare a structure, with:
struct fred {
int8 address:4;
int8 goflag:1;
int8 error:2;
int8 marker:1;
} register;
and then 'locate' it to a particular memory spot, you can access the first four bits of the byte at that point, using:
register.address
and the next bit in the same byte as:
register.goflag
This is a very useful way of talking to 'parts' of a byte.
On it's own, the declaration means that 'data' is now a 4bit number, able to hold 0..15 only.
Best Wishes |
|
|
Guest
|
|
Posted: Wed Jun 30, 2004 10:58 am |
|
|
Thank you both of you:
I raised this question because I found a definition like this in lcd.c
struct lcd_pin_map {
Boolean enable;
Boolean ers;
Boolean ws;
Boolean unused;
int data: 4;
} lcd;
struct lcd_pin_map const LCD_READ={0,0,0,0,15};
set_tris_lcd(LCD_READ); //set_tris_lcd(LCD_READ) equals set_tris_b(LCD_READ)
and set_tris_b(value); hocome the struct become value define in set_tris_b(value)
so right now the LCD_READ=00001111, right? |
|
|
Ttelmah Guest
|
|
Posted: Wed Jun 30, 2004 2:26 pm |
|
|
Yes. :-) |
|
|
Jeprox Guest
|
|
Posted: Wed Jun 30, 2004 4:34 pm |
|
|
In C, check out the topic on Bit Field. |
|
|
|
|
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
|