PIC 16F877 - A/D Converter
Apr 18, 2007 by Ale
This program displays on a led bar the binary value obtained before A/D conversion
;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
;**********************************************************
__config _LVP_OFF & _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF & _BODEN_OFF
& _DEBUG_OFF
list p=16f877
include "p16f877.inc"
; 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