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?
- posted
16 years ago
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?
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:
#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?
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,
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
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,
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.