Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Question about keyboard matrix

Status
Not open for further replies.

k3v1n

New Member
I'm wondering if its possible to use a similar circuit to the keyboard matrix circuit that you can find all over the place. What I'm trying to do is replace all the normally open switches with normally closed ones. Then with picbasic pro write a program that will tell you what switches if any are open. I've done a little experimenting and have got some results but its not perfect. I can get it to work with the top row of switches but does nothing after that.

This is my code ....
;-----------------------------------------------------------------------

CLEAR
DEFINE OSC 4 ; System speed
DEFINE LCD_DREG PORTD ; Define LCD connections
DEFINE LCD_BITS 4 ;width of data path
DEFINE LCD_DBIT 4 ;data starts on bit 4
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 1
ADCON1 = 7 ; Make PORTA and PORTE digital
LOW PORTE.2 ; LCD R/W low (write)
PAUSE 200 ; Wait for LCD to start

; define the variables
BUFFER VAR BYTE
ALPHA VAR BYTE ; counter for rows
COLUMN VAR BYTE
ROW VAR BYTE
SWITCH VAR BYTE

; SET UP PORT B PULL UPS
OPTION_REG.7 = 0 ; Enable PORTB pullups to make B4-B7 high
TRISB = %11110000 ; Make B4-B7 inputs, B0-B3 outputs,

; Set up the initial LCD readings
LCDOUT $FE, 1 ; Clear the LCD

BUFFER =PORTB
BUFFER = BUFFER ^%11111111

; print the first line
LCDOUT $FE, $80, "ROW=",BIN4 (BUFFER & $0F), "COL=", BIN4 BUFFER >>4
LCDOUT $FE, $C0,BIN8 BUFFER

END ; always end all programs with an END statement

;----------------------------------------------------

The last LCDOUT line displays 00010001, 00110001, 01110001, 11110001 when I run the program for 1st switch on (open), 1st and 2nd switch on (open), 1st, 2nd and 3rd switch on (open) and all the top row on. Or any combination of the top row the respective 0 or 1 is displayed. Nothing seems to work at all for any of the other rows of switches. I think its stuck on the first row. I'm trying to get to the point were if all switches are on it would display 11111111.
To add, I'm pretty new to the micro controller and picbasic programming. I'm using a Melabs Lab-X1 board with a PIC16F877A MPU. I'm not sure if I can do this with the circuit or if its just a matter of the programming. Any help would be greatly appreciated.
 
If you have a matrix of normally closed switches then each switch has to have a diode in series with it. Without the diodes the NC matrix looks like all the rows and columns are joined together - think about it.

A NC switch matrix is used on pinball machines and a good explanation of how they work can be found **broken link removed**.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top