We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hello, I would like to do a bit test of a unsigned char variable. It's like a jb in assembler.
here is my code in c.
unsigned char displ; unsigned char display3 = 0xA8; unsigned char i; sbit display_data = P1^0; displ = display3; for (i=0; i<7; i++) { if (displ^0 == 1){ display_data = 0; } else { display_data = 1; } displ>>=1; }
I don't have any warning or error, but the result of test is wrong. is it possible to do in c?
tkx.
Note that the '^' only has its Keil-specifc meaning in an sbit definition - elsewhere, it continues to be the standard 'C' exclusive-or operator.
Have you looked at the C51 facility for bit-addressable objects? http://www.keil.com/support/man/docs/c51/c51_le_bitaddrobj.htm
Without using C51's proprietary bit-addressable object extensions, you will have to use the standard 'C' bitwise mask operations...
You might also want to look at http://www.keil.com/support/man/docs/c51/c51__testbit_.htm