View previous topic :: View next topic |
Author |
Message |
Nora
Joined: 23 Mar 2008 Posts: 50
|
Would like help understanding 74595 library |
Posted: Sat Mar 26, 2011 3:42 pm |
|
|
Hello-
I am using the 74595.c library (successfully with one 74595 module).
I am unclear to how it actually works and was hoping someone here could explain it to me.
Especially this line Code: | if((*(eo+(NUMBER_OF_74595-1))&0x80)==0) |
I've commented the lines with what I think is happening.
Thanks in advance!
N_N
Code: |
void write_expanded_outputs(BYTE* eo) { /*SETS EO TO BE A POINTER TO OBJECTS OF TYPE BYTE*/
BYTE i; //int8
output_low(EXP_OUT_CLOCK);
output_low(EXP_OUT_ENABLE);
for(i=1;i<=NUMBER_OF_74595*8;++i) { // Clock out bits from the eo array
if((*(eo+(NUMBER_OF_74595-1))&0x80)==0)
/* (*(eo+(NUMBER_OF_74595-1)) IS THE VALUE OF EO + NUM OF 74595-1
IF THE ABOVE IS ANDED WITH 1000 0000 AND IS EQUAL TO 0 (MORE THAN 8 74595), THEN OUTPUT LOW ON THE DATA LINE*/
output_low(EXP_OUT_DO);
else
output_high(EXP_OUT_DO);
shift_left(eo,NUMBER_OF_74595,0); //ADDRESS, BYTES, VALUE
output_high(EXP_OUT_CLOCK);
output_low(EXP_OUT_CLOCK);
}
output_high(EXP_OUT_ENABLE);
output_low(EXP_OUT_ENABLE);
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 26, 2011 5:05 pm |
|
|
The code is testing the top bit (bit 7) of the last byte in the array, to see if
the bit is 1 or 0. The top bit of the last byte is the MSB of the whole array.
Bit 0 of the first byte is the LSB of the whole array.
The code tests the MSB, then sets the "DO" pin to be the same value.
Then it shifts the whole array over by 1 bit position. It shifts the array
in the direction of the MSB. |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Sun Mar 27, 2011 5:02 am |
|
|
Thanks PCM! |
|
|
|