A possible way to shorten this? Using Loop?

sodeaf

Senior Member
Hey guys, I have this code working great, and after testing all functions I am now going threw my code to make sure its all clean and organized. Something tells me there is a better way to do this? I have tried a couple things without success.

Thanks in advance.


Datain:
high pulseout
serin C.5,N2400_16,B1,B2,B3,B4,B5,B6
low pulseout


bcdtoascii B1,w20,w21
w20 = w20-$30
w20 = w20 *10
w21 = w21 -$30
b1 = w20+w21

bcdtoascii B2,w20,w21
w20 = w20-$30
w20 = w20 *10
w21 = w21 -$30
b2 = w20+w21


bcdtoascii B3,w20,w21
w20 = w20-48
w20 = w20 *10
w21 = w21 -48
b3 = w20+w21


bcdtoascii B4,w20,w21
w20 = w20-48
w20 = w20 *10
w21 = w21 -48
b4 = w20+w21

bcdtoascii B5,w20,w21
w20 = w20-48
w20 = w20 *10
w21 = w21 -48
b5 = w20+w21

bcdtoascii B6,w20,w21
w20 = w20-48
w20 = w20 *10
w21 = w21 -48
b6 = w20+w21
 

srnet

Senior Member
Something tells me there is a better way to do this? I have tried a couple things without success.

Thanks in advance.
Can you give us a clue as to what the code is supposed to do ?

There are no comments in the code or a description, it just appears to be a jumble of code with no obvious purpose.
 

eggdweather

Senior Member
The programme is converting BCD values (b1, b2, b3, etc) into ASCII in w20 and w21, then back to a binary, so b1= b1 after the conversion! I'm not sure why you would want to do this, other than create a delay.
e.g.
b1 = 20
bcdtoascii b1,w20,w21
then w20 = ASCII "2" or decimal 50 then subtract 48 = 2 then multiply by 10 and put the result (20) in w20
then w21 = ASCII "0" or decimal 48 then subtract 48 = 0 then add to b1 and put the result (0) in w21
then add w20+w21
afterwards b1 = 20
 
Last edited:

sodeaf

Senior Member
Ah yes sorry..

I am actually receiving the date from a machine via Hserin into my 28x2

28x2 hserin [200,print],0,11
get 2,B1,B2,B3,B4,B5,B6 'This is the date, in BCD MM/DD/YYYY/HH/MM

waitprint:
if printpulse = 0 then
goto waitprint
else
low printout
serout PrintTX,N2400_16, (B1,B2,B3,B4,B5,B6)
endif

Now I am receiving those values into a 20x2 which I want to display on an LCD screen and send to a thermal printer.

Datain:
high pulseout
serin C.5,N2400_16,B1,B2,B3,B4,B5,B6
low pulseout


bcdtoascii B1,w20,w21
w20 = w20-$30
w20 = w20 *10
w21 = w21 -$30
b1 = w20+w21

bcdtoascii B2,w20,w21
w20 = w20-$30
w20 = w20 *10
w21 = w21 -$30
b2 = w20+w21


bcdtoascii B3,w20,w21
w20 = w20-48
w20 = w20 *10
w21 = w21 -48
b3 = w20+w21


bcdtoascii B4,w20,w21
w20 = w20-48
w20 = w20 *10
w21 = w21 -48
b4 = w20+w21

bcdtoascii B5,w20,w21
w20 = w20-48
w20 = w20 *10
w21 = w21 -48
b5 = w20+w21

bcdtoascii B6,w20,w21
w20 = w20-48
w20 = w20 *10
w21 = w21 -48
b6 = w20+w21

I have it working great, if I don't do the above to convert the BCD, i get really funky digits on the LCD screen.
just thought there is a better way to do this.

Hope this makes sense
 
Top