' Read channel 0 of on-board ADC and display the results Device 16F877 ' Choose the 16F877 Declare XTAL 20 ' We'll use a 20MHz Xtal Declare Rsout_Pin PortB.0 ' Serial out pin is PortB bit-0 Declare ADIN_TAD FRC ' Choose the RC osc for ADC samples Declare ADIN_STIME 100 ' Allow 100us for charge time Dim Raw as Word Dim Value as Word Dim Volts as Byte Dim Millivolts as Word Rsout Cls ' Clear the serial LCD TrisA.0 = 1 ' Setup bit-0 of PortA as an input ADCON1 = %10000000 ' Right justified result in ADRESL and ADRESH Again: Raw = ADIN 0 ' Read the ADC Rsout at 2,1,"RAW= ",@Raw," " ' Display the RAW data Value = 489 *(Raw / 10) ' Quantasize the result Volts = Value / 10000 Millivolts=(Value // 10000) / 100 Rsout at 1,1,dec1 Volts,".",dec2 Millivolts,"V " ' Display the result Goto Again ' Do it forever