SDCC: Whats 0xAA using binary?

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?

Reply to
sdeyoreo
Loading thread data ...

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);

Reply to
jcomeau_ictx

P1.1 is one (1) bit binary, 0xaa (10101010) is eight (8) bits NOT binary

Do you understand now ??

donald

Reply to
Donald

google 'torfs binary constant macros'. Lovely solution.

pete

--
pete@fenelon.com "how many clever men have called the sun a fool?"
Reply to
Pete Fenelon

YES I DO!!! I'm sorry, I meant I want to set an entire port to 0XAA GET IT NOW?

Reply to
sdeyoreo

formatting link

Thank you, that helps.

Reply to
sdeyoreo

Thank you.

Reply to
sdeyoreo

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
Reply to
Mark McDougall

for (i = 8; i--; n >>= 1) putport(n & 1);

or n

Reply to
CBFalconer

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.

Reply to
sdeyoreo

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!
Reply to
Grant Edwards

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.

Reply to
sdeyoreo

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
Reply to
Mark McDougall

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.