
Originally Posted by
HenrikOlsson
Hi,
The typical way of doing this is to have your number scaled 10 or 100 or 1000 times (or whatever) so that a value in
myVAR of 12345 corresponds to 123.45 (for example). Then, to put that on the LCD, you can do something like
Code:
LCDOUT $FE, 1, "My value= ", DEC myVAR/100, ".", DEC2 myVAR//100 ' Clear screen and print result with two decimal places.
The
myVAR/100 will divide the value by 100 and print the result, which in this case will be 123.
The
myVAR//100 will again divide the value by 100 but then it'll take the remainder of that division, in this case 45, and print that.
The
DEC2 specifies that the number should always be printed with two digits.
/Henrik.
Here's my code; it works. Thanks.
ETA: I am using a 4.096V reference.
Code:
' Aliases and Modifiers:
' Program Code:
PAUSE 1000 'Pauses 1 second to allow LCD to setup.
start:
ADCIN 0, left_pot 'Reads analog voltage on AN0, converts it to 10-bit digital
'value, and stores it as left_pot.
lpot = (left_pot*4) 'Multiplies left_pot times 4 to get 1000x voltage.
ADCIN 1, right_pot 'Reads analog voltage on AN1, converts it to 10-bit digital
'value and stores it as right_pot.
rpot = (right_pot*4) 'Multiplies right_pot times 4 to get 1000x voltage.
LCDOUT $FE,1,"Left Pot = ", DEC left_pot 'Clears LCD screen, displays
'"Left Pot = " and the decimal ADC of left_pot.
LCDOUT $FE,$C0, "Voltage = ", DEC lpot/1000, ".", DEC3 lpot//1000
'Displays result to 3 decimal places.
LCDOUT $FE,$94,"Right Pot = ", DEC right_pot 'Sets LCD to beginning of
'second line and displays "Right Pot = " and the decimal ADC of
'right_pot.
LCDOUT $FE,$D4, "Voltage = ", DEC rpot/1000, ".", DEC3 rpot//1000
'Displays result to 3 decimal places.
Bookmarks