Here's a quickie example.
Note: I cut the trace from the pot to RA0 on my board, soldered a wire to the pot output
circuit so I can connect the output from the pot to other A/D input pins.
This leaves RA0 free for serial debugging with the PICKit2 USART tool.
Code:@ device pic16F690, intrc_osc_noclkout, bod_off, wdt_off, mclr_off, protect_off DEFINE OSC 4 DEFINE DEBUG_REG PORTA DEFINE DEBUG_BIT 0 ' RA0 = TX out to PICKit2 programmer USART tool DEFINE DEBUG_BAUD 9600 DEFINE DEBUG_MODE 0 ' 1 = inverted, 0 = true DEFINE ADC_BITS 10 ' Set number of bits in result DEFINE ADC_CLOCK 1 ' Set clock source Fosc/8 "2uS" DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS Q CON 1251 ' For 10-bit A/D +Vref = 5V : 5V/1023*256=1.251=Quanta ADval VAR WORD Result VAR WORD OSCCON = %01100000 ' 4MHz internal osc ANSEL = %00000100 ' RA2 = A/D in, rest digital ANSELH = 0 ADCON0 = %10001001 ' Right justify, channel AN2, A/D enabled CM1CON0 = 0 CM2CON0 = 0 PORTA = %00000001 ' serial out pin idles high TRISA = %00000100 ' RA2 in, rest out Main: ADCIN 2,ADval Result = ADval */ Q DEBUG "Raw = ",DEC ADval," Real = ",DEC Result DIG 3,".",DEC3 Result," V",13,10 PAUSE 500 GOTO Main end




Bookmarks