4x4 keypad Help


Results 1 to 7 of 7

Thread: 4x4 keypad Help

Threaded View

  1. #1
    Join Date
    Apr 2008
    Posts
    3

    Exclamation 4x4 keypad Help

    Hi all
    i am using a 18f452 with the 4 x4 keypad connected to portB
    this is on the proton Development board and the connections are as the attachment below
    All is get displayed on my lcd is

    " Keypad Test "
    "Press any key"
    I have ran the program on micro studio ICD and the program seems to be struck
    in this loop
    ==========================================
    getkeyu:
    ' Wait for all keys up
    PORTB = 0 ' All output pins low
    TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
    If ((PORTB >> 4) != $f) Then getkeyu ' If any keys down, loop

    Pause 50 ' Debounce
    ================================================== ====


    Is there something i am missing
    i have the complete code below and

    ================================================== ==============
    DEFINE LOADER_USED 1 ' uses a bootloader

    @ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H

    Define OSC 20
    clear

    DEFINE LCD_DREG PORTD ' Use Portd for LCD Data
    DEFINE LCD_DBIT 4 ' Use Upper(4) 4 bits of Port
    ' PORTD-4 thru PORTD-7 connects to
    ' LCD DB4 thru LCD DB-7 respectively
    DEFINE LCD_RSREG PORTE ' PORTE for RegisterSelect (RS) bit
    DEFINE LCD_RSBIT 0 ' PORTE-0 pin for LCD's RS line
    DEFINE LCD_EREG PORTE ' PORTE for Enable (E) bit
    DEFINE LCD_EBIT 1 ' PORTE-1 pin for LCD's E line

    DEFINE LCD_BITS 4 ' Using 4-bit bus
    DEFINE LCD_LINES 2 ' Using 2 line Display
    DEFINE LCD_COMMANDUS 2000 ' Command Delay (uS)
    DEFINE LCD_DATAUS 50 ' Data Delay (uS)

    ' ** Define LCD Control Constants **

    I CON 254 ' Control Byte
    Clr CON 1 ' Clear the display
    Line1 CON 128 ' Point to beginning of line 1
    Line2 CON 192 ' Point to beginning of line 2
    Line3 CON 148 ' Point to beginning of line 3
    Line4 CON 212 ' Point to beginning of line 4

    '
    ' Initialise Hardware
    ' -------------------

    TRISA=%00000000
    TRISB=%00000000
    TRISC=%10000000
    TRISD=%00000000

    INTCON2.7 = 1 ' Enable PORTB pullups
    ADCON1 = 7 ' Make PORTA and PORTE digital
    Low PORTE.2 ' LCD R/W low (write)

    Pause 1000 ' Wait for LCD to start

    lcdout I,Clr:Pause 30
    lcdout I,Line1," Keypad TEST "
    lcdout I,Line2,"..Power On.. !!"

    ' Define program variables
    col var byte ' Keypad column
    row var byte ' Keypad row
    key var byte ' Key value



    lcdout I,Clr:Pause 30
    lcdout I,Line1," Keypad Test "
    lcdout I,Line2, "Press any key" ' Display sign on message

    loop: Gosub getkey ' Get a key from the keypad
    lcdout I,Clr:Pause 30
    lcdout I,Line3, #key
    Pause 50
    Goto loop ' Do it forever


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

    getkeyu:
    ' Wait for all keys up
    PORTB = 0 ' All output pins low
    TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
    If ((PORTB >> 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
    PORTB = 0 ' All output pins low
    TRISB = (dcd col) ^ $ff ' Set one column pin to output
    row = PORTB >> 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

    End

    Best Regards
    Sabu
    Attached Images Attached Images  

Similar Threads

  1. connecting a 4X4 keypad
    By fadibasic in forum Schematics
    Replies: 6
    Last Post: - 12th November 2008, 17:52
  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. 4x4 Keypad and LCD sharing port B
    By msnm4 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th May 2008, 08:13
  4. I2C PCF8574 4X4 Keypad routine
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th January 2007, 21:25
  5. Inconsistent output on a 4x4 matrix keypad
    By markcadcam in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 24th November 2006, 03:54

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