list p=16f876A ; list directive to define processor
#include <p16f876A.inc> ; processor specific variable definitions
errorlevel -302, -207
count1 equ 0x20
;Define CONF_WORD = 0x3bf4
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _LVP_OFF & _DEBUG_OFF & _CPD_OFF
ORG 0x000 ; processor reset vector
clrf PCLATH ; ensure page bits are cleared
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
nop
retfie ; return from interrupt
main:
;;;;;;;;;;;;;;;INITIALIZE A2D CONVERTER;;;;;;;;;;;;;;;;;;;;;;;
InitA2D:
banksel TRISA
movlw 0x01
movwf TRISA ;configure Port A pins as input
movlw 0x00
movwf TRISB
movlw 0x0E
movwf ADCON1 ; Bit 7-3: Unimplemented, Bit 2-0 Pin Configuration
banksel ADCON0
movlw 0x01
movwf ADCON0 ; Bit 7-6:Fosc/8, Bit5-3:Channel RA0, Bit2:GO/DONE,
; Bit 1:Unimplemented, Bit0:ADON
loop:
call ReadA2D
goto loop
;;;;;;;;;;;;;;;;READ AD LINE and display on PORTB ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ReadA2D:
call DelayAD
banksel ADCON0
BSF ADCON0,GO
convWait:
btfsc ADCON0,GO
goto convWait
movf ADRESH,W
movwf PORTB
return
;;;;;;;;;;;;;;;;;DELAY FOR AD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DelayAD:
movlw .12
movwf count1
repeat:
decfsz count1,f
goto repeat
return
end