SERIN causing problems with Word variable

josefvs

New Member
Hi all,

I wrote a little program to read NMEA HDG sentence and display the heading using SERTXD, this is the fo=irt step to create an autohelm for a boat.

It seems to read the NMEA value fine until I try to add the numbers and display the result as a word variable, using the DEBUG b0, b1, b2 are fine. the result from SERTXD is displayed as: 314 - 5642 (the compass course is 314)

Main:
serin c.0,n4800,("$HCHDG,"),b0,b1,b2,b3
pause 100
if b1="." then gosub one
if b2="." then gosub two
if b3="." then gosub three
goto main

one:
let w3=b0
sertxd (b0," - ",#w3,13,10)
return

two:
let w3=b0*10+b1
sertxd (b0,b1," - ",#w3,13,10)
return

three:
let w3=b0*100
let w3=b1*10+w3+b2
sertxd (b0,b1,b2," - ",#w3,13,10)
return

Initially I suspected the SERTXD, but the following code provides the correct 314 as an output:

main:
b0=3
b1=1
b2=4
let w3=b0*100
let w3=b1*10+w3+b2
sertxd (#w3,13,10)
goto main

Can someone help me understand what an I doing wrong with the w3 value in the first program?

Thanks
 

hippy

Ex-Staff (retired)
The data from the GPS will be ASCII characters, not raw number values. so ...

$HCHDG,314.0

Will have put "3" into b0, "1" into b1 and "4" into b2. This is not the same as 3, 1 and 4. You need to convert the ASCII to the corresponding number values. The easiest way is to subtract "0" ...

one:
let w3 = b0-"0"

two:
let w3 = b0-"0" * 10 + b1-"0"

three:
let w3 = b0-"0" * 10 + b1-"0" * 10 + b2-"0"

Remember PICAXE maths is strictly left to right so the 'three' version is correct with two sets of 'times 10'.
 
Top