Keypad input test


Results 1 to 10 of 10

Threaded View

  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 15:24.

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, 01:50
  2. help!! With Keypad change
    By clare1 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th December 2006, 21:13
  3. Replies: 8
    Last Post: - 17th September 2006, 17:46
  4. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29
  5. Serial Keypad Input
    By OKST8 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 28th April 2005, 23: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