MrDEB
Well-Known Member
have a resistor ladder for 10 switches but getting the ADC port set up right.
The LCD only displays 5v regardless of which switch is pressed.
The ACON regestors?
The LCD only displays 5v regardless of which switch is pressed.
The ACON regestors?
Code:
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(1) + 1) * 500 / 1024 //set ADC input as porta.1
End Function
// sampled AD value...
Dim ADVal As Word
Dim led As PORTA.0
// initialise and clear LCD...
ADCON1 = $07 // PORTE as digital (LCD)
TRISA.1 = 1 // configure AN0 as an input ///
ADCON1.7 = 1 // set analogue input on PORTA.0 ///
DelayMS (500)
LCD.Cls
Input(PORTA.1) // ADC IN on portA.1
ADCON1 = %10000000 //set up ADC regesters
ADCON0.7 = 1
ADCON0.6 = 1
ADCON1 = $07
TRISA = %111111
TRISB = %11111111
TRISC = %00000000
TRISD = %00000000
TRISE = %000
// main program loop...
While true
led=1
DelayMS(1000)
led=0
DelayMS(1000)
ADVal = ADInAsVolt
LCD.MoveCursor (1,1)
LCD.Write("DC Volts = ", DecToStr(ADVal / 100), ".", DecToStr(ADVal, 2), " ")
DelayMS(250)
Wend