Hi, Jason
Did you had a look to THAT Thread ???
http://www.picbasic.co.uk/forum/showthread.php?t=1078
Alain
Hi, Jason
Did you had a look to THAT Thread ???
http://www.picbasic.co.uk/forum/showthread.php?t=1078
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 " !!!
*****************************************
WOW
I think that is my problem here. However I only understood a little bit of it.
Why is this so complicated just to store a word ?
OK, so I thought storing total.byte0 in location 0 and then storing total.byte1 in location 1 would handle the whole word right ?
'----------------------------------------------------------------------
total=33024 or total.byte0=10000000 and total.byte1=11111111
write 0,total.byte0
write 1,total.byte1
If so then in location 0 would be 10000000 and in location 1 would be 11111111
or is this wrong ?
if it is right then I can't get that data back the same way ?
read 0,total.byte0
read 1,total.byte1
total=33024
if not then what ???? I'm more confused then before, but I think your on the right track
total=33024
Binary(33024) = %1000000100000000
total.BYTE1 = %10000001
total.BYTE0 = %00000000
Originally Posted by PBP Manual
Last edited by rhino; - 8th June 2007 at 20:38.
Wisdom is knowing what path to take next... Integrity is taking it.
Ryan Miller
And there be the logic error I thought I saw earlier...
Now build you program up and see what happens...then we can work on optimizing that program a bit. I looks a bit of a mess...not too bad, but could be better...
thank you for setting me straight, however that didnt answer my question. am i reading the data back to "total" correctly ?
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
Last edited by jason; - 8th June 2007 at 21:55. Reason: UPDATE
Try this out:
Include "modedefs.bas" ' Include serial modes
DEFINE OSC 4
TRISA=$1b : trisb=$db : 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
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:if total > 0 then TOTAL=TOTAL-1
GOSUB WRITEIT:GOTO LOOP
END
Last edited by skimask; - 9th June 2007 at 04:06. Reason: Fixed the colons and smiley faces :)
Bookmarks