Re: PIC18使用In-line assembly
|
||||
---|---|---|---|---|
高級會員
|
版主請問一下,我改成
#pragma udata access near unsigned char CntL, CntH; 編譯時會出現: Error [1013] error in pragma directive 但是如果像W401第五章中的範例一樣宣告成 #pragma udata access AccessSection near unsigned char CntL, CntH; 就可以成功編譯了,關於這段我看不太懂,可以麻煩你幫我說明一下嗎?
發表於: 2009/12/30 10:25
|
|||
|
Re: PIC18使用In-line assembly
|
||||
---|---|---|---|---|
版主
|
改成:
pragma udata access near unsigned char CntL, CntH; void main(void) { _asm CLRF CntL,0 COMF CntL,1,0 CLRF CntL,0 CLRF CntH,0 COMF CntH,1,0 CLRF CntH,0 _endasm } 另外 In-Line Assemble 無法變數給 C 用。如果寫標準的 Assembly 再加上 Global (ASM) 與 extern ( C) 的宣告就可以了。
發表於: 2009/12/30 9:48
|
|||
|
Re: PIC18使用In-line assembly
|
||||
---|---|---|---|---|
高級會員
|
問題解決了:
當我用C語言宣告全域變數時,因為沒有使用關鍵字access,所以這變數被安排在RAM的GPR區中的0xd14位址。 #pragma udata unsigned char CntL, CntH; 之後我用的2種ASM指令最後一個參數我參考範例都設為0,但是閱讀指令說明才知道,當最後一個參數為0,它會從access區域找尋這個變數,所以當程式被組譯後,此處的CntL被認定是access區的0x001位址。 void main(void) { _asm CLRF CntL,0 COMF CntL,1,0 CLRF CntL,0 CLRF CntH,0 COMF CntH,1,0 CLRF CntH,0 _endasm } 不過對於使用說明上面的指令說明,對於兩個指令最後一個參數有談"擴充指令",之前我曾經因為這個東西導致發生一些預料外的狀況,所以就一直把它關掉了,到現在我只知道這東西在某些比較新的pic18 IC才有,但實際上是做什麼用的,實在是有看沒有懂。
發表於: 2009/12/29 18:30
|
|||
|
Re: PIC18使用In-line assembly
|
||||
---|---|---|---|---|
高級會員
|
參考W401的範例ex7-1.c,我把CntL及CntH的宣告改成全域變數:
#pragma udata unsigned char CntL, CntH; void main(void) { _asm CLRF CntL,0 COMF CntL,1,0 CLRF CntL,0 CLRF CntH,0 COMF CntH,1,0 CLRF CntH,0 _endasm } C宣告的Cnt跟ASM使用的Cnt依然是不同位址,請問還有地方是我沒注意到的嗎?
發表於: 2009/12/29 17:57
|
|||
|
Re: PIC18使用In-line assembly
|
||||
---|---|---|---|---|
高級會員
|
好像發現問題了
unsigned char CntL, CntH; 這行中,COMPILE將CntL安排在位址0xD14、CntH安排在位址0xD15,但是 _asm CLRF CntL, 0 COMF CntL,1, 0 CLRF CntL, 0 CLRF CntH, 0 COMF CntH, 1, 0 CLRF CntH, 0 _endasm 中COMPILE將CntL位址設在0x001、CntH位址設在0x002,所以我用Watch看著0xD14、0xD15自然是不會改變,不過我還沒找到要怎麼解決這個問題。
發表於: 2009/12/29 16:48
|
|||
|
PIC18使用In-line assembly
|
||||
---|---|---|---|---|
高級會員
|
大家好,我又來問問題了:
unsigned char CntL, CntH; _asm CLRF CntL, 0 COMF CntL,1, 0 CLRF CntL, 0 CLRF CntH, 0 COMF CntH, 1, 0 CLRF CntH, 0 _endasm 這是我使用C語言宣告變數,再以In-line assembly編寫一個簡單的測試,但是我用ICD2進行實際模擬時,在WATCH視窗中發現CntL及CntH不會改變,可是在W401第二天的講義第70頁有提到In-line assembly可以使用C的變數,請問是我誤會它的意思,還是使用的方法錯誤了呢? 另外想請教一下,如果換成要在In-line assembly中宣告2個變數,並且讓後段的C語言中可以讀取(寫入)它又要怎麼做呢?
發表於: 2009/12/29 16:12
|
|||
|