#include ; __CONFIG 0x3f21 __CONFIG _CONFIG1,_LVP_OFF &_FCMEN_OFF &_IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF &_INTRC_OSC_NOCLKOUT __CONFIG _CONFIG2, _WRT_OFF &_BOR21V ;setup variables cblock w2 endc org 0 initRegs: ;Setup PORTD banksel TRISD clrf TRISD ;set PORTD as direction as output banksel PORTD clrf PORTD ;Clear output pins at startup ;Setup our AI on pin RA0 banksel TRISA movlw 0xff movwf TRISA ;set RA0 as input, the rest are outputs banksel ANSEL movlw 0x01 movwf ANSEL ;Set RA0 as an analog input banksel ADCON1 ;movlw 0b11110000; movlw 0b11110000; movwf ADCON1 ;b[7] sets right justification, b[6:4] sets CS = FRC, ;b[2]+b[1:0] sets Vss and Vdd as refrences banksel ADCON0 movlw 0b01000001 movwf ADCON0 ; b[7:6] Configure A2D for Fosc/8, b[5:3] Select Channel RA0 ;b[0] Enable A2D Converter module ; ;Test outputs (debug only) ; banksel PORTD ; movlw 0xff ; movwf PORTD ; goto $ main ; TODO Step #5 - Insert Your Program Here goto acquireAI ; loop forever goto main nop nop nop acquireAI banksel ADCON0 nop ; 5uS needed to charge capacitor in RC circuit nop nop nop nop bsf ADCON0, GO_DONE ; Set A2D conversion status to in progress btfsc ADCON0, GO_DONE ; If in progress Keep Waiting Until Finsished (GO_DONE == 0) goto $-1 banksel ADRESH movfw ADRESH ;copy lower 8 bits ADC result held in ADRESL ;(because we chose right justification) to working register banksel PORTD ;movlw 0xff movwf PORTD ;set PORTD to ADC result return END