i2c to keyboard interface.pdf

(29 KB) Pobierz
I2C to Keyboard interface
Here follows a short description on how to use my i2c_kbd library, with this you could use
any AVR circuit with a matrix keyboard with minimal extra hardware. The interface from the
i2c to keyboard consists of a PCF8574 8bit I/O module, so with only 2 pins you could
interface the keyboard (or 3 pins if you use interrupt).
What you need to add in the beginning of your program is the following:
$lib "Key_i2c.lib"
$external _key_scan
Const Pcf8574_lcd = &H42
Config Scl = Portd.6
Config Sda = Portd.7
Dim _key_scan As Byte
!rcall _Key_init
.
.
.
!rcall _Key_Scan
if _key_scan = ? then …
If using interrupts add the following (skip last section from above):
Enable Interrupts
Config Int0 = Falling
On Int0 _int0_label
Enable Int0
.
.
.
if _key_scan = ? then …
.
.
.
_int0_label:
!rcall _Key_Scan
Return
The PCF8574 is connected as follows:
PCF8574
+5V
VDD
SDA
SCL
INT
P7
P6
+5V
A0
Hex adress 42
A1
A2
P0
P1
P2
P3
VSS
AVR- PortD.7
Gnd
AVR- PortD.6
AVR- INT0 (optional)
P5
Gnd
P4
C1 C2 C3 C4
A0, A1 and A2 gives the address
of the chip
A0 A1 A2 Pcf8574_lcd
0 0 0 &H40
1 0 0 &H42
0 1 0 &H44
1 1 0 &H46
0 0 1 &H48
1 0 1 &H4A
0 1 1 &H4C
1 1 1 &H4E
R1
R2
R3
R4
To observe when using interrupts!
Disable int0 before doing anything time consuming (RS232, LCD etc.) otherwise you may get
problem with those routines, when you press a key the program will jump to _key_scan.
The variable _key_scan holds the value of the key pressed (0 if none)
C1
C2
C3
C4
R1
1
2
3
4
R2
5
6
7
8
R3
9
10
11
12
R4
13
14
15
16
930940353.068.png 930940353.079.png 930940353.090.png 930940353.101.png 930940353.001.png 930940353.012.png 930940353.020.png 930940353.021.png 930940353.022.png 930940353.023.png 930940353.024.png 930940353.025.png 930940353.026.png 930940353.027.png 930940353.028.png 930940353.029.png 930940353.030.png 930940353.031.png 930940353.032.png 930940353.033.png 930940353.034.png 930940353.035.png 930940353.036.png 930940353.037.png 930940353.038.png 930940353.039.png 930940353.040.png 930940353.041.png 930940353.042.png 930940353.043.png 930940353.044.png 930940353.045.png 930940353.046.png 930940353.047.png 930940353.048.png 930940353.049.png 930940353.050.png 930940353.051.png 930940353.052.png 930940353.053.png 930940353.054.png 930940353.055.png 930940353.056.png 930940353.057.png 930940353.058.png 930940353.059.png 930940353.060.png 930940353.061.png 930940353.062.png 930940353.063.png 930940353.064.png 930940353.065.png 930940353.066.png 930940353.067.png 930940353.069.png 930940353.070.png 930940353.071.png 930940353.072.png 930940353.073.png 930940353.074.png 930940353.075.png 930940353.076.png 930940353.077.png 930940353.078.png 930940353.080.png 930940353.081.png 930940353.082.png 930940353.083.png 930940353.084.png 930940353.085.png 930940353.086.png 930940353.087.png 930940353.088.png 930940353.089.png 930940353.091.png 930940353.092.png 930940353.093.png 930940353.094.png 930940353.095.png 930940353.096.png 930940353.097.png 930940353.098.png 930940353.099.png 930940353.100.png 930940353.102.png 930940353.103.png 930940353.104.png 930940353.105.png 930940353.106.png 930940353.107.png 930940353.108.png 930940353.109.png 930940353.110.png 930940353.111.png 930940353.002.png 930940353.003.png 930940353.004.png 930940353.005.png 930940353.006.png 930940353.007.png 930940353.008.png 930940353.009.png 930940353.010.png 930940353.011.png 930940353.013.png 930940353.014.png 930940353.015.png 930940353.016.png 930940353.017.png 930940353.018.png 930940353.019.png
Zgłoś jeśli naruszono regulamin