Matrix Keypad routine


Closed Thread
Results 1 to 40 of 135

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96


    Did you find this post helpful? Yes | No

    Red face

    Hello,
    Just an hour ago I tried to include Mr. E's Keypad.bas file in pbp folder and my local "pic_programs" folder. I DID rename the txt file and saved it to .BAS file.
    Here is the code....
    Code:
    INCLUDE "KeyPad.bas"         
    myvar var byte
    
    
    start:
        @ READKEYPAD _myvar
        hserout ["Key=",dec myvar,13,10]
        'LCDOUT 254,ROW1,"COMMAND", DEC MYVAR
        goto start
    Won't compile....
    I keep getting lots of "opcode expected instead of....'kb_row','kb_col', 'debounce_delay' " errors. I did read the thread about the errors found when you don't save as a .BAS file but I must not be seeing something obvious, happens to me alot on this forum.

    Mr. E could you lend a hand,

    I am using version 2.50A & PM assembler
    Padawan-78

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    With Steve's version, you have to use MPASM.

    For PM, use the version I recently uploaded to Post#82

    hth,
    DT

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    Hi Guys ,

    Well this keyboard matrix routine has been here a while and works well.

    but if you need to place a 1 row or column port pin on another port out of sequence then you have a problem.

    I face this as i changed from 16f1947 to 18f67k22 on the pcb , where the 16f1947 has portF.0 , and 18f67k22 does not
    as you guessed a row pin was on Portf.0

    PORTF.0 -3 was row ,portb 0-3 was column , so no problem with the column port , but row0 wont work on an non existent port
    so the new row0 port was connected to a spare pin at portG.4

    PortG.4 TRES direction was set to output prior to keypad.bas include used , but could have been set in in the keypad.bas section of code after the asm that sets the TRES for the colume and row ports assigned


    I used the port offset value to point portG.4 , when it was selecting row0 , and set the POrtG.4 =1 prior as per steves comments
    the offset value 12 is worked out 12 port locations past portF0

    i also did not care if portF.0 TRES were set to output as per steves routine , but if this was an issue , removing the ASM code that sets the TRES in keypad.bas and do it as per normal would have been ok


    I hope this helps someone that has a similar problem

    cheers

    Sheldon

    Code section prior to change
    =====================

    Code:
    ScanKeypad:
            key=0                                              ; no key is press
            row=0                                              ; begin scan @ ROW0
            col=0                                              ; and COL0
                   
            kb_row_PORT=kb_row_PORT | InitialState             ; set all ROW bits to 1 using bitwise OR
            repeat                                             
                
              
                  ROWBIT=ROW+KB_ROW_BIT                    ; point to a ROW bit
                  kb_row_PORT.0[RowBit]=0                      ; clear actual ROW bit
    after code change
    ==============

    Code:
    ScanKeypad:
            key=0                                              ; no key is press
            row=0                                              ; begin scan @ ROW0
            col=0                                              ; and COL0
            PORTG.4 = 1                                        ; Setup row-0 = 1 
            
            kb_row_PORT=kb_row_PORT | InitialState             ; set all ROW bits to 1 using bitwise OR
            repeat                                             
                
                if row = 0  then 
                   Rowbit = 12                                 ; offset amount for row 0  from PortF.0 to point to PortG.4 
                 else  
                  ROWBIT=ROW+KB_ROW_BIT                        ; point to a ROW bit
                endif   
                  kb_row_PORT.0[RowBit]=0                      ; clear actual ROW bit

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