Download filezillafor windows

Matrix to 4-bit Keypad Encoder

Project kindly submitted by: galaxy


A keypad-matrix is very nice, but.. they have disadvantages if used with microcontrollers.

That has to be different, and that's why I made a matrix decoder that reads the matrix, and transforms it to a 4-bits binary code.

This code matches with the printing on the key's of a 3 X 4 keypad. These 4 bits can be placed in the upper region of portB, so your interrupt lines (B0 and B1) are free again. Now you don't need pullups anymore, so you can use other ports as well for the keypad.

That's not all. If even those 4 lines are too much for you, then you can remove the jumper J5. Without jumper J5, every keystroke will be sent in asynchronous serial mode.

The Schematic


Please remember that every individual keypad can have it's own connections, so pay attention to this !!

Pin 1 from the keypad stands for row 3
Pin 2 ---> row 2
Pin 3 ---> column 1
pin 4 ---> row 1
pin 5 --->column 3
pin 6 ---> row 4
Pin 7 --->column 2

The PIC runs on its internal oscillator, so we spare out a crystal and 2 caps.

A 4-bit code can be taken from the middle 4 pins of J2. The outer pins must be connected to a 5 volt supply and GND.

If no key is pressed, the output has the value 15 (bin 1111). If a key is pressed, the output gives the corresponding value of that key. The * gets the value 10, and the # gets the value 11. Every keypress gives a friendly beep. Additionally a negative 1 ms pulse is given on J4. You can use this pulse as an interrupt trigger, if you wish. This pulse is generated after the data has arrived at the port. The data stays on the port until the key is released.

If you've chosen the serial configuration, then the data-signal can be taken from RA0 (pin 5 of the header).
The signal has a reverse polarity, is 9600 baud, 8 bits wide, and has no parity (9600, 8, n, 1)
There's also an interrupt pulse here, too. This is sent by RA1 (pin 4 of the header).
This pulse is generated before the data is sent, giving the main-controller the chance to anticipate it.

In both configurations (parallel & serial) you are free to use the interrupt pulse. There is no requirement for it.

Component list

Quantity
reference
description



7
R1-R7
smd-resistors
1
C1
smd-capacitor
5
J1-J5
SIL-headers male
1
J3
beeper
1
U1
PIC 16F628

The PCB

It is a small PCB of approx. 5 X 2.5 cm (2 X 1 "). The pic is a conventional dip.

All resistors, and the cap are smt-devices. You are free to mount the SIL-header on top or on the bottom of the PCB. Whatever is best for you.


The Software

The program is written in Proton+

Here is the asm-file, together with the include file.

And we finish with the hex-file.


I have chosen the RS-232 protocol for this project. If you would rather use another protocol like I²C, or SPI then it's easy to implement in the software.

About the Proton Compiler

Crownhill's Proton Plus Compiler is a part of the Proton Development Suite - A suite of British-developed applications enabling fast development of PICmicro's using the PICBASIC Language.

For more information on the Proton Development Suite, please visit www.picbasic.org