Matrix Keypad routine


Closed Thread
Results 1 to 40 of 135

Hybrid View

  1. #1
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Question

    i have written this code. its just that im really confused and lost as to how to begin with the keypad. i kinda figured out how to hook up the keypad though. i just need help as to how to go about doing the code

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    i have written this code. its just that im really confused and lost as to how to begin with the keypad. i kinda figured out how to hook up the keypad though. i just need help as to how to go about doing the code
    I am HELPING. No need for whiney PM's.
    Key word here is HELPING...not DOING.
    I think you'll find a whole lot of people around here willing to HELP...some might even be willing to DO.
    Write some code, in fact, don't even write code, just write a sequence of thoughts of how you think the program should operate. The code will follow. That's how it works. You think about something and it happens eventually.
    As far as your keypad goes, what's wrong with the code that's provided earlier in the thread? I use it...works great for me.

  3. #3
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    well, i was thinking that when i push "Button A" of the keyapd, the upper setpoint will be displayed, "Button B" = Lower limit, "Button C" = Backspace, "Button D" = OK , "Button *" = alarm on/off, "Button #" = Main screen

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    well, i was thinking that when i push "Button A" of the keyapd, the upper setpoint will be displayed, "Button B" = Lower limit, "Button C" = Backspace, "Button D" = OK , "Button *" = alarm on/off, "Button #" = Main screen
    Ok, so you've defined the FUNCTIONs of the buttons...now how to you act on those functions.
    In fact, do yourself a favor and just work on adding one button at a time...

  5. #5
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    thats my point. I have no idea where to begin...i was thinking maybe scan keypad first, check if A or B was pressed and if so then act upon it by prompting the user to enter a desired setpoint. once that's done, press ok and return to the main display screen. the alarm can be set on for the desired lower setpoint and once the upper setpoint has been reached, the relay should switch on. vice versa

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    thats my point. I have no idea where to begin...i was thinking maybe scan keypad first, check if A or B was pressed and if so then act upon it by prompting the user to enter a desired setpoint. once that's done, press ok and return to the main display screen. the alarm can be set on for the desired lower setpoint and once the upper setpoint has been reached, the relay should switch on. vice versa
    Then write some code and see how it works!
    If it doesn't work, post the code, and I'm sure somebody will help you figure it out.

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


    Did you find this post helpful? Yes | No

    Default

    The first thing to do is open Mr. E's Keypad.bas and read the instructions he wrote for you.
    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.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    well, i was thinking that when i push "Button A" of the keyapd, the upper setpoint will be displayed, "Button B" = Lower limit, "Button C" = Backspace, "Button D" = OK , "Button *" = alarm on/off, "Button #" = Main screen
    Code:
    InterruptHandler:
    @ READKEYPAD _MyVar
    resume
    'now your key reading is stored in MyVar
    most 16 key keypads are laid out 123A 456B 789C *0#D, so 1=1 2=2 3=3 A=4 4=5 . . . .
    You can use this as is or use a lookup routine to alias the actual port reading to what
    you want, like so:
    Code:
    lookup MyVar,[0,"123A456B789C*0#D"],MyOtherVar
    now your key information stored in myOtherVar will mirror your keypad.
    so . . .
    Code:
    If myothervar = A then gosub Uppersetpoint
    if MyOtherVar = b then gosub . . . .easy
    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.

  9. #9
    Join Date
    Oct 2008
    Posts
    51


    Did you find this post helpful? Yes | No

    Default

    Hay guys and girls. I've been playing around with this coding this afternoon and i keep getting errors and when i dont nothing going as i thought it should so any chance somone could point out whats wrong please or point me in the right dirrection at least!

    My main coding:

    Code:
    TRISA=%00000011
    TRISB=%00000000
    TRISC=%11111110
    ADCON0=%11000000
    ADCON1=%00000111 
    INCLUDE "KeyPad.bas"         
    
        '                      
        '    Hardware connection
        '    ===================
        DEFINE KEYPAD_ROW        8       ' 8 row 
        define KEYPAD_ROW_PORT   PORTc   '   on PORTB
        DEFINE KEYPAD_ROW_BIT    0       '      <7:0>
        DEFINE KEYPAD_COL        4       ' 4 col 
        DEFINE KEYPAD_COL_PORT   PORTc   '   on PORTA
        DEFINE KEYPAD_COL_BIT    0       '      <3:0>
        DEFINE KEYPAD_DEBOUNCEMS 200     ' debounce delay = 200 mSec
        define KEYPAD_AUTOREPEAT 1       ' use auto-repeat
    ' LCD Display
    ' -----------
    ' Adjust these to suit your chosen LCD pinout
    '
    DEFINE LCD_DREG PORTb 			'Define PIC port used for LCD Data lines
    DEFINE LCD_DBIT 4 			'Define first pin of portb connected to LCD DB4
    DEFINE LCD_RSREG PORTb 			'Define PIC port used for RS line of LCD
    DEFINE LCD_RSBIT 3 			'Define Portb pin used for RS connection
    DEFINE LCD_EREG PORTb 			'Define PIC prot used for E line of LCD
    DEFINE LCD_EBIT 0 			'Define PortB pin used for E connection
    DEFINE LCD_BITS 4 			'Define the 4 bit communication mode to LCD
    DEFINE LCD_LINES 2 			'Define using a 2 line LCD
    DEFINE LCD_COMMANDUS 2000 		'Define delay between sending LCD commands
    DEFINE LCD_DATAUS 50 			'Define delay time between data sent.
        
        '
        '    Serial Communication definition
        '    ===============================
        DEFINE HSER_TXSTA 24h            ' enable transmit, BRGH=1
        DEFINE HSER_SPBRG 129            ' 9600 Bauds
    
        '   
        '    Variables definition 
        '    ===================
        myvar                    var byte
    
        '    ---------------------------------[Program Start]----------------------------------------------
    start:
        @ READKEYPAD _myvar
        hserout ["Key=",dec myvar,13,10]
    	gosub lcddisp
        goto start
    
    lcddisp:
    LCDOUT $FE, 1, myvar
    pause 60
    return
    end

    The modified Keypad code
    Code:
    TRISA=%00000011
    TRISB=%00000000
    TRISC=%11111110
    ADCON0=%11000000
    ADCON1=%00000111 
    INCLUDE "KeyPad.bas"         
    
        '                      
        '    Hardware connection
        '    ===================
        DEFINE KEYPAD_ROW        8       ' 8 row 
        define KEYPAD_ROW_PORT   PORTc   '   on PORTB
        DEFINE KEYPAD_ROW_BIT    0       '      <7:0>
        DEFINE KEYPAD_COL        4       ' 4 col 
        DEFINE KEYPAD_COL_PORT   PORTc   '   on PORTA
        DEFINE KEYPAD_COL_BIT    0       '      <3:0>
        DEFINE KEYPAD_DEBOUNCEMS 200     ' debounce delay = 200 mSec
        define KEYPAD_AUTOREPEAT 1       ' use auto-repeat
    ' LCD Display
    ' -----------
    ' Adjust these to suit your chosen LCD pinout
    '
    DEFINE LCD_DREG PORTb 			'Define PIC port used for LCD Data lines
    DEFINE LCD_DBIT 4 			'Define first pin of portb connected to LCD DB4
    DEFINE LCD_RSREG PORTb 			'Define PIC port used for RS line of LCD
    DEFINE LCD_RSBIT 3 			'Define Portb pin used for RS connection
    DEFINE LCD_EREG PORTb 			'Define PIC prot used for E line of LCD
    DEFINE LCD_EBIT 0 			'Define PortB pin used for E connection
    DEFINE LCD_BITS 4 			'Define the 4 bit communication mode to LCD
    DEFINE LCD_LINES 2 			'Define using a 2 line LCD
    DEFINE LCD_COMMANDUS 2000 		'Define delay between sending LCD commands
    DEFINE LCD_DATAUS 50 			'Define delay time between data sent.
        
        '
        '    Serial Communication definition
        '    ===============================
        DEFINE HSER_TXSTA 24h            ' enable transmit, BRGH=1
        DEFINE HSER_SPBRG 129            ' 9600 Bauds
    
        '   
        '    Variables definition 
        '    ===================
        myvar                    var byte
    
        '    ---------------------------------[Program Start]----------------------------------------------
    start:
        @ READKEYPAD _myvar
        hserout ["Key=",dec myvar,13,10]
    	gosub lcddisp
        goto start
    
    lcddisp:
    LCDOUT $FE, 1, myvar
    pause 60
    return
    end



    forgot to put the error code

    Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F876A "KEYPADTE.ASM" /l"KEYPADTE.lst" /e"KEYPADTE.err"
    Error[113] C:\PBP\PBPPIC14.LIB 2784 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2785 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2789 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2790 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2800 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2871 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2889 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2913 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2920 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2928 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2934 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\KEYPADTE.ASM 100 : Symbol not previously defined (PORTc)
    Error[113] C:\PBP\KEYPADTE.ASM 103 : Symbol not previously defined (PORTc)
    Error[113] C:\PBP\KEYPADTE.ASM 125 : Symbol not previously defined (PORTc)
    Error[113] C:\PBP\KEYPADTE.ASM 136 : Symbol not previously defined (PORTc)
    Halting build on first failure as requested.
    BUILD FAILED: Thu Nov 20 16:00:57 2008
    Attached Images Attached Images  
    Last edited by chrisshortys; - 20th November 2008 at 17:45.

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


    Did you find this post helpful? Yes | No

    Default

    YUP, that's what happen when you don't check the spelling of your DEFINEs. DEFINEs are case sensitive. So PORTb have to be written PORTB, and so on with all others.
    Steve

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

  11. #11
    Join Date
    Oct 2008
    Posts
    51


    Did you find this post helpful? Yes | No

    Default

    Cheers, so any clues as to whats wrong now? i dont get any reaction on the LCD and i get several ports flash high then low

Similar Threads

  1. calculator-like code entry with matrix keypad and display
    By Dennis in forum mel PIC BASIC Pro
    Replies: 35
    Last Post: - 16th December 2009, 22:58
  2. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 13:16
  3. I2C PCF8574 4X4 Keypad routine
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th January 2007, 21:25
  4. Inconsistent output on a 4x4 matrix keypad
    By markcadcam in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 24th November 2006, 03:54
  5. very basic matrix keypad question
    By kitcat in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th July 2006, 21:33

Members who have read this thread : 1

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