| View previous topic :: View next topic |
| Author |
Message |
JAM2014
Joined: 24 Apr 2014 Posts: 141
|
| Example: EX_EXPIO.c |
Posted: Thu Nov 06, 2025 2:50 pm |
|
|
Hi All,
I’m looking at example program ‘EX_EXPIO.c’ as the basis for a project. I need to read the data from up to 48 serially connected 74LS165 devices. The example program is clear to me for reading only one ‘165, but for multiple devices, it’s not so clear. Is the best way to change ‘NUMBER_OF_74165’ in 74165.c to 48? If so, in ‘EX_EXPIO.c’, how are the individual bytes referenced?
Jack |
|
 |
PrinceNai
Joined: 31 Oct 2016 Posts: 555 Location: Montenegro
|
|
Posted: Fri Nov 07, 2025 1:10 am |
|
|
| For my way of thinking the easiest way would be to declare an 8bit buffer NUMBER_OF_DEVICES big. Each byte of that buffer exactly represents one of the 74165's. Then I'd clock in 8 bits to same variable and move it to the buffer. Increment buffer position. Repeat NUMBER_OF_DEVICES times. That way accessing values later gets simpler. But of course it depends on what you are actually reading. Maybe bit 125 makes more sense to you than Buffer[15] bit 3. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19970
|
|
Posted: Fri Nov 07, 2025 8:27 am |
|
|
No, you would change the number to 6. Each chip gives 8 pins. That is why
it is set to '1' for the 8 pin example.
The variable ei, passed to the read_expanded_inputs function will have to
become an array of 6 bytes, instead of a single integer. so instead of:
| Code: |
BYTE data;
while (TRUE) {
read_expanded_inputs (&data);
//You will want:
BYTE data[6];
while (TRUE) {
read_expanded_inputs (data); //since the name of an array is it's address
|
The array then contains all 48 bits in the 6 bytes. |
|
 |
|