help with BitRead()

Hi Everybody,

i just need a help with the function Bitread . i don't understand how it works...
i'm currently need it for a project: i would like to read a byte inside a DS1307 (RTC component) and put it on a digital pin on the arduino.

example: inside the DS1307, i have to read at the adress 00h, the LSB (BIT0)then BIT1.....then BIT0 goes to digital pin 0(of Arduino board),the BIT1 goes to digital pin 2....

it seems that the bitread function can do that...

So is it possible to help me?
thanks,

Vincent

example: inside the DS1307, i have to read at the adress 00h, the LSB (BIT0)then BIT1.....then BIT0 goes to digital pin 0(of Arduino board),the BIT1 goes to digital pin 2....

What is at address 00h? Why do you need to activate pins based on that data? When will you do this? What part of it are you having problems with? The bitRead() function is pretty simple - tell it what byte to extract a bit from, and which bit to extract. It returns that bit.

sheer:
i just need a help with the function Bitread . i don't understand how it works...
i'm currently need it for a project: i would like to read a byte inside a DS1307 (RTC component) and put it on a digital pin on the arduino.

Where the byte comes from doesn't matter. You need to obtain the byte value by whatever means necessary. Then you can call bitRead() to extract the value of specific bits from that byte. Once you have the bit value, you can output it to a digital pin or do whatever else you want to do with it.

from the DS1307, i got 8 bytes in BCD (0000 0000)....then i don't know how to use bitread function if i understand i have to use it 8 times...one time for each bytes.......all i need is just an example with an explanation.

http://arduino.cc/en/Reference/BitRead

i've already read this and i don't understand how to use it.....

You use it like this:

http://codepad.org/jtApX9tP

It reads bits from the right to the left :slight_smile:

sheer:
i've already read this and i don't understand how to use it.....

In your original post, only a small part of what you're trying to do can be done with bitRead(). Maybe your difficulty is that you're expecting bitRead() to do more than it does.

Your original problem is:

  • Read a byte from a DS1307
  • Extract the value of one bit from the byte
  • Output HIGH or LOW on an output pin according to the value of the bit

The bitRead() function only does the middle step for you. It is up to you to obtain the byte, and do something useful with the bit you extracted from it.