calculator-like code entry with matrix keypad and display


Closed Thread
Results 1 to 36 of 36

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    974


    Did you find this post helpful? Yes | No

    Default

    Just some minor modifications to your code

    Code:
      
    myvar var byte 'var output from keypress
    Array var Byte [3] 'array variable to hold 3 keypresses
    A0 var byte 'counter/index
    B0 var Byte 'sum of digits
    KeyPress Var Byte 'holds each keypress as it happens
               Pause 2000       ' Wait for LCD to startup
    
      
       A0=0   'index = 0
    
    Ini:
    
    lcdout $fe,1
    lcdout "enter number"
    B0 = 0                             ' start with 0 in the sum of digits
    @ READKEYPAD _myvar  'read keypress variable and place in myvar
      b0 = b0*10+_myvar     ' add in the new number
    
    
      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 = "a" or "b" or "c" or "d" then goto numbers
    if keypress = "*" then goto retry
    If KeyPress = "#" then    'check input keypress for a # value
    'if B0 > 255 then goto overflow 'test for overflow B0>255
    HSEROUT ["here is the total ",dec B0,$0d,$0a]  'send result to pc com port 
     
    A0=0
     
    ENDIF
    
    If A0>2 then retry 'Ini
    
    Array[A0]=KeyPress -48
    A0=A0+1
    
    goto ini
    
    numbers: 'tell person to enter only numbers
    lcdout "numbers only"
    pause 1000
    A0=0
    myvar=0
    goto ini
    
    retry: 'is the * key is pressed then prompt for a retry and clear A0 and myvar
    lcdout "retry"
    pause 1000
    lcdout $fe,1
    A0=0
    myvar=0
    goto ini
    
    overflow: 'tell person to enter 0 to 255 only
    lcdout $fe,1
    lcdout "0 to 255 ONLY!"
    pause 1000
    A0=0
    myvar=0
    
    goto ini

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Dennis,
    You might find this thread useful, check the zip files LLoyd posted.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3


    Did you find this post helpful? Yes | No

    Default Hi Joe

    Hi Joe

    Just curious as to what thread? Did you maybe forget to post the URL ?
    Will search for all posts by LLoyd

    Jerson ...Thanks a million will try iut and feedbask asap

    Kind regards

    Dennis

  4. #4


    Did you find this post helpful? Yes | No

    Default Jerson ...

    Thanks for the modification suggestion

    Have tried the code as you have it posted

    First issue was a compile error on this line
    Code:
     b0 = b0*10+_myvar     ' add in the new number
    So I changed it to read
    Code:
     b0 = b0*10+myvar     ' add in the new number
    and it compiled.

    The resultant output in MCS serial tool each time on any keypress is 15 ??

    At the moment I'm scanning through to see what else you modified and where the issue lies, will feedback if and when I find the problem :-)

    Kind regards
    Dennis

  5. #5


    Did you find this post helpful? Yes | No

    Default Joe's URL

    Joe ..

    Did you mean this URL ?
    http://www.picbasic.co.uk/forum/showthread.php?t=5695
    Yes I have been checking it out too that one out too.
    There's also this one
    http://www.picbasic.co.uk/forum/show...ight=door+lock
    and this one
    http://www.picbasic.co.uk/forum/show...ght=calculator

    Kind regards
    Dennis

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dennis View Post
    Joe ..

    Did you mean this URL ?
    http://www.picbasic.co.uk/forum/showthread.php?t=5695
    Yes I have been checking it out too that one out too.
    There's also this one
    http://www.picbasic.co.uk/forum/show...ight=door+lock
    and this one
    http://www.picbasic.co.uk/forum/show...ght=calculator

    Kind regards
    Dennis
    Hi Dennis,
    Yep, the first one, second page, where Lloyd posted the finished code he paid Mr_E to write. Since I do not know your exact plan here I thought you might discover how to handle the arrays and use the numbers. Also dunno why you use byte var hassel instead of using a word simply use something like
    Code:
    if tempx >999 then tempx = 999
    or instead of 999 you could cause the routine to jump to a subroutine that handles errors or make 999 into a zero so it works to simply overflow.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7


    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

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,183


    Did you find this post helpful? Yes | No

    Default

    I recall now once used the keyboard subroutine and I think it returns 32 when no key is pressed. Have you checked for this? Except if you have a DEFINE SCAN_ONCE 1 on top of your code.

    This way it waits in the @ READKEYPAD for as long as no key is pressed.

    Ioannis

  9. #9


    Did you find this post helpful? Yes | No

    Default Ioannis :-)

    Thanks for the reply :-)

    Except if you have a DEFINE SCAN_ONCE 1 on top of your code.
    I have that enabled :-)

    Will try the code ;-)

    Dennis

  10. #10
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    974


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dennis View Post
    Thanks for the modification suggestion

    Have tried the code as you have it posted

    First issue was a compile error on this line
    Code:
     b0 = b0*10+_myvar     ' add in the new number
    So I changed it to read
    Code:
     b0 = b0*10+myvar     ' add in the new number
    and it compiled.

    The resultant output in MCS serial tool each time on any keypress is 15 ??

    At the moment I'm scanning through to see what else you modified and where the issue lies, will feedback if and when I find the problem :-)

    Kind regards
    Dennis
    You may also need to check for the * and # conditions before you modify the B0 variable like this
    Code:
    @ READKEYPAD _myvar  'read keypress variable and place in myvar
    
        if myvar < 10 then
             b0 = b0*10+myvar     ' add in the new number
        else
             if myvar = 12 then  retry    ' check for * condition
             if myvar =13 then       ' check for # condition
                 HSEROUT ["here is the total ",dec B0,$0d,$0a]  'send result to pc com port 
                 A0=0
             endif
        endif
    As you can see, I have used the raw values from readkeypad and you may need to change the 12 and 13 to whatever it is you get for * and #

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