Using SDCC, I want to write something like: P1.1 = 0xAA but I want to use binary instead of hex, like: P1.1=10101010 What's the way to write binary?
SDCC: Whats 0xAA using binary?
Apr 21, 2007
12 Replies
If the 0b10101010 format hasn't yet been implemented, and you don't feel like hacking the compiler sources, a macro has been provided here:
formatting link
#define BIN(x) \ ( ((0x##x##L & 0x00000001L) ? 0x01 : 0) \ | ((0x##x##L & 0x00000010L) ? 0x02 : 0) \ | ((0x##x##L & 0x00000100L) ? 0x04 : 0) \ | ((0x##x##L & 0x00001000L) ? 0x08 : 0) \ | ((0x##x##L & 0x00010000L) ? 0x10 : 0) \ | ((0x##x##L & 0x00100000L) ? 0x20 : 0) \ | ((0x##x##L & 0x01000000L) ? 0x40 : 0) \ | ((0x##x##L & 0x10000000L) ? 0x80 : 0))
T2CON = BIN(00110100);
P1.1 is one (1) bit binary, 0xaa (10101010) is eight (8) bits NOT binary
Do you understand now ??
donald
google 'torfs binary constant macros'. Lovely solution.
pete
pete@fenelon.com "how many clever men have called the sun a fool?"
YES I DO!!! I'm sorry, I meant I want to set an entire port to 0XAA GET IT NOW?
formatting link
Thank you, that helps.
Thank you.
What processor are you using? P1.1 looks like a bit port... ?!?
Regards,
Mark McDougall, Engineer
Virtual Logic Pty Ltd,
21-25 King St, Rockdale, 2216
Ph: +612-9599-3255 Fax: +612-9599-3266
for (i = 8; i--; n >>= 1) putport(n & 1);
or n
Sorry, P1.1 is a bit. I meant, I'm trying to write to the whole port, using binary, not hex. I have to bit-bang an 8051 dev board to talk to a DC101 DAC. The macro the other posters linked me to works fine.
Then using bit operations and not the whole port would seem to be the logical thing to do...
Grant Edwards grante Yow! Youth of today! Join
at me in a mass rally
visi.com for traditional mental
attitudes!
Well, alltogether there's eight lines that need to be controlled to work the DDC101, like sys clk, data clk, sys reset, setup reset, dataXmit,.... It was easiest just to wire each pin to a port bit and blast out the words to make the data streams. Another 2 lines to read in the data, DataValid and DataOut; I'll use 2 bits of another port as inputs to read these lines.
Shouldn't you be using macros or constants rather than 'magic numbers'?
Regards,
Mark McDougall, Engineer
Virtual Logic Pty Ltd,
21-25 King St, Rockdale, 2216
Ph: +612-9599-3255 Fax: +612-9599-3266
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required