Hello skimask
Yes Ive been working on your suggestion this whole time, But did get side tracked with one of those replys. so here is the conclusion if I take out "IF COINOUT = 1 THEN COINOUT100" from the main loop it works fine. but I dont see what is wrong there. I dont even have any coins going out while I'm testing this to cause a problem. But ive programed the pic and tested it about 4 times now. every time I take it out of the loop it works fine
COINOUT100:
PREMIOS=PREMIOS+1
TOTAL=TOTAL-1
GOSUB WRITEIT
GOTO LOOP
that math was wrong but I figured it out. However even if I take that clear out it still wouldn't write correctly
A = TOTAL * PERCENT
A = DIV32 100
so I keeped working until I came to that conclusion
here is the code in its cut down version with the problem quoted out
Include "modedefs.bas" ' Include serial modes
DEFINE OSC 4
TRISA = %11011
TRISB = %11011011
A VAR WORD
DONE VAR BIT
X VAR BYTE
PERCENT VAR BYTE
TOTAL VAR WORD
PREMIOS VAR WORD
CAMBIO VAR WORD
MAC VAR BYTE
T0 VAR TOTAL.byte0
T1 VAR TOTAL.byte1
P0 VAR PREMIOS.BYTE0
P1 VAR PREMIOS.BYTE1
C0 VAR CAMBIO.BYTE0
C1 VAR CAMBIO.BYTE1
COINOUT VAR PORTB.0
COININ VAR PORTB.1
DONE=0
PERCENT=50
DISABLE
GOSUB READIT
loop:
IF PORTB.6 = 1 THEN LLACONECTED
IF COININ = 1 THEN COUNT1COIN
' IF COINout = 1 THEN COINOUT100 'this is the problem
GOTO LOOP
COUNT1COIN:
PAUSE 20
IF COININ=1 THEN COUNT1COIN
TOTAL=TOTAL+1
GOSUB WRITEIT
GOTO LOOP
LLACONECTED:
GOSUB READIT
PAUSE 500
FOR X=1 TO 5
GOSUB INFO
NEXT X
GOTO BORRAR
BORRAR:
SERIN2 PORTA.3,16780, 500,BORRAR,[WAIT ("CB"),DEC1 DONE]
IF DONE=1 THEN BORRAR1
IF DONE=0 THEN
gosub info
gosub info
gosub info
else
endif
GOTO BORRAR
BORRAR1:
TOTAL=0
PREMIOS=0
CAMBIO=0
GOSUB WRITEIT
FOR X=1 TO 5
GOSUB INFO
NEXT X
GOTO LOOP
WRITEIT:
WRITE 0,T0
WRITE 1,T1
WRITE 2,P0
WRITE 3,P1
WRITE 4,C0
WRITE 5,C1
RETURN
READIT:
READ 0,T0
READ 1,T1
READ 2,P0
READ 3,P1
READ 4,C0
READ 5,C1
READ 6,MAC
RETURN
INFO:
SEROUT2 PORTA.2,16780,["M",DEC3 MAC]
PAUSE 100
SEROUT2 PORTA.2,16780,["T",DEC5 TOTAL]
PAUSE 100
SEROUT2 PORTA.2,16780,["P",DEC5 PREMIOS]
PAUSE 100
SEROUT2 PORTA.2,16780,["S",DEC5 CAMBIO]
PAUSE 100
rETURN
CNT:
COUNTER=1
PAUSE 20
COUNTER=0
PAUSE 20
RETURN
'COINOUT100:
' PREMIOS=PREMIOS+1
' TOTAL=TOTAL-1
' GOSUB WRITEIT
'GOTO LOOP
Bookmarks