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


Browsing this Thread:   4 Anonymous Users






Re: PIC18使用In-line assembly
#7
版主
版主


查看用戶資訊
參照:

wei0510 寫道:
版主請問一下,我改成

#pragma udata access
near unsigned char CntL, CntH;

編譯時會出現:

Error [1013] error in pragma directive

但是如果像W401第五章中的範例一樣宣告成

#pragma udata access AccessSection
near unsigned char CntL, CntH;

就可以成功編譯了,關於這段我看不太懂,可以麻煩你幫我說明一下嗎?


AccessSection 是指節區名稱(Section Name) 自己給個名字不要重複即可。

發表於: 2009/12/30 10:41
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18使用In-line assembly
#6
高級會員
高級會員


查看用戶資訊
版主請問一下,我改成

#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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18使用In-line assembly
#5
版主
版主


查看用戶資訊
改成:
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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18使用In-line assembly
#4
高級會員
高級會員


查看用戶資訊
問題解決了:

當我用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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18使用In-line assembly
#3
高級會員
高級會員


查看用戶資訊
參考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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18使用In-line assembly
#2
高級會員
高級會員


查看用戶資訊
好像發現問題了

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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


PIC18使用In-line assembly
#1
高級會員
高級會員


查看用戶資訊
大家好,我又來問問題了:

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
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... ]

教育訓練中心

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