help with calculator


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Posts
    3

    Default help with calculator

    I'm building a 4-digit calculator but when you put 9999 * 9999 I get an error in the outcome variable 37601 where I keep the result for display of word type, help please

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,613


    Did you find this post helpful? Yes | No

    Talking

    Hi,

    Without further detail given ...

    Your calculator is limited to a RESULT of 65535 ...after that there's some truncature.

    You know what ???

    37601 = ( 9999*9999 ) //65536

    incredible !!! ... PBP always shows something " intelligent "

    Try using PBPL anc a 18Fxxxx Pic .... or another calculating method ! ....

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default

    Hi,

    There is not much to add after Acetronics excellent explanation. However, if you post your code, we might be able to help you more.

    Robert

  4. #4
    Join Date
    Nov 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    am beginner sorry... can save the result in the memory??? help please or with arrays...

    Code:
    DEFINE OSC 20
    DEFINE LCD_DREG PORTB 'LCD data port 
    DEFINE LCD_DBIT 4 'LCD data starting bit 0 or 4 
    DEFINE LCD_RSREG PORTB 'LCD register select port 
    DEFINE LCD_RSBIT 0 'LCD register select bit 
    DEFINE LCD_EREG PORTB 'LCD enable port 
    DEFINE LCD_EBIT 2 'LCD enable bit 
    DEFINE LCD_BITS 4 'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2 'Number lines on LCD 
    DEFINE LCD_COMMANDUS 2000 'Command delay time in us 
    DEFINE LCD_DATAUS 50 'Data delay time in us
    
    alldigital 
    TRISC=%11110000
    TRISB=0
    
    INICIO2:
    X VAR BYTE
    X=0
    Y VAR BYTE
    Y=0
    
    SUM VAR WORD
    SUM=0
    RES VAR WORD
    RES=0
    MUL VAR word
    MUL=0
    DIVIN VAR WORD
    DIVIN=0
    DIVDEC VAR WORD
    DIVDEC=0
    DECI VAR WORD
    DECI=0
    G VAR byte
    G=0
    H VAR byte
    H=0
    I VAR byte
    I=0
    P VAR byte
    P=0
    J VAR BYTE
    J=0
    K VAR word
    K=0
    L VAR WORD
    L=0
    FLAG VAR BYTE
    FLAG=0
    CLC VAR BYTE
    CLC=0
    
    A VAR PORTC.0
    B VAR PORTC.1
    C VAR PORTC.2
    D VAR PORTC.3
    UNO VAR PORTC.4
    DOS VAR PORTC.5
    TRES VAR PORTC.6
    CUATRO VAR PORTC.7
    
    LCDOUT $FE, 1
    
    INICIO:
    
    'TECLADO
    HIGH A
    IF UNO=1 THEN X=1
    IF DOS=1 THEN X=2
    IF TRES=1 THEN X=3
    IF CUATRO=1 THEN X=10
    IF UNO=1 || DOS=1 || TRES=1 || CUATRO=1 THEN GOSUB ANTIREBOTE:Y=Y+1
    PAUSE 10
    LOW A
    
    HIGH B
    IF UNO=1 THEN X=4
    IF DOS=1 THEN X=5
    IF TRES=1 THEN X=6
    IF CUATRO=1 THEN X=11
    IF UNO=1 || DOS=1 || TRES=1 || CUATRO=1 THEN GOSUB ANTIREBOTE:Y=Y+1
    PAUSE 10
    LOW B
    
    HIGH C
    IF UNO=1 THEN X=7
    IF DOS=1 THEN X=8
    IF TRES=1 THEN X=9
    IF CUATRO=1 THEN X=12
    IF UNO=1 || DOS=1 || TRES=1 || CUATRO=1 THEN GOSUB ANTIREBOTE:Y=Y+1
    PAUSE 10
    LOW C
    
    HIGH D
    IF UNO=1 THEN X=20 'ON
    IF DOS=1 THEN X=0
    IF TRES=1 THEN X=14 'ENTER
    IF CUATRO=1 THEN X=13
    IF UNO=1 || DOS=1 || TRES=1 || CUATRO=1 THEN GOSUB ANTIREBOTE:Y=Y+1
    PAUSE 10
    LOW D
    
    IF Y=1 && X<10 THEN G=X:LCDOUT $FE, 2, #X
    IF Y=2 && X<10 THEN H=X:LCDOUT $FE, 2, #G, #X
    IF Y=3 && X<10 THEN I=X:LCDOUT $FE, 2, #G, #H, #X
    IF Y=4 && X<10 THEN P=X:LCDOUT $FE, 2, #G, #H, #I, #X
    IF FLAG=0 && Y=0 THEN LCDOUT $FE, 2, "0  "
    IF X=10 THEN LCDOUT $FE, 2, "+   "
    IF X=11 THEN LCDOUT $FE, 2, "-   "
    IF X=12 THEN LCDOUT $FE, 2, "*   "
    IF X=13 THEN LCDOUT $FE, 2, "/   "
    IF X=20 THEN GOTO INICIO2
    
    'PRIMER NUMERO
    IF FLAG=0 THEN
        IF Y=2 && X>=10 THEN
        J=X
        K=G
        LCDOUT $FE, 2, #K
        PAUSE 100
        FLAG=1
        Y=0
        G=0:H=0:I=0:P=0
        ENDIF
        
        if y=3 && x>=10 THEN 
        J=X
        K=(G*10)+H
        LCDOUT $FE, 2, #K
        PAUSE 100
        FLAG=1
        Y=0
        G=0:H=0:I=0:P=0
        ENDIF
        
        IF Y=4 && X>=10 THEN
        J=X
        K=(g*100)+(H*10)+(i)
        LCDOUT $FE, 2, #K
        PAUSE 100
        FLAG=1
        Y=0
        G=0:H=0:I=0:P=0
        ENDIF
        
        IF Y=5 && X>=10 THEN
        J=X
        K=(g*1000)+(H*100)+(i*10)+P
        LCDOUT $FE, 2, #K
        PAUSE 100
        FLAG=1
        Y=0
        G=0:H=0:I=0:P=0
        ENDIF
    ENDIF
    
    'SEGUNDO NUMERO
    iF FLAG=1 THEN
        IF Y=2 && X=14 THEN 
        L=G
        LCDOUT $FE, 2, #L
        PAUSE 100
        CLC=1
        GOSUB OPERACIONES
        ENDIF
        
        IF Y=3 && X=14 THEN
        L=(G*10)+H
        LCDOUT $FE, 2, #L
        PAUSE 100
        CLC=1
        GOSUB OPERACIONES
        ENDIF
        
        IF Y=4 && X=14 THEN
        L=(g*100)+(H*10)+i
        LCDOUT $FE, 2, #L
        PAUSE 100
        CLC=1
        GOSUB OPERACIONES
        ENDIF
        
        IF Y=5 && X=14 THEN
        L=(g*1000)+(H*100)+(i*10)+P
        PAUSE 10
        LCDOUT $FE, 2, #L
        PAUSE 100
        CLC=1
        GOSUB OPERACIONES
        ENDIF
    ENDIF
    
    GOTO INICIO
    
    ANTIREBOTE:
    IF UNO=1 || DOS=1 || TRES=1 || CUATRO=1 THEN
    GOTO ANTIREBOTE
    ELSE
    RETURN
    ENDIF
    
    OPERACIONES:
    
    IF CLC=1 THEN
        IF J=10 THEN
        SUM=K+L
        LCDOUT $FE, 2, #k, "+", #l,"="
        LCDOUT $FE, $C0, #SUM
        PAUSE 100
        X=0
        ENDIF
        
        IF J=11 THEN
            IF L>K THEN
            RES=L-K
            LCDOUT $FE, $C0,"-", #RES        
            ELSE
            RES=K-L
            LCDOUT $FE, $C0, #RES
            ENDIF
        LCDOUT $FE, 2, #K, "-",#L,"="
        PAUSE 100
        X=0
        ENDIF
        
        IF J=12 THEN
        MUL=(K*L)
        LCDOUT $FE, 2, #k, "*",#L,"="
        LCDOUT $FE, $C0, #MUL
        PAUSE 100
        X=0
        ENDIF
        
        IF J=13 THEN
        DIVIN=K/L
        DIVDEC=K//L
        DECI=(DIVDEC*100)/L
        LCDOUT $FE, 2, #k, "/",#L,"="
        LCDOUT $FE, $C0, #DIVIN,".",#DECI
        PAUSE 100
        X=0
        ENDIF
    
    HIGH D
    IF UNO=1 THEN X=20 'ON
    IF DOS=1 THEN X=0
    IF TRES=1 THEN X=14 'ENTER
    IF CUATRO=1 THEN X=13
    IF UNO=1 || DOS=1 || TRES=1 || CUATRO=1 THEN GOSUB ANTIREBOTE:Y=Y+1
    PAUSE 10
    LOW D
    
    IF X=20 THEN LCDOUT $FE,1,"0":GOTO INICIO2
    GOTO OPERACIONES
    
    ELSE
    GOTO INICIO
    ENDIF

Similar Threads

  1. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 16:45
  2. Tmro Tmr1 Calculator
    By kevin in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th April 2006, 17:39
  3. help with my calculator project
    By loayaouad in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th May 2005, 07:42
  4. Calculator
    By neiron21 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st February 2005, 00:53
  5. Baud Rate and Timing Calculator
    By picnaut in forum General
    Replies: 3
    Last Post: - 23rd January 2004, 16:48

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