ADC In

This example reads an analog input on PORTA.0 and sends its value out serially on PORTC.6


' 10-bit A/D conversion 
' Connect analog input to channel-0 (RA0)

' Define ADCIN parameters
' Set number of bits in result
DEFINE  ADC_BITS        10 
' Set clock source (3=rc)
DEFINE  ADC_CLOCK       3   
' Set sampling time in microseconds
DEFINE  ADC_SAMPLEUS    10        

adcVar  VAR WORD ' Create variable to store result

' Set PORTA to all input
TRISA = %11111111     

' Set up ADCON1
ADCON1 = %10000010      

Pause 500               ' Wait .5 second

main:     
  ADCIN 0, adcVar ' Read channel 0
  SEROUT2 PORTC.6, 16468, [DEC adcVar, 10, 13]

  Pause 10               ' Wait.01 second
GoTo main