Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BitRead implementation
13-08-2014, 07:33 PM,
#1
BitRead implementation
Hi. Doing something like the following code:

digitalwrite(addrPins[0], BitRead(pin,0));
digitalwrite(addrPins[1], BitRead(pin,1));
digitalwrite(addrPins[2], BitRead(pin,2));

I didn't found the expected result because the pin variable gets modified itself in every call to BitRead. Looking at file p8/include/pinguino/core/macro.h (in the last 11 trunk) we can see:

#define BitRead(octet, n) (octet = (octet >> n) & 1)

But looking at the file hardware/arduino/cores/arduino/Arduino.h, the only implementation of bits macros thats looks different in Pinguino from Arduino is BitRead. Here is the line in Arduino.h:

#define bitRead(value, bit) (((value) >> (bit)) & 0x01)

May be in Pinguino "macro.h" this macro should be something like:

#define BitRead(octet, n) ((octet >> n) & 1)

Is a typo in Pinguino or the BitRead is intended to operate that way ?
Thanks, Mario.
Reply
13-08-2014, 07:47 PM,
#2
RE: BitRead implementation
I don't know, but it would need parens:

#define BitRead(octet, n) (((octet) >> (n)) & 1)

John
Reply
14-08-2014, 04:31 PM,
#3
RE: BitRead implementation
Parens added.
New macro.h files will be published very soon in Pinguino v11.
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
16-08-2014, 03:18 AM,
#4
RE: BitRead implementation
(14-08-2014, 04:31 PM)regis Wrote: Parens added.
New macro.h files will be published very soon in Pinguino v11.

Thanks Regis for your response
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)