|
|
View previous topic :: View next topic |
Author |
Message |
pyrodigy
Joined: 27 Nov 2017 Posts: 3
|
Ordinary 74165.c and 74595.c question |
Posted: Fri Jan 26, 2018 4:28 pm |
|
|
Hi
There are 2 questions about read from read_expanded_inputs and write to write_expanded_outputs functions.
I would like to say that I am able to read and write without any problem. But,
1- When i would like to read multiple bytes from NUMBER OF multiple 74165 chips and i would like to send these bytes from UART, i see in the terminal; Byte[last] comes first instead of Byte[0]. I always need to reverse data[last] to data[first] before every transmission. I could not find an answer while search in the forum. Probably i am the only one i can not able to use deservedly :(
Could you please provide me a solution How can i get reserved data from this function ?
Code: | void read_expanded_inputs(BYTE *ei) {
BYTE i;
output_high(EXP_IN_CLOCK);
output_low(EXP_IN_ENABLE); // Latch all inputs
output_high(EXP_IN_ENABLE);
for(i=1;i<=NUMBER_OF_74165*8;++i) { // Clock in bits to the ei structure
shift_left(ei,NUMBER_OF_74165,input(EXP_IN_DI));
output_low(EXP_IN_CLOCK);
output_high(EXP_IN_CLOCK);
}
output_low(EXP_IN_ENABLE);
} |
My second issue is:
When i would like to write a string to the write_expanded_outputs function, this function deletes my whole string while doing its job. I always define a dummy string which is same length of original and i get exact copy from original string before write to this function. Why this function deletes my string ? And what can i do if i do not want to lose my original string ?
Code: | void write_expanded_outputs(BYTE* eo) {
BYTE i;
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)
output_low(EXP_OUT_DO);
else
output_high(EXP_OUT_DO);
shift_left(eo,NUMBER_OF_74595,0);
output_high(EXP_OUT_CLOCK);
output_low(EXP_OUT_CLOCK);
}
output_high(EXP_OUT_ENABLE);
output_low(EXP_OUT_ENABLE);
} |
Best Regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Ordinary 74165.c and 74595.c question |
Posted: Fri Jan 26, 2018 5:01 pm |
|
|
pyrodigy wrote: |
Byte[last] comes first instead of Byte[0].
shift_left(ei,NUMBER_OF_74165,input(EXP_IN_DI));
}
|
That's because it uses the shift_left() function to get the bits. The first
byte to come in will be in the highest (msb) location of the array.
The last byte to come in will be in location 0 of the array.
The solution is to read the array in reverse order. The example program
below shows one way to do this. The output of the program is:
Code: | #include <18F46K22.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOPBADEN
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
//======================================
void main()
{
int8 i;
int8 my_array[] = 0x12,0x34,0x56,0x78;
for(i=0; i < sizeof(my_array); i++)
printf("%x ", my_array[sizeof(my_array) -1 -i]);
while(TRUE);
} |
pyrodigy wrote: |
Why this function deletes my string ? And what can i do if i do not want to lose my original string ?
shift_left(eo,NUMBER_OF_74595,0);
|
It deletes your 'eo' string because shift_left() shifts in a 0 at the lowest
bit position, each time it does a shift. So your array gets filled with zero
bits. The solution is to first copy your array to a temporary array, and
give the temporary array to the shift_left() function as a parameter.
You can use the memcpy() function to copy the array. It's in the CCS manual. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|