void main(){
CLK = 0;
PL = 0;
delay(50);
PL = 1;
if(SI)
{
shiftdata = shiftdata + 1;
for(q=0;q<7; q++)
{
shiftdata << q;
CLK = 1;
delay(30);
CLK = 0;
if(SI)
shiftdata= shiftdata + 1;
}
}
shiftdata << q;
Code C - [expand] 1 2 3 if(DATA_IN) byte[i][j] |= 1; else byte[i][j] |= 0;
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 void Read_Keys() { char i, j; SHLD = 0; Delay_us(500); SHLD = 1; for(i = 0; i < 7; i++) { for (j = 0; j < 8; j++) { if(DATA_IN) byte[i][j] |= 1; else byte[i][j] |= 0; byte[i][j] <<= 1; CLK = 1; Delay_us(500); CLK = 0; } } }
for(i = 0; i < 7; i++) {
for (j = 0; j < 8; j++) {
byte[i] <<= 1;
if(DATA_IN)
byte[i] |= 1;
else byte[i] |= 0;
CLK = 1;
Delay_us(500);
CLK = 0;
}
}
if the rooms are different location,it is good to use RS485 protocol,it only use 2 wires.
i have already tested with MODBUS protocol using AT89C51 as master and AT89C2051 as slave.
so the wiring complications are avoided.
I cannot use matrix keyboard because my switches are placed in different room or place ..
- - - Updated - - -
what is the need of CE Clock enable pin ?
I agree that extending an "interchip" interface like SPI or I2C over many meters to a different room means asking for trouble. It's not completely impossible, but without well considered signal filtering, ESD events or RF interferences are likely to cause communication errors and e.g. ghost key presses. The solution suggested by matthai is straightforward and doesn't require much additional resources, except for a second µC.if the rooms are different location,it is good to use RS485 protocol,it only use 2 wires.
i have already tested with MODBUS protocol using AT89C51 as master and AT89C2051 as slave.
so the wiring complications are avoided.
You need 1d array only. The 2nd dimension is implemented by the 8bits of each byte in the 1d array.
FvM in this link:
https://www.edaboard.com/threads/332224/#post1448018
posted the correct code.
You should do something like that (althow it is not the way I would write it):
Code:for(i = 0; i < 7; i++) { for (j = 0; j < 8; j++) { byte[i] <<= 1; if(DATA_IN) byte[i] |= 1; else byte[i] |= 0; CLK = 1; Delay_us(500); CLK = 0; } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?