Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 4
Define LCD_EREG = PORTA
Define LCD_EBIT = 5
Define SIMULATION_WAITMS_VALUE = 1
'------------------------------------
'setup temp variables
Dim ascbfr4 As Byte
Dim ascbfr3 As Byte
Dim ascbfr2 As Byte
Dim ascbfr1 As Byte
Dim ascbfr0 As Byte
Dim temp3 As Word
Dim binval As Word
Dim val0 As Word
'Define ADC_CLOCK = 3
'Define ADC_SAMPLEUS = 50
ADCON0 = %01000001 'adcchan0
ADCON1 = %10001011 'Dis clk div,,,an0 > an3 analaog rest dig
TRISA = %00000001
TRISB = %11111111 'all inputs on portb
TRISC = %11111111
'-----------------------------------------------------
Lcdinit
main0:
Lcdcmdout LcdClear
main:
Gosub readadc
Goto main
End
readadc:
'read adc word
Adcin 0, val0
binval = 199 'val0 'rename for the bin2asc subr
Gosub bin2asc
Lcdcmdout LcdLine1Home
Lcdout "val0: ", ascbfr4, ascbfr3, ascbfr2, ".", ascbfr1, ascbfr0
Return
'you can convert any binary value from 0000h to fffFh to 0000 to 65535 decimal
'just name the binary word as binval and call this subr and the ASCII
'result will be in ascbfr4,3,2,1,0, ready for your LCD or UART
'just pop the DP in the output to the LCD [as shown above]
bin2asc:
ascbfr4 = binval / 10000
temp3 = binval Mod 10000
ascbfr3 = temp3 / 1000
temp3 = binval Mod 1000
ascbfr2 = temp3 / 100
temp3 = temp3 Mod 100
ascbfr1 = temp3 / 10
ascbfr0 = temp3 Mod 10
'results are BCD so
'convert to ASCII for LCD or UART
ascbfr4 = ascbfr4 Or 0x30
ascbfr3 = ascbfr3 Or 0x30
ascbfr2 = ascbfr2 Or 0x30
ascbfr1 = ascbfr1 Or 0x30
ascbfr0 = ascbfr0 Or 0x30
Return