Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Data type - new data type nibble

Status
Not open for further replies.

AlGeorge

Member level 1
Joined
Nov 17, 2009
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Waihi Beach
Activity points
1,606
Data type - nibble

Hi due to limited PIC resources, I need to access nibble of the char data. Values do not exceed 15. Instead of continually shifting the bits can I define a new data type nibble? If so, can anyone suggest how. I'm using cc5x compiler.
Thanks,
Alistair.
 

unaided

Member level 5
Joined
Mar 3, 2006
Messages
80
Helped
10
Reputation
20
Reaction score
1
Trophy points
1,288
Location
China
Activity points
1,652
Data type - nibble

I think you can define a struct like this:
typedef struct
{
char data1:4;
char data2:4;
}nibble;
 

AlGeorge

Member level 1
Joined
Nov 17, 2009
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Waihi Beach
Activity points
1,606
Re: Data type - nibble

unaided said:
I think you can define a struct like this:
typedef struct
{
char data1:4;
char data2:4;
}nibble;
Thanks compiler does not like eg
typedef struct {char parthours:4;}nibble;
^------
Error[1] C:\PICdev\myjob.c 50 : Not implemented
(The syntax is not implemented. This can be a compiler limitation)

typedef unsigned int data1:4;
^------
Error[1] C:\PICdev\myjob.c 50 : Not implemented
(The syntax is not implemented. This can be a compiler limitation)
 

kender

Advanced Member level 4
Joined
Jun 19, 2005
Messages
1,422
Helped
138
Reputation
276
Reaction score
39
Trophy points
1,328
Location
Stanford, SF Bay Peninsula, California, Earth, Sol
Activity points
9,968
Data type - nibble

$0.02 suggestion. Your could use macros: get_upper_nibble(...), get_lower_nibble(...), set_upper_nibble(...), set_lower_nibble(...). This wouldn't help you declare the data type, but it could streamline your code.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top