Device = 18F43k22
Clock = 20
// some LCD options...
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
// uses LCD and AD libraries...
Include "LCD.bas"
Include "ADC.bas"
Include "convert.bas"
// read the AD port and scale for 0 - 5 volts...
Function ADInAsVolt() As Word
result = (ADC.Read(0) + 1)*500/1024 //set ADC input as porta.0
End Function
// sampled AD value...
Dim ADVal As Word
Dim led As PORTA.0
Dim led1 As PORTC.0
Dim led2 As PORTC.1
Dim led3 As PORTC.3
Dim ADCOut As Word
// initialise and clear LCD...
ADCON1 = $07 // PORTE as digital (LCD)
TRISA.1 = 1 // configure AN0 as an input ///
ADCON1.6 = 1 // set analogue input on PORTA.0 ///
DelayMS (500)
LCD.Cls
Input(PORTA.0) // ADC IN on portA.1
ADCOut = 0
// ADCON1 = %10000000 //set up ADC regesters
//ADCON0.7 = 1
//ADCON0.6 = 1
ADCON1 = $07
TRISA = %11111111
TRISB = %11111111
TRISC = %00000000
TRISD = %00000000
TRISE = %000
/////////////////////////////
'ADC setup
ADCON2=%10101111
ADCON1=%00000000
TRISA=%00000001
ANSELA=%00000001
ADCON0=%00000001
ADCON0=%00000011
///////////////////////////////////
While ADCON1.bits(1) <> 0 'ADC not done yet
DelayUS(10)
Wend
// main program loop...
While true
// Dim ADCOut as Word
DelayMS(200)
ADVal = ADC.Read(0) // changed as per "visitor"
LCD.MoveCursor (1,1)
LCD.Write("ADC = ", DecToStr(ADVal), " ") // changed as per "visitor"
//LCD.Write("DC Volts = ", DecToStr(ADVal))//, ".", DecToStr(ADVal, 2), " ")
DelayMS(250)
Wend
output = 152, 236, 320, 405, 488, 572, 659, 723, 836, 929now omn to building the CASE SELECT portion