Maker Pro
Maker Pro

4x4 matrix with 8255 port expander

Hi guys,

I'm new to this forum.

I am currently doing my final year school project and i'm finding a difficulty with interfacing a 4x4 matrix keypad with and 8255 port expander (using port C) and all is connected to an 8051 microcontroller.

I'm using C language and everything is working on a simulator (Proteus) but on the hardware side i'm only able to write text on an LCD but not from the keypad.

Can anyone help me out pls?
Any tips and ideas on what to look out for etc etc


Thanks.
 

Harald Kapp

Moderator
Moderator
Oh my, the good old 8255...

You haven't given a schematic. So let me assume that the 4x4 keypad is connected similar like this:
C0...C3 = rows of the keypad
C4...C7 = columns of the keypad
(You can swap port numbers to fit your circuit).
There is a button between each row and column at the crossing points, thus 4x4 buttons.
You will have to configure 4 port pins for input, 4 port pins for output. Assume
C0...C3 = output
C4...C7 = input
You will also need a set of pull-up resistors (or pull down resistors, the choice is your's). Connect one pull-up resistor (e.g. 10 kOhm) from each column to Vcc. This ensures defined High level at the inputs when no button is pressed.

In order to read from the keyboard, the following sequence can be used:
program C0=0, C1=1, C2=1, C3=1
read C4...C7. This will be the state of the first 4 buttons.
program C0=1, C1=0, C2=1, C3=1
read C4...C7. This will be the state of the second 4 buttons.
program C0=1, C1=1, C2=0, C3=1
read C4...C7. This will be the state of the third 4 buttons.
program C0=1, C1=1, C2=1, C3=0
read C4...C7. This will be the state of the fourth 4 buttons.
You have now the states of all 16 buttons. Any button pressed will appear as "0" on the corresponding input pin, Not pressed buttons will be "1".

Harald
 
Top