;16F877 A/D test routine
;
;TEST CIRCUIT:
;pin 11 & 32 = 5VDC
;pin 12 & 31 = 0VDC
;pin 1 = 5VDC
;pin 2 = 0 - 5 VDC analog input (center tap on 20k variable resistor)
;pin 13 & 14 = 4MHz crystal with 18pF capacitors to 0VDC
;pin 15,16,17,18,23,24,25,26 PORTC outputs each to 330 ohm resistor
;       in series with LED to 0VDC
;**********************************************************

	LIST	P=PIC16F877												
	INCLUDE "P16f877.inc"											
	__CONFIG B'11111100110001' 
	ERRORLEVEL -302

        ; Start at the reset vector
        org     0x000
        goto    Start
        org     0x004
Interrupt
        retfie
Start
        bsf     STATUS,RP0      ;bank 1
        bcf     STATUS,RP1
        movlw   H'00'
        movwf   TRISC           ;portc [7-0] outputs
        clrf    ADCON1          ;left justified, all inputs A/D
        bcf     STATUS,RP0      ;bank 0
        movlw   B'01000001'     ;Fosc/8 [7-6], A/D ch0 [5-3], A/D on [0]
        movwf   ADCON0
Main
        call    ad_portc
        goto    Main


ad_portc
                                ;wait for acquision time (20uS)
                                ;(non-critical for this test)

        bsf     ADCON0,GO       ;Start A/D conversion
Wait
        btfsc   ADCON0,GO       ;Wait for conversion to complete
        goto    Wait

        movf    ADRESH,W        ;Write A/D result to PORTC
        movwf   PORTC           ;LEDs
        return

        end