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