Keypad input test


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2008
    Posts
    47

    Exclamation Keypad input test

    Please could you debug my program. It displays strange lines across the LCD at the start then it prompt the user to enter high setpoint but the keypad doesnt seem to work and the program just halts at that point. It's purpose is to measure and display temperature. I've added a keypad to enable the user to set upper and lower setpoints. At the start up of my design, i would like to prompt the user to enter setpoints. Is my code doing what i want it to do? please let me know. Thank you!

    ' Define LCD registers and bits

    Define LCD_DREG PORTB
    Define LCD_DBIT 0
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 5
    Define LCD_EREG PORTB
    Define LCD_EBIT 4
    dEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE KEYPAD_ROW 4 ' 4 ROW keypad
    DEFINE KEYPAD_ROW_PORT PORTC ' ROW port = PORTC
    DEFINE KEYPAD_ROW_BIT 4 ' ROW0 = PORTC.4
    DEFINE KEYPAD_COL 4 ' 4 COL keypad
    DEFINE KEYPAD_COL_PORT PORTC ' COL port = PORTC
    DEFINE KEYPAD_COL_BIT 0 ' COL0 = PORTC.0

    Pause 1000
    LCDOut $FE,1,"Initializing ...."
    pause 1000
    gosub setuppersp
    gosub setlowersp

    Pause 1000

    adval var word ' Create adval to store result
    temp var word ' Create temp to store result
    temp1 var word ' Create temp1 to store result
    col VAR BYTE ' Keypad column
    row VAR BYTE ' Keypad row
    key VAR BYTE ' Key value
    MyOtherVar var word
    uppersp var word
    lowersp var word

    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %10000010 ' Set PORTA analog and RIGHT justify result
    ADCON0 = %11000001 ' Configure and turn on A/D Module
    Pause 100 ' Wait 0.1 second


    loop: ADCON0.2 = 1 ' Start Conversion

    AGAIN: Pause 1
    If ADCON0.2 = 1 Then AGAIN ' Wait for low on bit-2 of ADCON0, conversion finished

    adval.highbyte = ADRESH ' Move HIGH byte of result to adval
    adval.lowbyte = ADRESL ' Move LOW byte of result to adval

    Lcdout $fe, 1 ' Clear screen
    temp=50*adval ' Conversion to Degrees
    temp=temp/100
    Lcdout "TEMP = ",DEC temp,$DF,"C" ' Display the value of temp
    temp1 = temp*18 ' Conversion to Fahrenheit
    temp1 = temp1+320
    temp1 = temp1/10
    lcdout $FE,$C0, "TEMP = ",dec temp1,$DF,"F" ' Display the value of temp
    Pause 1000 ' Wait 1 second

    Goto loop ' Do it forever
    End

    ' Keypad Subroutine

    scan:
    Gosub getkey ' Get a key from the keypad
    PAUSE 200
    Goto scan ' Do it forever

    ' Subroutine to get a key from keypad
    getkey:
    Pause 50 ' Debounce

    getkeyu:
    ' Wait for all keys up
    PORTC = 0 ' All output pins low
    TRISC = $f0 ' Bottom 4 pins out, top 4 pins in
    IF ((PORTC >> 4) != $f) Then getkeyu ' If any keys down, loop

    Pause 50 ' Debounce

    getkeyp:
    ' Wait for keypress
    For col = 0 to 3 ' 4 columns in keypad
    PORTC = 0 ' All output pins low
    TRISC = (DCD col) ^ $ff ' Set one column pin to output
    row = PORTC >> 4 ' Read row
    IF row != $f Then gotkey ' If any keydown, exit
    Next col

    GoTo getkeyp ' No keys down, go look again

    gotkey: ' Change row and column to key number 1 - 16
    key = (col * 4) + (NCD (row ^ $f))
    Return ' Subroutine over

    lookup key,[0,"123A456B789C*0#D"],MyOtherVar

    End

    setuppersp:
    LCDOut $FE,1,"Enter High Setpoint:"
    gosub getkey
    LOOKUP key,["123A456B789C*0#D"],uppersp
    RETURN

    setlowersp:
    LCDOut $FE,1,"Enter Low Setpoint:"
    gosub getkey
    LOOKUP key,["123A456B789C*0#D"],lowersp
    return
    Last edited by Kalind; - 7th October 2008 at 16:24.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    There is no need to send multiple PMs, when someone gets the time, they will help.

    First thing I see, it looks like you copy/pasted from at least two different programs, but that was it. You did not do any re-write to make them work. The duplicate "END"s is what I am getting at.

    Next,
    then it prompt the user to enter high setpoint
    You say the program does this, but I do not see where.

    Then I do not see where the code goes from the main loop to the keypad routine.

    Without doing a complete re-write for you, I will suggest that you work on one thing at a time. Maybe start with the keypad. Get it working, then move on to saving a value.

    Do not try to write the whole thing at once and then try to figure out where it went wrong.

    I normally use a shift register for keypads, so if you want to do it the way you have it, go back and read http://www.picbasic.co.uk/forum/showthread.php?t=3250

    That should get you going there. Then we can work on saving a value.
    Dave
    Always wear safety glasses while programming.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    3 buttons instead of the keypad
    One to drive the value up (up arrow?), one to drive the value down (down arrow?), one to save the value and move on (enter?).
    maybe even a 4th button to reset the value back to a default value (ESC?).
    A lot easier than 'punching in numbers'.
    Overdesigning a project sometimes really sucks...

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


    Did you find this post helpful? Yes | No

    Default

    Are you trying to use Mister_e's Keypad.bas program ? You will need the statement INCLUDE "keypad.bas" early in your code. You will need interrupts, and it will require you to use MPASM as the assembler unless you use Darrel's modified version.
    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.

  5. #5
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    no im using another keypad routine. can u help me out on this one joe?

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    no im using another keypad routine.
    I thought you were using Steve's for some reason.
    Where did you get the code and how is the keypad connected to the pic.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    connected to the pic via port c.

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    I thought you were using Steve's for some reason.
    Where did you get the code and how is the keypad connected to the pic.
    I did a search on KEYPAD_ROW_PORT and the only places I could find that PARTICULAR define is connected with Steve's keypad routine...
    hmmmm........

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This looks like part of you code.
    http://www.melabs.com/resources/samples/x1/pbp/keyx.bas
    and here is the schematic for it
    http://www.melabs.com/downloads/labx1sch.pdf
    Make the necessary hardware changes and get the above code working. Do not add anything else yet, just the keypad code. (maybe a blinky to see if thing are running) but nothing else.

    Then we will go from there.
    Dave
    Always wear safety glasses while programming.

  10. #10
    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
    no im using another keypad routine. can u help me out on this one joe?
    All I can do to get Steve's routine to work, I will be posting something using it when I kill off a couple of bugs in my code, Finally with some help from Jeremy got my interrupts to work
    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. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 02:50
  2. help!! With Keypad change
    By clare1 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th December 2006, 22:13
  3. Replies: 8
    Last Post: - 17th September 2006, 18:46
  4. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 6th May 2005, 00:29
  5. Serial Keypad Input
    By OKST8 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th April 2005, 00:49

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