• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: PIC16 組合語言: 中斷程式與主程式不同Page
#5
版主
版主


查看用戶資訊
Microchip 所提供的範例為 :
;***** VARIABLE DEFINITIONS
w_temp        EQU    0x7D        
variable used for context saving 
status_temp    EQU    0x7E        
variable used for context saving
pclath_temp    EQU    0x7F        
variable used for context saving

:
:

    
ORG     0x004             interrupt vector location

    movwf   w_temp            
save off current W register contents
    movf    STATUS
,w          move status register into W register
    movwf    status_temp       
save off contents of STATUS register
    movf    PCLATH
,w      move pclath register into w register
    movwf    pclath_temp      
save off contents of PCLATH register

isr code can go here or be located as a call subroutine elsewhere
:
:
:

    
movf    pclath_temp,w      retrieve copy of PCLATH register
    movwf    PCLATH          
restore pre-isr PCLATH register contents
    movf    status_temp
,w     retrieve copy of STATUS register
    movwf    STATUS            
restore pre-isr STATUS register contents
    swapf   w_temp
,f
    swapf   w_temp
,w          restore pre-isr W register contents
    retfie                    
; return from interrupt


易上範例摘自 C:\Program Files\Microchip\MPASM Suite\Template\Code\16F877ATEMP.asm 因為有 8K flash 所以就會加入 PCLATH 暫存器的儲存。
如果使用 PIC18F877 之類有內建 Share Bank 的元件,只要將中斷所使用的變數設定在 Share RAM 裡,這樣在中斷時也可以不動到 PCLCTH 的。

發表於: 2009/8/28 9:22
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC16 組合語言: 中斷程式與主程式不同Page
#4
新會員
新會員


查看用戶資訊
謝謝shpeng:

如你所說,

ORG 0x0004
_PushAll <--- 一定要放在0x0004,不可直接 lgoto.

我 直接先 lgoto 才 _PushAll 了, :)

謝謝你的解答!!

發表於: 2009/8/27 21:15
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC16 組合語言: 中斷程式與主程式不同Page
#3
資深會員
資深會員


查看用戶資訊
_PushAll    macro
    movwf    w_temp
    movfw    STATUS
    clrf    STATUS
    movwf    status_temp
    movfw    PCLATH
    movwf    pclath_temp 
    movfw    FSR
    movwf    fsr_temp   
    clrf    PCLATH
    endm

_PopAll        macro
    clrf    STATUS        
;BANK0
    movfw    fsr_temp
    movwf    FSR
    movfw    pclath_temp
    movwf    PCLATH 
    movfw    status_temp
    movwf    STATUS
    swapf    w_temp
,f
    swapf    w_temp
,w
    endm

    ORG 0x0004
     _PushAll  
<--- 一定要放在0x0004,不可直接 lgoto.

    
lcall    PAGE1_XXXX
     
.
     .
     .
     .
     
_PopAll  <--- 
    
RETFIE


主程式有 RUN PAGE1,2,3,中斷程式要存 PCLATH.
祝順心

發表於: 2009/8/27 17:09
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC16 組合語言: 中斷程式與主程式不同Page
#2
資深會員
資深會員


查看用戶資訊
參考一下這裏
http://www.microchip.com.tw/modules/w ... lefile.php?cid=18&lid=304

原始提供者:劉文昱jack@jaeger.com.tw

標題:靈活使用PIC16C57的PROGRAM MEMORY
當您使用Microchip公司的PIC16C57在設計程式時,是否被它的PROGRAM MEMORY需分PAGE使用,而PAGE之設定又影響到goto、call、addwf 2、movwf 2四個指令之執行結果而困擾不已呢?以下是小弟領悟出來的一點心得,在此野人獻曝,與大家分享。
.....

發表於: 2009/8/27 17:01
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


PIC16 組合語言: 中斷程式與主程式不同Page
#1
新會員
新會員


查看用戶資訊
如果主程式在Page 1 (ORG H'800'), 中斷程式在Page 0,
在中斷情況發生時中斷程式執行完畢(RETFIE)後應該仍會處於Page0而導致錯誤(應該是要返回主程式段本來位址才對).

請問該如何做才能避免此問題?

發表於: 2009/8/27 15:19
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... ]

教育訓練中心

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