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


Browsing this Thread:   3 Anonymous Users






Re: PIC12F510 problem
#6
高級會員
高級會員


查看用戶資訊
不知道是啥原因
在我發文過後,重新BUILD 再去執行程式
完全沒加 NOP
一切正常

READ_MODIFY_WRITE
沒有確定的結果嗎?

發表於: 2006/6/12 18:01
微電腦自動控制設計,產品製造
才疏學淺,若有錯誤敬請指正
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC12F510 problem
#5
版主
版主


查看用戶資訊
TEST_LOOP:
    
btfsc    SW_UP
    nop
    
goto    DOWN_TEST
    bcf    LED_UP
    nop
    bsf    LED_DOWN
    nop
    
DOWN_TEST
:
    
btfsc    SW_DOWN
    
goto    TEST_LOOP
    nop
    bcf    LED_DOWN
    nop
    bsf    LED_UP
    
goto    TEST_LOOP

雖然是 PIC18Fxxxx 但因為 BCF, BSF, BTFSS, BTFSC 都還是會將PORT的值讀進來做運算,所以還是要加入NOP指令以避免 Read-Modify-Write 的現象。

發表於: 2006/6/12 17:46
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC12F510 problem
#4
高級會員
高級會員


查看用戶資訊
請問板大,這種情形應該不會發生在18F對吧

我有一個簡單的CODE LED死都不亮(LOW 推動)
能幫我看一下嗎
list    p=18f458
#include <p18f458.inc>
    
#define     SW_UP         PORTB,0
#define     SW_DOWN     PORTB,1
#define     LED_UP        PORTB,4
#define     LED_DOWN     PORTB,5
    
    
org        0000h
    
goto    MAIN

        
MAIN
:
    
movlw    0ffh
    movwf    PORTB
    movlw    
b'00000011'
    
movwf    TRISB
    
TEST_LOOP
:
    
btfsc    SW_UP
    
goto    DOWN_TEST
    bcf        LED_UP
    bsf        LED_DOWN
    
DOWN_TEST
:
    
btfsc    SW_DOWN
    
goto    TEST_LOOP
    bcf        LED_DOWN
    bsf        LED_UP
    
goto    TEST_LOOP        
        
    
    end

板子是自己焊的
LED用線短路到地測試過了會亮(CPU拔起來,從IO的位置短路)
用ICD2跑
WATCH PORTB 執行BCF的時候,他的值都不會改變
不知道是啥問題
剛開始用18F,還不是很清楚他的IO跟以前16C有何差異
怎會這樣

發表於: 2006/6/9 18:06
微電腦自動控制設計,產品製造
才疏學淺,若有錯誤敬請指正
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC12F510 problem
#3
版主
版主


查看用戶資訊
這種現象稱之為 " READ-MODIFY-WRITE ",在 Data Sheet 裡有詳細的說明。在對同一PORT的BIT連續動作時需插入一個NOP指令以避免發生READ-MODIFY-WRITE 的動作。

5.5.2 SUCCESSIVE OPERATIONS ON I/O PORTS
The actual write to an I/O port happens at the end of an
instruction cycle. Whereas for reading, the data must
be valid at the beginning of the instruction cycle
(Figure 5-14). Therefore, care must be exercised if a
write followed by a read operation is carried out on the
same I/O port. The sequence of instructions should
allow the pin voltage to stabilize (load dependent)
before the next instruction causes the file to be read
into the CPU. Otherwise, the previous state of that pin
may be read into the CPU rather than the new state.
When in doubt, it is better to separate these
instructions with a NOP or another instruction not
accessing this I/O port.

發表於: 2006/6/9 9:33
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC12F510 problem
#2
高級會員
高級會員


查看用戶資訊
他們有個名詞在解釋連續對IO寫入讀出錯誤的情形
我忘了叫啥
基本上是這樣
當你BSF指令執行的時候,他會先讀入再輸出,連續執行時
因為時序的關係這樣會有錯誤
解決的方法是在 TRIS之後加一條NOP
每個BSF之間加一條NOP

發表於: 2006/6/8 19:20
微電腦自動控制設計,產品製造
才疏學淺,若有錯誤敬請指正
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


PIC12F510 problem
#1
新會員
新會員


查看用戶資訊
怎样把GP0,GP1,GP2定义成GPIO ?


#include <P12F510.INC>

__CONFIG _CP_OFF & _MCLRE_OFF & _IOSCFS_OFF & _WDT_OFF & _IntRC_OSC
ORG 0x000 ; coding begins here


clrf CM1CON0
clrf ADCON0
movlw b'001000'
tris GPIO

; Initialize output port
bsf GPIO, 0
bsf GPIO, 1
bsf GPIO, 2
bsf GPIO, 4
bsf GPIO, 5

END

这样简单的代码,怎么GPIO拿不到1呢?
请高手赐教。多谢!

發表於: 2006/6/7 18:43
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... ]

教育訓練中心

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