0% found this document useful (0 votes)
230 views

I2c To Keyboard Interface

This document describes how to interface a matrix keyboard to an AVR microcontroller using an I2C PCF8574 I/O expander. By connecting the PCF8574 to the microcontroller using only two I2C pins, the keyboard can be scanned. Interrupts can also be used to detect key presses with only one additional pin. The PCF8574 address is set using its A0, A1, A2 address pins. Scanning the keyboard updates a variable that indicates which key is pressed, allowing the program to respond accordingly.

Uploaded by

kondoritocl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
230 views

I2c To Keyboard Interface

This document describes how to interface a matrix keyboard to an AVR microcontroller using an I2C PCF8574 I/O expander. By connecting the PCF8574 to the microcontroller using only two I2C pins, the keyboard can be scanned. Interrupts can also be used to detect key presses with only one additional pin. The PCF8574 address is set using its A0, A1, A2 address pins. Scanning the keyboard updates a variable that indicates which key is pressed, allowing the program to respond accordingly.

Uploaded by

kondoritocl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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:










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


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

C1 C2 C3 C4
R1
R2
R3
R4
VDD
SDA
SCL
INT
P7
P6
A1
A2
P0
P1
P2
P3
VSS P4
P5
A0
PCF8574
Gnd
Gnd
+5V +5V
Hex adress 42
AVR- INT0 (optional)
AVR- PortD.6
AVR- PortD.7

You might also like