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.

How to assign a name to each individual bit in the xdata?

Status
Not open for further replies.

tom12sg

Member level 2
Joined
Feb 1, 2004
Messages
45
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Activity points
422
Bit assign in xdata

Hi,

Need advice on the following:

I'm using keil for 8051.
Normally I will use a bit for flag test
e.g bit flag_error=0;

How can i use xdata instead? How to assign a name to each individual bit in the xdata?
Please give simple example on how to set/clear/test a particular bit
Is there any easy way?

Regards,
 

Re: Bit assign in xdata

Couple of ways:
1. use a struct bitfield - watch bitfield order.

typedef struct tagBit {
unsigned char b0:1;
unsigned char b1:1;
unsigned char b2:1;
unsigned char b3:1;
unsigned char b4:1;
unsigned char b5:1;
unsigned char b6:1;
unsigned char b7:1;
}Bit;

xdata Bit test;
test.b0 = 1;

2. Defind simple access functions on a data byte, eg.

#define SetBit(var,place) (var |= (1<<place))
#define ClrBit(var,place) (var &= ~(1<<place))
#define ValBit(var,place) (var & (1<<place))

#define TEST 0
unsigned chat var1;
SetBit( var1,TEST)

Hope this helps.
Regards
NTFreak
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top