Continue to Site

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.

bit manipulation in mcu programming

Status
Not open for further replies.

84prakash

Newbie level 3
Joined
Apr 10, 2012
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,309
hi
if we declare a int variable in pic16f877 we know 16 bits are allocated to that variable. for example if i'm assigning 3 variables for date month and year viz DATE MONTH YEAR totally 48 bits will be allocated. In variables MONTH highest value will be 12(0000000000001100). in the variable DATE highest value will be 31(0000000000011111). totally 23 bits are wasted. if i want to store 100 dates more memory will be wasted. My question is how to define a variable whose bit length is 4 or 5. pls help me to solve my long time doubt. if not in pic16f can we declare like that in ARM7. pls tell the instructions
 

Code:
typedef struct {
    unsigned char year:4;
    unsigned char month:4;
    unsigned char day:5;
} DATE;

That will create a variable type that uses only 9bits to store your data in and the individual members can be accesses in the same way as a normal struct. Its worth saying though that the compiler is free to pad this data structure out as it sees fit, so the best possible case would be 16 bits being used for it, with more likely 24bits being used instead.
If it does get padded out to 24bits then you may as well just use a structure with three chars for the different variables and forget all about the whole bit field thing.

Hope this helps.
/Pheetuz
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top