Device 16F877
Declare XTAL 4
DECLARE ADIN_RES 10 ' 10-bit result required
DECLARE ADIN_TAD FRC ' RC OSC chosen
DECLARE ADIN_STIME 50 ' Allow 50us sample time
Declare LCD_TYPE 0 ' Type of LCD Used is Alpha
Declare LCD_DTPIN PORTB.4 ' The control bits B4,B5,B6,B7
Declare LCD_RSPIN PORTB.2 ' RS pin on B2
Declare LCD_ENPIN PORTB.3 ' E pin on B3
Declare LCD_INTERFACE 4 ' Interface method is 4 bit
PORTB_PULLUPS True
Dim Result1 As Float
Dim Result2 As Float
Dim Last_Result1 As Float
Dim Last_Result2 As Float
Symbol Input1 = PORTA.0
Symbol Input2 = PORTA.1
TRISA = %00000011 ' Configure AN0 (PORTA.0+1) as an input
ADCON1 = %10000000 ' Set analogue input, Vref is Vdd
Main:
Result1 = ADIN 0 ' Grab A0's digital value
Delayus 1 ' Allow internal capacitors to charge
Result2 = ADIN 1 ' Grab A1's digital value
Result1 = Result1 * 5 / 1023 ' Scale it to volts
Result2 = Result2 * 5 / 1023 '
If Last_Result1 <> Result1 Then ' Check if value has changed
Print At 1, 1, Dec2 Result1, "V " ' If it has, display new data
Last_Result1 = Result1 ' and update last value
EndIf
If Last_Result2 <> Result2 Then ' Check if value has changed
Print At 2, 1, Dec2 Result2, "V " ' If it has, display new data
Last_Result2 = Result2 ' and update last value
EndIf
Goto Main ' Loop for ever