Matrix Keypad routine


Closed Thread
Results 1 to 40 of 135

Hybrid View

  1. #1
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    It looks quite comprehensive.

    I tend to base most of my algorithms around direct logic - boolean algebraic structures - rather than continuous mathematics, i.e calculations. PIC's are not as well equipped for calculations.

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


    Did you find this post helpful? Yes | No

    Default

    If that was true... ASM additions, substraction, bit shifting functions and few STATUS register bits wouldn't exist...(carry/Borrow, Z)
    Last edited by mister_e; - 12th May 2007 at 23:35.
    Steve

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

  3. #3
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post On Par?

    Quote Originally Posted by mister_e View Post
    If that was true... ASM additions, substraction, bit shifting functions and few STATUS register bits wouldn't exist...(carry/Borrow, Z)
    So, you believe that a PIC performs on par with: A = (100 / I) + (J * 2) Vs IF B = 1 THEN A = 120 ?
    Huge amount of work for the PIC to do something like this: A = (100 / I) + (J * 2)
    100 x the num of clock cycles perhaps?
    Last edited by T.Jackson; - 13th May 2007 at 06:47.

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


    Did you find this post helpful? Yes | No

    Default

    Trent, If your example was right i could agree with some part of it... programming method and code optimization is an endless story... i'm not going to argument on which is better, which is worst... it's not what the actual thread is about anyway.

    100X ??? NAH, i don't think so. Depending the Value of I, few times maybe... but not 100 for sure. and * 2, is just a Byte shifting, one position to the left... not much... 1-2 cycle not much.
    -----------------------------

    Charudatt,
    before going in sleep mode, make sure those PINs are set to input (with pull-up) and the others are set LOW and OUTPUT (or input but with pull-down resistor). Once you'll press a key, RB<7:4> should see the LOW signal... which should wake your PIC, then you call the keypad scan.
    Last edited by mister_e; - 13th May 2007 at 09:11.
    Steve

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

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    I tend to base most of my algorithms around direct logic - boolean algebraic structures - rather than continuous mathematics, i.e calculations. PIC's are not as well equipped for calculations.
    Huh? Lookups have their place (and I love them when needed) but to say PICs are not equipped for calculations is just plain silly.

    For all your projects (that you have posted), was time of the issue or code space? (answer = the latter). With your example equation, which one takes less code space? Which one is faster for larger I? (answer = calculation based approach).

    Code:
    ' Calculation based equation A = 100/I +J*2
    If I > 100 then
    A = J<<1
    ELSE
    A = 100
    FOR X = 1 to 100
    A = A – I
    IF A < I then OUT
    NEXT X
    OUT:
    A = X+ J<<1
    ENDIF
    or
    Code:
    ' lookup based equation A = 100/I +J*2
    IF I = 1 then A = 100+J<<1
    If I = 2 then A = 50 +J<<1
    If I = 3 then A = 33+J<<1
    If I = 4 then A = 25+J<<1
    ...
    ' (a bunch more  if-thens)
    ...
    if I =100 then A = 1+J<<1
    If I > 100 then A = J<<1
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  6. #6
    Join Date
    May 2007
    Location
    Harvest, Alabama
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Pull Up Resistors

    I know the Pull up Resistor attaches to Vss but where does it go else wise? Also... What happens to other test programs etc by its presence?

    Paul

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    To port B.

    As for the programs, what programs? Depends on what are the programs doing... Usually the port B with PU enabled, reads as all 1s.

    Ioannis

  8. #8
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Smile Don't twist my words...

    Quote Originally Posted by paul borgmeier View Post
    Huh? Lookups have their place (and I love them when needed) but to say PICs are not equipped for calculations is just plain silly.
    I didn't say not equipped - I said not as well equipped. And, I'm more so referring to something that's more so "hard coded" over calculations. When I say hard coded I'm talking about something that's direct as in (a = 100) Vs (a = b x 10 / 2) No prizes for guessing which is faster and uses less resource.
    Last edited by T.Jackson; - 23rd May 2007 at 09:28.

  9. #9
    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 T.Jackson View Post
    I didn't say not equipped - I said not as well equipped. And, I'm more so referring to something that's more so "hard coded" over calculations. When I say hard coded I'm talking about something that's direct as in (a = 100) Vs (a = b x 10 / 2) No prizes for guessing which is faster and uses less resource.
    If a is hard coded to equal 100, then I would guess b and c would be hard coded too. If I understand you correctly this is what the PIC a good for. If this was all I had to do I good do it on paper once and would not have to bother with all of this programing and such. In my world variables change.

    In you opinion, what should we all be using?
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    May 2007
    Location
    Harvest, Alabama
    Posts
    10


    Did you find this post helpful? Yes | No

    Unhappy Pullup resistors

    How do we determine what the pullup should be? I mean 100 to 300 ohms or 10 K ohms doesn't exactly give me the data I need. (Does it vary with the circuit being driven for example?) I really want to trigger the circuit with a minimum of time so I want the pullup fast so that my transistors (Nice NPN's for switching) with about 4.7 K ohms lead in resistance trigger off pretty much as fast as any current comes on the pin to signal it.

    I will be pushing a signal in the switch of the NPN transistor so that there is some current to pull a MOSFET fast. I need some current to move like NOW.

    In any case since I just cooked a $15 chip and an X1 Board , I really want to know some answers. (I just burned up some money) I need to know what voltage appears on the pins of the chip when we set for example a PORTA.2 =1. or PORTA.2 = 0 Is it on PORTA.1 = 1 a positive or negative voltage. It was logic testing that cooked this equipment.

    All advice will be appreciated.

    Well I got a cross of a posting that occurred between my post and an answer.

    The issue of Pullups seems to be a feature of the pin to cause it to draw some current to make it pull down a few thousandths of an ampere so that the circuit stays logic stable. I would think that if I am driving a transistor as I am the obvious value to use is about 10K because the transistor will have a 4.7 K or so leading out of the logic pin into the transistor Emitter. Or does this 4.7 to Vss draw down enough power so that the transistor needs no other resistor on the emitter?

    Generally a 5 VDC to emitter of a switching transistor with logic state high would take a 4.7 K ohm in the way of the signal feeding into the emitter (P of the NPN). If you take a 5 VDC state with a 10 K ohm to Vss and the positive voltage on the pins as high logic state then a 4.7 to the emitter should keep enough current to the transistor to open the gate so I am guessing based upon the previous answer that a 10 K ohm is in order (???)

    When we change from an input drain state as in the keyboard to an output control state, I would suspect that we add a current to bring the pin near switch on state but just below in order to logically control things, Is this so?


    Thanks
    Last edited by CluckShot; - 18th June 2007 at 00:52. Reason: cross posting

  11. #11


    Did you find this post helpful? Yes | No

    Default Optional timeout keyboard routine

    Hi MisterE

    Using with succes your keypadroutine on a 4x2 keypad

    I was wondering if it would be possible to jump out the keypadroutine if no key is pressed
    in order to handle the main loop

    I need to receive some serial commands by HSERIN, but when a key is pressed
    it should go to a label and then return to the main loop checking Hserin

    Now it waits for a keypress

    Thanks

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


    Did you find this post helpful? Yes | No

    Wink thanks guys

    T. Jackson & Mr. E,

    Nice work to both of you regarding Matrix Keypads!

    I have used Trents example with great success, I plan on trying out Mr. E's with a handheld Wireless panel/LCD I put together for work. I want to add a 4x4 matrix keypad to the front of the reciever case and upgrade my TXM/RSM LR LINX modules to the new LT tranciever type. I really think having the matrix keypad will expand (the crap out of) the types of commands I can send.....wall mounted reciever, robot, whatever....
    Attached Images Attached Images  
    Padawan-78

  13. #13
    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

  14. #14
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Exclamation Need help desperately!!!

    I'm doing a temperature control system. Pretty new to PIC programming. I have managed to display temperature on the LCD using an LM35 sensor and a 16 x 2 lcd with a 16F873. I want to add on a 4 x4 matrix keypad so that i can set setpoints to switch a relay and a low warning buzzer I have no idea how to program for the above mentioned add-ons. Please could someone help me. below is my code which will obviously need additions and a scematic of my circuit is attached . Please could somebody help me with this!!

    ' 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

    adval var word ' Create adval to store result
    temp var word ' Create temp to store result
    temp1 var word ' Create temp1 to store result

    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
    Attached Images Attached Images  

  15. #15
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    HI
    ABOUT THE ROUTINE WRITTEN BY MR MISTER_E.
    I NEED HELP HOW TO MAKE THE NUMBERS ARE IN SERIES EXAMPLES 12345566
    AND THEN PRESS THE BUTTON # SEND VIA SERIAL A SEQUECIA.
    Code:
    #CONFIG
        __config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _LVP_OFF & _WRT_OFF   
    #ENDCONFIG
    
    DEFINE OSC 4 
    
    TRISA=%00000011
    TRISB=%00000000
    TRISC=%11111110
    ADCON0=%11000000
    ADCON1=%00000111 
    INCLUDE "KeyPad2.bas"         
    
    '                      
    '    Hardware connection
    '    ===================
    
    DEFINE KEYPAD_ROW		4      
    DEFINE KEYPAD_ROW_PORT   	PORTC   
    DEFINE KEYPAD_ROW_BIT	0
    DEFINE KEYPAD_COL        	3
    DEFINE KEYPAD_COL_PORT   PORTC
    DEFINE KEYPAD_COL_BIT    	4
    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
    '
    '----DEFINIR   LCD--------------------------------------------------------------
    DEFINE LCD_DREG PORTB     ' LCD data port
    DEFINE LCD_DBIT 4         ' LCD data starting bit
    DEFINE LCD_RSREG PORTB    ' LCD register select port
    DEFINE LCD_RSBIT 2        ' LCD register select bit
    DEFINE LCD_EREG PORTB     ' LCD enable port
    DEFINE LCD_EBIT 3         ' LCD enable bit
    DEFINE LCD_BITS 4         ' LCD data bus size
    DEFINE LCD_LINES 2        ' Number lines on LCD
    DEFINE LCD_COMMANDUS 5000 ' Command delay time in us
    DEFINE LCD_DATAUS 50      ' Data delay time in us
    
    mykey   VAR BYTE
    myvar   var byte
    array   var byte[5]
    index   var byte
    i       var byte
    word_v  var word
     
    LCDOUT $FE,1,  "  FONTE DIGITAL   "
    PAUSE 1000
    LCDOUT $FE,1
        '    ---------------------------------[Program Start]----------------------------------------------
    start:
        @ READKEYPAD _myvar
    	gosub lcddisp
        goto start
    
    lcddisp:
        LCDOUT $FE,$C0,DEC4 myvar 
        pause 60
        return
        end
    Attached Images Attached Images  

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 : 2

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