• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   2 Anonymous Users






Re: 想請大家幫我看一個簡單的程式
#2
資深會員
資深會員


查看用戶資訊
ANSEL 中的ADCS 應設為 001 FOSC/8 或 101 = FOSC/16
轉換時間 不能太快或太慢

GP5 你是設成 輸出 ANSEL AN3 是GPIO4
ADCON0 中的 CHS0:1 --> 0 是 AN0
DATASHEET 中的 A/D 那一章 你要再詳讀一下

發表於: 2007/3/2 5:03
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


想請大家幫我看一個簡單的程式
#1
新會員
新會員


查看用戶資訊
大家高手好,個人因為想學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

想請問一下我那邊的邏輯關念錯了呢?先感謝大家><

發表於: 2007/3/1 15:57
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------