标题: AD 程序 [打印本页] 作者: winnie 时间: 2009-5-20 14:38 标题: AD 程序 LIST P=16F877
INCLUDE <C:\WORK\P16F877.INC>
TEMP EQU 70H
FLAG1 EQU 71H
OPTION_BACK EQU 72H
ADH EQU 73H
ADL EQU 74H
COUNT EQU 75H
W_STACK EQU 76H
ST_STACK EQU 77H
ORG 0x0000
GOTO MAIN
ORG 0x0004
BTFSC PIR1,ADIF
GOTO ADS
RETFIE
ADS BTFSS ADCON0,GO
GOTO AD
RETFIE
ORG 0x0020
AD CALL PUSH
BCF PIR1,ADIF
BTFSS TEMP,2 ;TEST TEMP-4? YES,THEN CLEAR THE ADH,ADL. OR WILL GO TO AD CONVERTER
GOTO AD1
CLRF ADH
CLRF ADL
AD1 bsf status,rp0 ;select bank1
MOVF ADRESL,0
ADDWF ADL
BTFSC STATUS,C
INCF ADH
BCF STATUS,RP0 ;SELECT BANK0
MOVF ADRESH,0
ADDWF ADH
DECFSZ TEMP ;temp-1=0 ? no,then go to next ad,but yes will set the finished flag
GOTO AD2
MOVLW 0x04 ;initial temp again.
MOVWF TEMP
BSF FLAG1,1 ;set the AD finished flag
CALL POP
RETFIE
AD2 CALL DELAY ;CALL THE DELAY TIME ,FOR DELAY 2uS.
BSF ADCON0,GO ;START THE NEXT AD
CALL POP
RETFIE
PUSH MOVWF W_STACK
MOVF STATUS,0
MOVWF ST_STACK
BCF STATUS,RP0
RETURN
POP MOVF ST_STACK,0
MOVWF STATUS
MOVF W_STACK,0
RETURN
ADINI BCF STATUS,RP0
MOVLW B'10000001' ;AD INITIAL,OPEN THE AD
MOVWF ADCON0