"shrink" thse lines
Robban
Posts: 124
Hi
i have a program that are very large and almost doesn´t fit in a bank on my bsp2p.
I wonder if it is possible with other commands to compress these lines but still have the same funktion.
· valuechars:
IF CHAR=0 AND addr=220 THEN bigzero
IF char=0 AND addr<>220 THEN zero
IF char=1 AND addr=220 THEN bigone
IF char=1 AND addr<>220 THEN one
IF char=2 AND addr=220 THEN bigtwo
IF char=2 AND addr<>220 THEN two
IF CHAR=3 AND addr=220 THEN bigthree
IF char=3 AND addr<>220 THEN three
IF CHAR=4 AND addr=220 THEN bigfour
IF char=4 AND addr<>220 THEN four
iF CHAR=5 AND addr=220 THEN bigfive
IF char=5 AND addr<>220 THEN five
IF CHAR=6 AND addr=220 THEN bigsix
IF char=6 AND addr<>220 THEN six
IF CHAR=7 AND addr=220 THEN bigseven
IF char=7 AND addr<>220 THEN seven
iF char=8 AND addr=220 THEN bigeight
IF char=8 AND addr<>220 THEN eight
IF CHAR=9 AND addr=220 THEN bignine
IF char=9 AND addr<>220 THEN nine
IF CHAR=" " THEN _
RETURN
Robban
i have a program that are very large and almost doesn´t fit in a bank on my bsp2p.
I wonder if it is possible with other commands to compress these lines but still have the same funktion.
· valuechars:
IF CHAR=0 AND addr=220 THEN bigzero
IF char=0 AND addr<>220 THEN zero
IF char=1 AND addr=220 THEN bigone
IF char=1 AND addr<>220 THEN one
IF char=2 AND addr=220 THEN bigtwo
IF char=2 AND addr<>220 THEN two
IF CHAR=3 AND addr=220 THEN bigthree
IF char=3 AND addr<>220 THEN three
IF CHAR=4 AND addr=220 THEN bigfour
IF char=4 AND addr<>220 THEN four
iF CHAR=5 AND addr=220 THEN bigfive
IF char=5 AND addr<>220 THEN five
IF CHAR=6 AND addr=220 THEN bigsix
IF char=6 AND addr<>220 THEN six
IF CHAR=7 AND addr=220 THEN bigseven
IF char=7 AND addr<>220 THEN seven
iF char=8 AND addr=220 THEN bigeight
IF char=8 AND addr<>220 THEN eight
IF CHAR=9 AND addr=220 THEN bignine
IF char=9 AND addr<>220 THEN nine
IF CHAR=" " THEN _
RETURN
Robban
Comments
This is equivalent to your program fragment and will take less room. Without some description of what the rest of your program is trying to do, it's impossible to tell what other space might be saved in the routines at the various labels (like bigone / one / etc.).
if addr = 220 THEN temp = 0
else temp = 1
Lookup (char*2) + temp, [noparse][[/noparse]bigzero, zero, bigone, one, ...]
note the psuedo code...
but if the adress is lower or higher then 220 then the display the numbers should be in normal size but mirrored.
i tried to copy your program but i get <> marked and a message "binary operator expected or )"
why?
Post Edited (Robban) : 12/11/2008 7:34:03 PM GMT
why do i get the "Binary operator expected or ")" with Mike:s rows?
Do you have the following lines at the top of your code?
If not, that may be the source of your trouble with the suggestions you've received.
-Phil
here´s the whole program of that bank
look at the section "valuechars:"
' {$STAMP BS2p}
' {$PBASIC 2.5}
HEXSTR VAR Byte(15)
I VAR Byte
value VAR Word
Valjare VAR Nib
' range VAR Word
LJUS VAR Byte
Z VAR Byte
Q VAR Byte
addr VAR Word
sp VAR Nib
char VAR Nib
a VAR Nib
GET 25,valjare
IF valjare=1 THEN hast
IF valjare=2 THEN temp
IF valjare=3 THEN motor
IF valjare=4 THEN volt
IF valjare=5 THEN fueltrim
IF valjare=6 THEN felkoder
IF valjare=7 THEN back
IF valjare=8 THEN dispoff
IF valjare=9 THEN reserv
IF valjare=10 THEN limit
IF valjare=11 THEN setup
RUN 1
' Turn off H.U.D
dispoff:
SEROUT 2,240,[noparse][[/noparse]$20,$19]
PAUSE 50
valjare =0
PUT 26,8
RUN 1
' Display rpm
hast:
SEROUT 3,16624,[noparse][[/noparse]"010c",13]
GOSUB HExkonv2
WRITE 200, value/4/10
q=22
z=1
addr=200
GOSUB getvalue
'SERIN 4,16624,[noparse][[/noparse]WAIT(">")]
' Display Throttle position
SEROUT 3,16624,[noparse][[/noparse]"0111",13]
GOSUB HExkonv
WRITE 210,value*100/255
q=93
z=1
addr=210
GOSUB getvalue
'SERIN 4,16624,[noparse][[/noparse]WAIT(">")]
' Display speed
SEROUT 3,16624,[noparse][[/noparse]"010d",13]
GOSUB hexkonv
value=56
WRITE 220,value
q=42
z=39
addr=220
GOSUB getvalue
'SERIN 4,16624,[noparse][[/noparse]WAIT(">")]
RUN 1
' Display temp
TEMP:
'Display Cooltemp
SEROUT 3,16624,[noparse][[/noparse]"0105",13]
GOSUB hexkonv
WRITE 230,value-40
q=74
z=40
addr=230
GOSUB getvalue
'SERIN 4,16624,[noparse][[/noparse]WAIT(">")]
' DIsplay Airtemp
SEROUT 3,16624,[noparse][[/noparse]"010f",13]
GOSUB hexkonv
WRITE 240,value-40
q=74
z=30
addr=240
GOSUB getvalue
SERIN 4,16624,[noparse][[/noparse]WAIT(">")]
RUN 1
'Display engine
motor:
SEROUT 3,16624,[noparse][[/noparse]"0110",13]
GOSUB hexkonv2
WRITE 250,value/100
q=74
z=15
addr=250
GOSUB getvalue
'SERIN 4,16624,[noparse][[/noparse]WAIT(">")]
SEROUT 3,16624,[noparse][[/noparse]"010B",13]
GOSUB hexkonv
WRITE 260,value
q=74
z=30
addr=260
GOSUB getvalue
PAUSE 1000
SEROUT 3,16624,[noparse][[/noparse]"0104",13]
GOSUB hexkonv
WRITE 270,value*100/255
q=74
z=45
addr=270
GOSUB getvalue
'SERIN 4,16624,[noparse][[/noparse]WAIT(">")]
PUT 26,3
RUN 1
'Display ECU voltage
volt:
SEROUT 3,16624,[noparse][[/noparse]"ate1",13]
PAUSE 1000
SEROUT 3,16624,[noparse][[/noparse]"atrv",13]
SERIN 4,16624,[noparse][[/noparse]STR hexstr\9]
FOR i=1 TO 4
WRITE 290, hexstr(i)
q=90
z=40
addr=290
GOSUB getvalue
GET 20,ljus
WRITE 300,ljus,$0e
q=90
z=20
addr=300
GOSUB getvalue
NEXT
SEROUT 3,16624,[noparse][[/noparse]"ate0",13]
SERIN 4,16624,[noparse][[/noparse]WAIT(">")]
PUT 26,4
RUN 1
'Display fuel trim
FUELTRIM:
trim:
SEROUT 3,16624,[noparse][[/noparse]"0106",13]
GOSUB HEXKONV
WRITE 310,value/128*100-100
q=74
z=40
addr=310
GOSUB getvalue
SERIN 4,16624,[noparse][[/noparse]WAIT(">")]
SEROUT 3,16624,[noparse][[/noparse]"0107",13]
GOSUB HEXKONV
WRITE 320, VALUE/128*100-100
q=74
z=20
addr=320
GOSUB getvalue
SERIN 4,16624,[noparse][[/noparse]WAIT(">")]
RUN 1
' READ TROUBLE CODES
Felkoder:
SEROUT 3,16624,[noparse][[/noparse]"0101",13]
GOSUB HEXKONV
WRITE 330, VALUE-128
q=30
z=37
addr=330
GOSUB getvalue
SERIN 4,16624,[noparse][[/noparse]WAIT(">")]
PUT 26,6
RUN 1
'BACKING
back:
'DEC RANGE,$0e]
'WRITE 38,range
'q=30
'z=22
'addr=340
'GOSUB getvalue
'PAUSE 200
'RUN 1
limit:
'RUN 4
setup:
'RUN 6
'Reserv
reserv:
'SEROUT 2,240,[noparse][[/noparse]$12, 00, 00, 125, 70]
'PUT 26,9
'RUN 3
' Convert 1 byte Hex
hexkonv:
'SERIN 4,16624,[noparse][[/noparse]STR hexstr\10]
FOR i= 6 TO 7
IF hexstr(i) < "0" OR hexstr(i) > "9" THEN skip1x
hexstr(i) = hexstr(i) - "0"
skip1x:
IF hexstr(i) < "a" OR hexstr(i) > "f" THEN skip2x
hexstr(i) = hexstr(i) - "a" + 10
skip2x:
IF hexstr(i)<"A" OR hexstr(i)>"F" THEN skip3x
hexstr(i)=hexstr(i)-"A" +10
SKIP3x:
NEXT
' calculate value
value =(hexstr(6) << 4) + hexstr(7)
RETURN
' Convert 2 byte hex
hexkonv2:
'SERIN 4,16624,[noparse][[/noparse]STR hexstr\13]
FOR i= 6 TO 7
IF hexstr(i) < "0" OR hexstr(i) > "9" THEN skip4x
hexstr(i) = hexstr(i) - "0"
skip4x:
IF hexstr(i) < "a" OR hexstr(i) > "f" THEN skip5x
hexstr(i) = hexstr(i) - "a" + 10
skip5x:
IF hexstr(i)<"A" OR hexstr(i)>"F" THEN skip6x
hexstr(i)=hexstr(i)-"A" +10
SKIP6x:
NEXT
FOR i = 9 TO 10
IF hexstr(i) < "0" OR hexstr(i) > "9" THEN skip7x
hexstr(i) = hexstr(i) - "0"
skip7x:
IF hexstr(i) < "a" OR hexstr(i) > "f" THEN skip8x
hexstr(i) = hexstr(i) - "a" + 10
skip8x:
IF hexstr(i)<"A" OR hexstr(i)>"F" THEN skip9x
hexstr(i)=hexstr(i)-"A" +10
SKIP9x:
NEXT
' calculate value
value =(hexstr(6) << 12) + (hexstr(7) << 8) + (hexstr(9) << 4) + hexstr(10)
RETURN
getvalue:
STORE 2
READ addr,value
IF addr=200 THEN value=value*10
IF addr=220 AND value<100 THEN a=1
IF value>100 AND value<1000 THEN a=2
IF value>1000 THEN a=3
FOR sp=A TO 0
WRITE addr+1,value DIG sp
GOSUB maskit
NEXT
RETURN
maskit:
READ addr+1,char
q=q+8
GOSUB valuechars
RETURN
valuechars:
tempa VAR Nib
IF addr = 220 THEN temp = 0
ELSE temp = 1
LOOKUP (char*2) + temp, [noparse][[/noparse]bigzero, zero, bigone, one]
RETURN
_:
SEROUT 2,240,[noparse][[/noparse]$1A, $40, $10, Q, Z, $18,$08,$00,$00,$00,$00,$00,$00,$00,$00]
ZERO:
SEROUT 2,240,[noparse][[/noparse] $1A, $40, $10, Q, Z, $18,$08,$0E,$11,$19,$15,$13,$11,$0E,$00]
RETURN
ONE:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$08, $0E,$04,$04,$04,$04,$0C,$04,$00]
RETURN
TWO:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$08,$1F,$08,$04,$02,$01,$11,$0E,$00]
RETURN
THREE:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$08,$0E,$11,$01,$06,$01,$11,$0E,$00]
RETURN
FOuR:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$08,$02,$02,$1F,$12,$0A,$06,$02,$00]
RETURN
FIVE:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$08, $0E,$11,$01,$0E,$10,$10,$1F,$00]
RETURN
SIX:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$08,$0E,$11,$11,$1E,$10,$08,$06,$00]
RETURN
SEVEN:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$08, $08,$08,$08,$04,$02,$01,$1F,$00]
RETURN
EIGHT:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$08,$0E,$11,$11,$0E,$11,$11,$0E,$00]
RETURN
NINE:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$08,$0E,$11,$01,$0F,$11,$11,$0E,$00]
RETURN
CH:
SEROUT 2,240,[noparse][[/noparse] $10,Q+3,Z+7,CHAR]
RETURN
decimalII:
a=1
SEROUT 2,240,[noparse][[/noparse]$0e]
RETURN
bigone:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$a,$1F,$04,$04,$04,$04,$04,$04,$04,$0C,$04,$00]
RETURN
bigtwo:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$a,$1F,$10,$10,$10,$10,$1F,$01,$01,$01,$1F,$00]
RETURN
bigthree:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$a,$1E,$01,$01,$01,$01,$0E,$01,$01,$01,$1E,$00]
RETURN
bigfour:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$a,$01,$01,$01,$01,$01,$1F,$11,$11,$11,$11,$00]
RETURN
bigfive:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$a,$1E,$01,$01,$01,$01,$1E,$10,$10,$10,$1F,$00]
RETURN
bigsix:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$a,$0E,$11,$11,$11,$1E,$10,$10,$10,$10,$0E,$00]
RETURN
bigseven:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$a,$04,$04,$04,$04,$04,$02,$02,$01,$01,$1F,$00]
RETURN
bigeight:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$a,$0E,$11,$11,$11,$11,$0E,$11,$11,$11,$0E,$00]
RETURN
bignine:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$a,$0E,$01,$01,$01,$0F,$11,$11,$11,$11,$0E,$00]
RETURN
bigzero:
SEROUT 2,240,[noparse][[/noparse] $1A ,$40, $10, Q,Z, $18,$a,$0E,$11,$11,$11,$11,$11,$11,$11,$11,$0E,$00]
RETURN
Back to the "<>" (expecting a binary operator) error, it looks like we all got fooled on that one. You cannot, in fact,
use relational operators in general expressions. It makes zero sense, but that's just the way it is. So revamping
Mike's suggestion a little, we get:
BTW, when you wrote your program, did you write it all at once before you began testing it? With large programs
like yours, it's better to write and test little pieces at a time, before putting it all together. You'll finish sooner
and have a lot more fun in the process.
-Phil
i wrote a little and then test it in the car....the project is a "heads up display for the car " using a OBD2> Elm converter>seriell and a VFD display.
is there anyway that i could comress the whole program?
the strings they're sending into DATA statements. Then write a subroutine that's passed the address of the string to send.
Use READ to get the bytes and send them via a SEROUT. I'm not going to write your code for you. You'll have to do a little
research in the PBASIC manual. Good luck!
-Phil