大家高手好,個人因為想學PIC所以小小試了一下,
我是用12F675八支腳的。
想先寫一個簡單的程式就是t2-t1=正數時不動作,當相減
為負數時就要送一個high的信號出去。
LIST P=12F675
#INCLUDE<P12F675.INC>
D1 EQU 0X21
VB1 EQU 0X22
ORG 00H
START:
BSF STATUS,RP0;切換到BANK1
MOVLW B'00001000';設定數位類比模式
MOVWF ANSEL
MOVLW B'00011000';設定GP5為輸入接腳
MOVWF TRISIO ;設定GP0為輸出接腳
BCF STATUS,RP0;切換到BANK0
CLRF ADCON0 ;往左靠
CLRF GPIO ;設定GPIO輸出
MOVLW B'00001101'
MOVWF ADCON0
;============AD轉換=========
ADCONVERT:
CALL DELAY
BSF ADCON0,GO
ADWAIT:
NOP
BTFSS PIR1,ADIF
GOTO ADWAIT
BCF PIR1,ADIF
MOVF ADRESH,W
MOVWF VB1
CALL DELAY
;===========第二次轉換=======
ADCONVERT1:
CALL DELAY
BSF ADCON0,GO
ADWAIT1:
NOP
BTFSS PIR1,ADIF
GOTO ADWAIT1
BCF PIR1,ADIF
MOVF ADRESH,W
;=============================
SUBWF VB1,W ;W-VB1
MOVWF VB1
BTFSS STATUS,C ;判斷進位旗標如果為負就goto shutdown
GOTO SHUTDOWN
SUBWF VB1,W ;W-VB1
MOVWF VB1
BTFSC STATUS,C ;為正的話就回去start
GOTO START
;==================================
SHUTDOWN:
BSF GPIO,0 ;給GP0 high 訊號
GOTO SHUTDOWN
;=================================
DELAY:
MOVLW .25
MOVWF D1
DLY1:
DECFSZ D1,F
GOTO DLY1
RETURN
END
想請問一下我那邊的邏輯關念錯了呢?先感謝大家><