calculator-like code entry with matrix keypad and display


Results 1 to 36 of 36

Threaded View

  1. #4


    Did you find this post helpful? Yes | No

    Default lost...

    Hi Ioannis

    Thanks a million for the reply,tips and guidance.

    Yes Indeed it is your sample code as well as Aratti's that prompted this thread.

    See the code snippet you sent me here (all original and intact with no changes)
    Code:
     
    array   var byte[5]
    index   var byte
    i       var byte
    word_v  var word
    
    'Get keypress
    index=0
    
    loop:
    gosub key_read
    if mykey=32 then loop 'No key press returns 32
    array[index]=myvar
    index=index+1
    if index=5 then calculate_result
    goto loop
    ...
    
    caculate_result:
    word_var=0:mult=10000
    for i=index-1 to 0 step -1
        word_var=word_var*mult+array[i]
        mult=mult/10
    next i
    index=0
    goto display_result
    Ok so there were (and still are) quite a few things that didn't and don't make sense to me. And please understand I am battling to catch on to a lot of the coding tricks and reading the manual and forums and anything else that will give me some form of understanding to get functional.

    I took the code snippet and dissected it, tried my best to comment it and then add it to what I had so far.
    Then I compiled it solving each compile error as best I could (bearing in mind being a newbie it's difficult to spot common syntax errors and coding mistakes or areas that could be tweaked) and here is what I came up with:
    [code]
    'using mister_e's keypad code

    array var byte[5] 'the array set at 5
    index var byte
    i var byte
    word_var var word ' word for capturing data
    mult var byte a byte for multiplication << sould this be a word

    index=0 'sets index to 0

    loopy: 'main loop for keypress capture


    @ READKEYPAD _myvar 'read keypress variable
    LOOKUP myvar,[0,"123A456B789C*0#D"],myvar 'use lookup table to dsiplay proper keypress
    ''if mykey=32 then loop 'No key press returns 32 '<<no idea what mykey yshould be ?? a var or a word ?and why 32?
    array[index]=myvar 'build the array as the index number increases
    index=index+1 'when the code runs past here add 1 to index var
    if index=5 then calculate_result 'if the counter/index is 5 calculate result
    goto loopy 'start the loop again


    calculate_result: 'calculate results label
    word_var=0 'set word variable to 0
    mult=10000 'multiply result by 10000 to format number
    for i=index-1 to 0 step -1 'for loop begins
    word_var=word_var*mult+array[i] '
    mult=mult/10
    next i 'end of for statement
    index=0 'set index to 0
    goto display_result


    goto start


    display_result:
    lcdout word_var
    goto TX
    TX:
    hserout ["i got this string of numbers",$0d,$0a]
    hSEROUT ["Received:",STR myvar\5,$0d,$0a]
    'HSEROUT ["1st digit ", dec array(0),$0d,$0a]
    'HSEROUT ["2nd digit ", dec array(1), $0d,$0a]
    'HSEROUT ["3rd digit ", dec array(2), $0d,$0a]
    'HSEROUT ["4th digit ", dec array(3), $0d,$0a]
    'HSEROUT ["5th digit ", dec array(4), $0d,$0a]
    'HSEROUT ["5th digit ", word_var, $0d,$0a]
    goto clearkeys


    clearkeys:
    myvar = 0
    goto loopy

    end
    [code]

    So a few observations so far ...
    The code allows for a # or * or A,B,C,D to be typed in, this messes everything up of course.
    I have no idea what the array is holding when entering the keys.How can I display the whole array on the LCD ?
    After typing in the first few characters like 00123 ended with a hash the code just does its own thing -- well at least that's how it seems.
    HSEROUT works at least because everytime I press the # key I get things in MCS serial tool window, they're just wingdings and odd characters, but at least something is happening

    Is there a way to capture each keystroke and then add convert them to binary and then add them together and then display the result as decimal ?

    I used to have an 8-way dip switch connected to the PIC and then just set the binary number up on that and it was done ! Say for example the number 123 would be as easy as flipping the switches to 1111011 and that was that.
    With a keypad I can type in the number by pressing keys 1 (wich is not 1 unless we do a look-up) same for 2 and 3 and then each number is independent and 8 bits in size.
    So in order to get the number 123 into some sort of variable I have to

    1.accept all keypresses into an array and filter out the keys *,#,A,B,C,D,and if any of these are encountered remove them from the array
    (is there a table look-up I could implement for that ?

    2.check the size of the array and if it's 3 digits then I should multiply each digit independently so 1 by 100 then 2 by 10 and 3 by 1 (or do nothing to 1)

    3.once that's done I should then be able to add them together and finally derive a total ... this total can then be checked to see if it is VALID or not. For example if it is a 3 bit number and I only want a byte then it must be less than 255 otherwise generate an overflow error on lcd.

    4.Finally I have the number , then it must either be converted to binary or decimal depending on where it should go.

    And then to top it all off the modifiers for LCDOUT and HSERIN/OUT,HSERIN2/OUT SERIN/SEROUT SERIN2/OUT and their behaviour are all slightly different.

    That said though, at least I have some code to start working with and I certainly am trying and battling along and I would really appreciate any help,tips,tricks on any of the stupid mistakes I am making or have made in the along the way to finally getting a working code/keypress/data entry system using a 4x4 or 3x3 keypad and LCD.
    I was also wondering if this hasn't come up many a time before and it seems the forums are a little sparse for something that does exaclty this unless I am searching for the wrong info ?
    Kind regards
    Dennis
    Last edited by Dennis; - 15th December 2009 at 03:29.

Similar Threads

  1. a little help with keypad on 18f4520 please
    By Dennis in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 24th November 2009, 21:38
  2. Keypad input test
    By Kalind in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th October 2008, 05:00
  3. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 14:16
  4. LCD display not working properly
    By dilpkan in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 2nd February 2008, 08:43
  5. Keypad entry?
    By TONIGALEA in forum General
    Replies: 3
    Last Post: - 8th August 2004, 17:10

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