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.

clear bit function is not working in C18 compiler

Status
Not open for further replies.

Arrowspace

Banned
Joined
Jan 23, 2015
Messages
186
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Activity points
0
Code:
#define set_bit(x,y) (x=x|(1<<y))
#define clr_bit(x,y) (x=x|(0<<y))

I am trying to set single bit and clearing it, my set function is working, but clear function is not working.
 

you should use something like that:

Code:
#define set_bit(x,y) (x |= 1 << y)
#define clr_bit(x,y) (x &= ~(1 << y))

Another set of usual macros:

Code:
#define toogle_bit(x,y) (x ^= 1 << y )
#define read_bit(x,y) ((x>> y) & 1 )
 
why this will not work

Code:
#define clr_bit(x,y) (x=x|(0<<y))
 

The OR operator "|" that you are using above is not able to clear anything.
Just take a thorough look on the code which I gave, and try to understand how it works.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top