Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF
Include "ADC.bas" // Include the ADC.bas library
Dim LED As PORTC.0 // Declare the LED pin
//**********************************************
// sample ADC pin 1 input
//***********************************************
Function Get_ADC_Sample() As Word // Function to grab the ADC sample
result = ADC.Read(0) // Grab an ADC sample from channel 0
result = result * 2 // Scale the answer up by a factor of 2
End Function
OSCCON = %01110110 // Setup the internal OSC for 8Mhz
Input(PORTA.0) // Make AN0 an inputpin 1
//********************************************************************
// Create an infinate loop
//********************************************************************
While True
If (Get_ADC_Sample)<=512
Then Low (led0)
EndIf
If (Get_ADC_Sample) > 512
Then Toggle (led0) // Make the LED pin High
EndIf
Wend