Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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
// 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
// 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
DelayMS(200)
ADVal = ADInAsVolt
LCD.MoveCursor (1,1)
LCD.Write("DC Volts = ", DecToStr(ADVal))//, ".", DecToStr(ADVal, 2), " ")
DelayMS(250)
Wend
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
Yes, but ADC.BAS isn't one of the libraries that have been updated... it's still the same version as long ago.Are you aware that there is a recent update (last few months)? I believe that ADC.BAS and most of the other include files have been updated to support new chip variants.
Device = 18F25K22
Clock = 64
// some LCD options...
#option LCD_DATA = PORTC.4
#option LCD_RS = PORTC.0
#option LCD_EN = PORTC.1
// uses LCD and AD libraries... /
Include "IntOSC.bas"
Include "LCD.bas"
Include "ADC.bas"
Include "convert.bas"
// read the AD port
Function ADCread() As Word
result = (ADC.Read(0))
End Function
// sampled AD value...
Dim ADVal As Word
// initialise and clear LCD...
TRISA.0 = 1 // configure AN0 as an input
DelayMS (500)
LCD.Cls
//ADC setup
ADCON2=%10101111
ADCON1=%00000000
TRISA=%00000001
ANSELA=%00000001
ADCON0=%00000001
ADCON0=%00000011
While ADCON1.bits(1) <> 0 //Is ADC done yet
DelayUS(10)
Wend
// main program loop...
While true
ADVal = ADCread
LCD.MoveCursor (1,1)
LCD.Write("ADC = ", DecToStr(ADVal), " ")
DelayMS(250)
Wend
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 HERE IS WHERE i TOOK OUT
End Function
// DIM STATEMENTS
Dim ADVal As Word
Dim led As PORTC.4
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
Output(led) //LED TESTING
Output(led1)
Output(led2)
led=0
led2=0
led3=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
ADVal = ADC.Read(0) // changed as per "visitor"
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)
Select ADVal
Case > 1000 'value over 1000
'no button pressed
Case > 900 Toggle(led)'value between 901 – 1000
'Button 10 pressed
Case > 800 Toggle(led1) 'value between 801 – 900
'Button 9 pressed
Case > 700 Toggle(led2)'value between 701 – 800
'Button 8 pressed
End Select
Wend
Debating leaving the FUNCTION--ETC WITH THE adc.read(0)+1)*500/1023
iT DIDN'T SEEM TO AFFECT ANYTHING WITH OR WITHOUT THE EXTRA MATH.
I know I shouldn't read these threads but it's just irresistible. Train wreck type of thing.
Mike.
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
Function ADCread() As Word
result = (ADC.Read(0))
End Function
// sampled AD value...
Dim ADVal As Word
Dim ADCOut As Word
// initialise and clear LCD...
TRISA.0 = 1 // configure AN0 as an input
LCD.Cls
DelayMS (500)
//ADC setup
ADCON2=%10101111
ADCON1=%00000000
TRISA=%00000001
ANSELA=%00000001
ADCON0=%00000001
ADCON0=%00000011
While ADCON1.bits(1) <> 0 //Is ADC done yet
DelayUS(10)
Wend
// main program loop...
While true
ADVal = ADCread
ADCOut = ADVal
LCD.MoveCursor (1,1)
Select ADCOut
Case > 1000 'value over 1000
' button 1 pressed
LCD.Write("button1 = ", DecToStr(ADVal), " ")
Case > 500 'value between 500 – 1000
'Button 2 pressed
LCD.Write("button2 = ", DecToStr(ADVal), " ")
Case > 330 'value between 330 – 500
'Button 3 pressed
LCD.Write("button3 = ", DecToStr(ADVal), " ")
Case > 230 'value between 230 – 330
'Button 4 pressed
LCD.Write("button4 = ", DecToStr(ADVal), " ")
Case > 190 'value between 190 – 230
'Button 5 pressed
LCD.Write("button5 = ", DecToStr(ADVal), " ")
End Select
DelayMS(250)
Wend
I realize I need to alter the CASE/SELECT for my application If I am interpenetrating correctly I can eliminate the FUNCTION.
As I understand it I need the FUNCTION for the CASE/SELECT as per the help file.
Sorry Pommie, no train wreck yet.