Thu May 16, 2013 4:37 pm
list p = 16f877
include <p16f877.inc>
BANK0 macro
bcf STATUS,RP0
bcf STATUS,RP1
endm
BANK1 macro
bsf STATUS,RP0
bcf STATUS,RP1
endm
BANK2 macro
bcf STATUS,RP0
bsf STATUS,RP1
endm
BANK3 macro
bsf STATUS,RP0
bsf STATUS,RP1
endm
COUNT EQU 0x22 ;USED FOR COUNTING
RESULT EQU 0x23
ORG 0
NOP
GOTO START
ORG 0x20
START CALL INIT
REPEAT CLRF COUNT ;SET COUNT TO ZERO
RAMP MOVF COUNT,W ;GET COUNT vALUE
MOVWF PORTD ;AND OUTPUT TO DAC
BTFSC PORTA,4 ;TEST COMP OUTPUT
GOTO DONE ;IF NOT ZERo
; CoNVERS ION CoMPLETE
INCF COUNT ;COtINT UP
GOTO RAMP ;RAMP UP
DONE MOVF COUNT,W ;GET COUNT
MOVWF RESULT ;AND STORE
GOTO REPEAT ;DO AGAIN
;PORT INIT ROUTINE
INIT BSF STATUS,RP0 ;SET To BANK 1.
CLRF TRISD ;SET PORT D To OUTPUT
MOVLW 06 ;MAKE PoRT A DIGITAL
MOVWF ADCON1
BSF TRISA,4 ;AND BIT A4 To INPUT
BCF STATUS,RP0 ;BACK To BANK 0
RETURN
END
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.