My first attempt at a distance calculation (using a floating point

implementation of the haversine formula) required 5 trigonometric function

calls, two square roots, and several floating point divisions. It also

needed 3 watchdog resets to keep the CPU from timing out during the

calculation! Floating point math is NOT the HC08's strong suit.

I rewrote it using mostly integer math, applying the pythagorean theorem and

dividing each hemisphere into 8 latitude bands to compensate for the

convergence of the meridians. I think it's accurate enough for this

application, and it's pretty fast. It's got one square root call and no

division.

I also added the ability to use compressed mode with a fixed position. This

was important because the distance calculation works from the compressed

integer representation of the coordinates, so the conversion had to be done

anyway.

Something's still not quite right - two points with the same coordinates

show a distance of 323 feet. Gotta track that one down. But it seems to be

good enough for distances in miles - everything seems to be within about 10%

of what it should be.

I was thinking that a cool use for this would be to add a scripting option

to trigger an action based on distance to a station. A T2 at your house

could see your car coming and turn the driveway light on when it's within a

mile, or your mobile station could turn on a proximity alarm light when you

come within a certain distance of another station on the road.

Now for bearing calculation. Anyone know how to fake an arctangent

calculation?

Scott