Go Down

Topic: how do i split one bit into 3 or more bytes?? (Read 3525 times) previous topic - next topic

rlwilliams

hi i am trying to use more than 3 74hc595 shift registers to power LED's directly. i have two shift registers working by
splitting the bit into 2 bytes as shown below:

byte registerOne = lowByte(bitsToSend);
  byte registerTwo = highByte(bitsToSend);

I am wondering what code i need to have this as 3 or more bytes?

any help would be great! thanks

tomm

I'm not sure what you're doing with the shift registers exactly, but is there some reason you aren't daisy chaining them?

rlwilliams

hi derby,

i am daisy chaining the shift registers with the data running through all of them in the chain, however the problem i have is getting them to react individually to the data sent.

eg  byte registerOne = lowByte(bitsToSend);
  byte registerTwo = highByte(bitsToSend);
byte registerThree = highByte(bitsToSend);

Highlighted byte will be triggered identical to register two.

do you see what i mean?

thanks

AWOL

Assuming (because you haven't shown us) that "bitsToSend" is an "int", then the answer is that there aren't any more bytes.
An "int" is 16 bits, or two bytes long.
Or, if it's a "long", simply shift right 16 bits and mask with 0xFF.

Korman

If you just have two bytes, you can get away with using one 16-bit integer value and splitting it with highbyte() and lowbyte(). For more than two, things become impractical, in that case you  better define a byte array and shift that out.

So your code will look something like this:
Code: [Select]
const int daisylength = 3;
uint8_t daisydata[daisylength];

void loop() {
...
// Setting some bits
daisydata[2] |= 0x43;
...
// Send out data
for (int i = 0; i < daisylength; i++) {
   shiftOut(dataPin, clock, LSBFIRST, daisydata[i]);
}
// Latch etc.
....
}


Then you can increase your daisy-chain by simply increasing the value of daisylength and adding the necessary hardware.

Korman

rlwilliams

ok thats great!

one question however

When setting the bits

i am having problems with the constant before the = sign

Whenever i use a different symbol than | the software says it is missing a ; before the contant.

any ideas??



AWOL

Quote
Whenever i use a different symbol than | the software says it is missing a ; before the contant

Do you mean the bitwise OR operation?

What other symbols did you try?  (and, other than '+', why?)

rlwilliams

I think bit wise

Eg.

// Setting some bits
daisydata[2] |= 0x43;
daisydata[2] A= 0x43;
daisydata[2] £= 0x43;
daisydata[2] @= 0x43;


The green line works fine

The red lines and others alike the arduino software asks for this below

daisydata[2] ;A= 0x43;

The red semi colon then produces the error that 'A' is undefined.

any ideas?

Korman

Ouch.

The line:
Code: [Select]
daisydata[2] |= 0x43;

is equivalent to writing:

Code: [Select]
daisydata[2] = daisydata[2] | 0x43;

which means that daisydata[2] will have all bits of the hexadecimal 0x43 (01000011 in binary) set. You can't put any random characters in there, the operators with = exist only for some operations (+ - * / % ^ ~  $ and |)

Korman

Grumpy_Mike

This wouldn't happen to be a home work assignment would it? We got an almost identical request some months back.

AWOL

Quote
daisydata[2] £= 0x43;

Ah! the old pound-sign (note to US readers: yes, that really is a pound sign) operator.
Why didn't you say so before?

GrooveFlotilla

Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.


Korman

#13
Apr 06, 2011, 05:57 pm Last Edit: Apr 06, 2011, 06:00 pm by Korman Reason: 1

@Korman
what does the $ operator do?


The main application of the $-operator is to exercise the syntax checker of the compiler to prevent the accumulation of rust between the bits. It's used mostly by typing-challenged posters who were targeting the &-key but missed it wildly by 3 keys. This inaccuracy training is also a prerequisite for the job of missile guidance officer in war zones to properly execute surgical strikes with carpet bombing.

Korman

jraskell


It's used mostly by typing-challenged posters who were targeting the &-key but missed it wildly by 3 keys.


When I read that, the thought, "What keyboard is he using where the $ is anywhere near the &" popped into my head before even getting to the latter part describing how badly you missed it.

Go Up