calculator-like code entry with matrix keypad and display


Results 1 to 36 of 36

Threaded View

  1. #5


    Did you find this post helpful? Yes | No

    Default doing the math !

    Hi all

    I am working on the digits now, and I think I have almost got it sorted (or not!)
    I just can't see where I am going wrong and I'm sure it's the way I'm working with the array.

    To somplify things I have given the variable a set number, the number 123 as in my examples above.
    here's the code so far
    Code:
    Start:
    Codex	VAR BYTE
    Temp	VAR BYTE [3]
    TempTot var byte 
    Codex = 123
    Tempx var byte
    'Find character for decimal 100 column
    Tempx = Codex/100 'divide Codex by 100 'cos its the digit in 100's column
    Temp(0) = Tempx + 48 'add 48 to get ascii value
    lcdout "first " ,temp(0)
    HSEROUT ["1st digit ", Temp(0),$0d,$0a]
    pause 1000
    
    'Find character for decimal 10 column
    Tempx = Codex/10 'since Codex = 123 after dividing Temp = 12
    Temp(1) = Tempx//10 'Remainder is required so with Codex = 123 the number in Temp = 2
    Temp(1) = Tempx + 48 'add 48 to get ascii value
     lcdout "second ",temp(1) 
    HSEROUT ["2nd digit ", Temp(1),$0d,$0a]
                      pause 1000
    'Find character for decimal 1 column
    Tempx = Codex//10 'Get Remainder so…with Codex = 123 then Temp = 3
    Temp(2) = Tempx + 48 'add 48 to get ascii value
     lcdout "third ",temp(2)
    HSEROUT ["3rd digit ", Temp(2),$0d,$0a]
     pause 1000
     TempTot = Temp(0)+temp(1)+Temp(2)
      hserout ["here's the binary total ",dec temptot,$0d,$0a]
     hserout ["here's the binary total ",bin temp,$0d,$0a]
     goto start
    Observations:
    The first and third digits are correct , the second is a problem (and I think it's the wrong number since it shows up as a ">" character ) so this obviously messes up the total after addition which ends up as 160 as opposed to 123 :-(
    Here is what I see in the MCS serial tool window
    Code:
    1st digit 1
    2nd digit <
    3rd digit 3
    here's the binary total 160
    here's the binary total 110001
    Any help would be appreciated

    Dennis
    Last edited by Dennis; - 15th December 2009 at 05:50. Reason: Now I'm wondering if I should be multiplying and not dividing :-(

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