calculator-like code entry with matrix keypad and display


Closed Thread
Results 1 to 36 of 36

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default update

    Hi guys

    Just a few updates
    Jerson ...still trying to see what's wrong with the code snippet you send .. did you try it at all ?
    You mentioned raw characters .. did you mean I shouldn't do a lookup ?

    Joe... I'm busy going through the gate entry code.

    Will feedback as soon as I get more info :-)

    Kind regards
    Dennis

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    ......So the problem now is how to get numbers which are less than 3 digits to work.
    For example if I enter the number 99 I get 227 in MCS serial tool
    Another example is the number 1 (single digit) shows up as 195

    I am trying to figure out why but can't see it as yet.
    Dennis the reason is that the array are no cleared. Add the three lines in red to the previous snippet and you are in business

    Al.

    Code:
    Array var Byte [3]
    A0 var byte
    B0 var Byte
    KeyPress Var Byte ' will contain the ascii character of the key pressed
    
    A0=0
    
    Ini:
    If KeyPress = "#" then
    
    if A0=2 then
    B0= (Array[0]*100)+(Array[1]*10)+Array[2]
    HSEROUT [B0]
    endif
    
    if A0=1 then
    B0= (Array[0]*10)+Array[1]
    HSEROUT [B0]
    endif
    
    if A0=0 then
    B0= Array[0]
    HSEROUT [B0]
    endif
    
    A0=0
    Array[0]=0
    Array[1]=0
    Array[2]=0
    ENDIF
    
    If A0>2 then Ini
    
    Array[A0]=KeyPress -48
    A0=A0+1
    goto Ini
    PS. Dennis the matter was just more complicated so I added the complete correction. I sure you will understand where the problem was.
    Al.
    Last edited by aratti; - 16th December 2009 at 18:44.
    All progress began with an idea

  3. #3


    Did you find this post helpful? Yes | No

    Default still struggling..

    Joe

    Thanks for pointing me to the gate access example, unfortunately it does not cover what I am after.
    The gate combo program compares each digit as it is typed in to a pre-stored value in eeprom and based on a successful match eventually enable a pin to go high.
    Yes granted it does utilize mister_e's keypad code (thanks mister_e...brilliant job - it work's like a charm, no hassle no fuss!)

    It does do a lookup as does my example and this is to get the raw scan codes into a 'familiar' character.

    It does not capture each keypress into an array.
    It does not sum the individual keystrokes and present them as a single byte or word.

    I think the gate access code is awesome and I would just like to say thanks to Lloyd for offering the code after he had paid mister_e to write it.

    And after having said that, it may be a good time to point out that as much as it is easy and simple to cut and paste pre-built code into the compiler window, this method does nothing for one's education and learning experience. I would like to battle along with code snippets and tips and tricks to eventually get to a working solution , however rough and un-polished it may be.

    Yes , agreed , I'm sure it is less frustrating but where's the fun without battling along (especially for me a 'reborn' PIC newbie hobbyist) until 2 or 4am sometimes until I eventually get something working.
    I find the forum a fantastic place to get other ideas and share experiences with others who have the same interest , be it hobby or vocation or otherwise.

    As you know you can read the manual and google and read sources for hours and then eventually get to a point of giving up or coming right.
    I think most of the people on the forum post a message at the point where they have reached the stage where they want to bash their head against a wall and decide to eventually give in and post a message.
    Posting a message on the forums can be a rather daunting thought or task because quite often people flame someone for saying the wrong thing or being out of line, not only that, the person posting often feels quite shy since they may be laughed at or 'looked down upon' by some highly skilled few who don't suffer fools easily.
    After having battled for nearly 3 months now to get where I am at, I completely understand a newbie's plight to getting functional.
    And in the time I have been lurking around on these forums and seeing how to create new threads and add code snippets and URL's and also get into some sort of functional coding style.
    I am more than happy to help someone get functional with their project and hope that someday I will have as much knowledge as most of the people who frequent this forum.

    I would just like to say THANK YOU to all those who I have interacted with and who have offered assistance to my (sometimes) absurd and 'silly' questions :-)

    And a big THANK to all of the people on this forum for keeping it going !

    On a final note ....

    I am still battling to capture 3 keystrokes into a var/byte/array ,index them , and then add them all up so that they are represented by one byte.
    I just can't see where I am going wrong :-(

    Kind regards

    Dennis

  4. #4


    Did you find this post helpful? Yes | No

    Default Al ..........

    Hi Al


    Welcome back :-) and how are you tonight ?

    Was it Siesta time in Milano ?
    :-)

    Wondered if you had disappeared or given up on me :-)

    Will try it right now and feedback asap !

    By the way is that the reason for the anything but 3 bits correct value issue ?

    Dennis

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Wondered if you had disappeared or given up on me :-)
    No Dennis, I had a long hard day at work!

    Did you read also my added code?

    Al.
    All progress began with an idea

  6. #6


    Did you find this post helpful? Yes | No

    Default something strange...

    Hi Al ...

    Sorry to hear about the long hard work day :-( it was a public holiday in my country .. so it felt like a weekend :-)

    I tried the code and checked the lines in red.

    I excitedly (stupidly I gues) just copied and pasted it in .... :-)
    Well it didn't I now only ever see a 0 in hyperterminal for any number keyed in following the #

    Time to debug :-) , if you see anything obvious just let me know and I will test.. will keep you posted

    Kind regards

    Dennis

  7. #7


    Did you find this post helpful? Yes | No

    Default bugs...

    Al..
    There is some odd behaviour now ... :-(
    Here's updated code with added display options and cosmetics for testing.
    So far # must be pressed twice and 126 is displayed for any number (1,2 or 3 digits) ??
    Check clearing of var's and counter , will continue with tests, I'm willing to bet it's something really small causing the problem
    Kind regards
    Dennis

    Code:
    'keypad capture code begins here
              
    'variables begin here
            
    Array var Byte [3] 'byte array holds keypresses
    A0 var byte 'counter/index
    B0 var Byte 'working sum of bytes
    KeyPress Var Byte ' will contain the ascii character of the key pressed passed from myvar
    myvar var byte 'holds keypress byte
    digit var byte 'check the number of bytes entered
    
    start:
    A0=0 'set index to 0
    
    Ini: 'main loop
    
    lcdout $fe,1
    lcdout "enter number"
    @ READKEYPAD _myvar  'read keypress variable and place in myvar
      
      LOOKUP myvar,[0,"123A456B789C*0#D"],myvar 'use lookup table to diplay proper keypress
      keypress = myvar 'pass the variable to solve strange character problem
     ' will contain the ascii character of the key pressed
      
      lcdout keypress
      pause 1000
      lcdout $fe,1  
    
    If KeyPress = "*" then goto retry
    
    If KeyPress = "#" then 'if # conditions begin here
    
    if A0=2 then 'if counter is 2 then sum all bytes
    B0= (Array[0]*100)+(Array[1]*10)+Array[2] 'byte sum
    lcdout "3 digits ",dec B0,$0d,$0a
    pause 1000
    lcdout $fe,1
    HSEROUT ["here is the total ",dec B0,$0d,$0a]  'send result to pc com port 
    endif
    
    if A0=1 then
    B0= (Array[0]*10)+Array[1]
    lcdout "2 digits " ,dec B0,$0d,$0a
    pause 1000
    lcdout $fe,1
    HSEROUT ["here is the total ",dec B0,$0d,$0a]
    endif
    
    if A0=0 then
    B0= Array[0]
    lcdout "1 digit " ,dec B0,$0d,$0a
    pause 1000
    lcdout $fe,1
    HSEROUT ["here is the total ",dec B0,$0d,$0a]
    endif
    
    A0=0
    Array[0]=0
    Array[1]=0
    Array[2]=0
    ENDIF
    
    If A0>2 then Ini
    
    Array[A0]=KeyPress -48
    A0=A0+1
    goto Ini
    
    retry:
    lcdout "retry"
    pause 1000
    lcdout $fe,1
    A0=0
    myvar=0
    goto ini
    goto start
    end
    Last edited by Dennis; - 16th December 2009 at 20:42.

  8. #8
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Dennis, I think the bug was a missing goto. (see code added in red)

    Al.

    Code:
    'keypad capture code begins here
              
    'variables begin here
            
    Array var Byte [3] 'byte array holds keypresses
    A0 var byte 'counter/index
    B0 var Byte 'working sum of bytes
    KeyPress Var Byte ' will contain the ascii character of the key pressed passed from myvar
    myvar var byte 'holds keypress byte
    digit var byte 'check the number of bytes entered
    
    start:
    A0=0 'set index to 0
    
    Ini: 'main loop
    
    lcdout $fe,1
    lcdout "enter number"
    @ READKEYPAD _myvar  'read keypress variable and place in myvar
      
      LOOKUP myvar,[0,"123A456B789C*0#D"],myvar 'use lookup table to diplay proper keypress
      keypress = myvar 'pass the variable to solve strange character problem
     ' will contain the ascii character of the key pressed
      
      lcdout keypress
      pause 1000
      lcdout $fe,1  
    
    If KeyPress = "*" then goto retry
    
    If KeyPress = "#" then 'if # conditions begin here
    
    if A0=2 then 'if counter is 2 then sum all bytes
    B0= (Array[0]*100)+(Array[1]*10)+Array[2] 'byte sum
    lcdout "3 digits ",dec B0,$0d,$0a
    pause 1000
    lcdout $fe,1
    HSEROUT ["here is the total ",dec B0,$0d,$0a]  'send result to pc com port 
    endif
    
    if A0=1 then
    B0= (Array[0]*10)+Array[1]
    lcdout "2 digits " ,dec B0,$0d,$0a
    pause 1000
    lcdout $fe,1
    HSEROUT ["here is the total ",dec B0,$0d,$0a]
    endif
    
    if A0=0 then
    B0= Array[0]
    lcdout "1 digit " ,dec B0,$0d,$0a
    pause 1000
    lcdout $fe,1
    HSEROUT ["here is the total ",dec B0,$0d,$0a]
    endif
    
    A0=0
    
    GOTO Ini
    
    ENDIF
    
    If A0>2 then Ini
    
    Array[A0]=KeyPress -48
    A0=A0+1
    goto Ini
    
    retry:
    lcdout "retry"
    pause 1000
    lcdout $fe,1
    A0=0
    myvar=0
    goto ini
    goto start
    end
    Al.
    All progress began with an idea

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, 20:38
  2. Keypad input test
    By Kalind in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th October 2008, 04:00
  3. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 13:16
  4. LCD display not working properly
    By dilpkan in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 2nd February 2008, 07:43
  5. Keypad entry?
    By TONIGALEA in forum General
    Replies: 3
    Last Post: - 8th August 2004, 16: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