Keyboard Matrix with a Twist


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Oct 2008
    Posts
    11

    Default Keyboard Matrix with a Twist

    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.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

  3. #3
    Join Date
    Oct 2008
    Posts
    11


    Did you find this post helpful? Yes | No

    Default A reply i got on another forum which explains the hardware needed

    A conventional keyboard matrix can be drawn as rows and columns of wires, with a switch where each row wire crosses a column wire.
    You scan the matrix by (for example) having pull-up resistors on each of the column wires. You drive one of the row wires low, and see which of the column wires have gone low in response - and you conclude that the switches on the junctions between the driven row and the responding column(s) are closed (i.e. pressed).

    This is fine until you have several switches closed.
    Suppose you have the switches that join row A with column 2, row A with column 3 and row B with column 3 all closed.
    When you pull row B low, column 3 will be pulled down.
    The problem is that this will pull row A low. And this will pull column 2 low so you think you have the switch between row B and column 2 closed as well.
    (Sorry I'm no good at ascii art).

    There is a fix:
    Put a diode in series with each switch.

    Hope this helps.
    - Danish

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    appart from having an existing zillion of these in stock, could you explain WHY you want to use closed-type switches???

    Sure it's all doable...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Oct 2008
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    I'm trying to make my own alarm system.

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Welcome back Steve.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. 10x4 matrix keyboard using only portB
    By aratti in forum Code Examples
    Replies: 19
    Last Post: - 16th November 2011, 09:39
  2. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 16:10
  3. reading and conecting 10x6 matrix keyboard
    By ustredna in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 9th August 2006, 03:04
  4. LCD + keyboard matrix minimal I/O
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st June 2006, 19:49
  5. Matrix keyboard problem
    By MegaADY in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 9th May 2005, 18:50

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts