Mr RB
Well-Known Member
The calc_distance() routine you are using already decodes the measurement 00-99 into 2 values;
cm10 (this is the TENS digit)
cm (this is the UNITS digit)
Then later on in oyur code in the main loop you are doign this;
which is bad because it has already been done in the calc_distance() function.
All you need to do to display the distance in cm is this;
Which will display the 2 decimal digits (0-9) as 2 ascii digits ('0'-'9')
cm10 (this is the TENS digit)
cm (this is the UNITS digit)
Then later on in oyur code in the main loop you are doign this;
Code:
//CM is higher than 09 so spilt the variable CM into 2
cmHigh = ( ( cm >> 4 ) & 0x0F ) + 0x30;
cmLow = ( cm & 0x0F ) + 0x30;
All you need to do to display the distance in cm is this;
Code:
lcd_data(cm10 + '0');
lcd_data(cm + '0');
Which will display the 2 decimal digits (0-9) as 2 ascii digits ('0'-'9')