Input and Output based on BYTEs (Using Shift Registers to cut down wiring)
tdeyle
Posts: 85
Okay. I have an LED array and a switch remote that is wired to a main board that contains the Prop.
I have 8 LEDs and 8 Switches that need to be activated/monitored. I was thinking to use a 74HCT165 for the Switches and a 74HCT595 for the LEDs. I would call the BYTE variable for the LEDs LED, and the switches, SWITCH. Each bit in the LED Byte would represent the state of an LED, as well, each bit in the SWITCH byte would represent the state of a switch.
Problem is, the program has to read/write to each individual bit. For example, one method might need to write a 1 to bit 5 of the LED Byte, while another method writes a 0 to bit 3, etc.
Is there a way to read/write bits in this manner?
I have 8 LEDs and 8 Switches that need to be activated/monitored. I was thinking to use a 74HCT165 for the Switches and a 74HCT595 for the LEDs. I would call the BYTE variable for the LEDs LED, and the switches, SWITCH. Each bit in the LED Byte would represent the state of an LED, as well, each bit in the SWITCH byte would represent the state of a switch.
Problem is, the program has to read/write to each individual bit. For example, one method might need to write a 1 to bit 5 of the LED Byte, while another method writes a 0 to bit 3, etc.
Is there a way to read/write bits in this manner?
Comments
For the LED byte, I would have to activate the LED by OR'ing the byte onto itself, with a 1 in the bit position that I want to activate.
EX: If I wanted to turn on the LED that corresponds to bit 4, I would write the following:
LED := LED | %0000_1000
If I wanted to turn it off, I would XOR the byte onto itself, with a 1:
LED := LED ^ %0000_1000
For the SWITCH byte, since the program only recognizes a single button press at a time, I would use a CASE loop to determine the value of the SWITCH byte and assign a 1 to the corresponding variable.
EX:
CASE Switches
1 : UpButton := 1
2 : DownButton := 1
4 : LeftButton := 1
8 : RightButton := 1
16 : IncButton := 1
32 : DecButton := 1
64 : SelectButton := 1
128 : BackButton := 1
Of course, the states that these buttons would be cleared to zero before this loop.