2015-02-09 82 views
0

彙編代碼中斷MPLAB的MPLab中斷彙編語言

MPLAB IDE:v8.92 芯片:dsPIC33FJ64GP802

我已經打算在這段代碼在彙編語言中斷。我不知道是否有與代碼或鏈接文件的問題(我用的連接器和頭文件對芯片),但是當我火異步切換INT0,代碼遇到

CORE-W0008: Software Reset Instruction called at PC=0x000202 

和代碼繼續從第一行開始,而不是進入中斷子程序。 我的研究沒有發現這個軟件重置指令的許多有用的結果。

這是代碼;

.include "p33FJ64GP802.inc" 

.global __reset 
.global __INT0interrupt   ; ISR (Interrupt Service Routine) 

.text       

__reset:    ; Code section 

MOV #0x900, W15     ; Enable the stack register 

MOV #__SPLIM_init, W0   

MOV W0, SPLIM     ; Initialize Stack Pointer Limit Register 

NOP 


CALL INITinit   ; Initialize interrupt enables 

CALL initIO    ; Initialize interrupt I/O ports 

CALL LED1 


INITinit:    ; Initialize the interrupt 

BSET IPC0, #0     ; Set Interrupt Priority Control bit #0 high 

BSET IPC0, #1     ; "  "   "  " bit #1 high 

BSET IPC0, #2     ; "  "   "  " bit #2 high 
(interrupt has highest priority) 

BSET IEC0, #0     ; Set Interrupt Enable Control (Register 0) High 
(Interrupt request enabled) 

BCLR IFS0, #0     ; Clear Interrupt Flag Status (Register 0) Low 

RETURN 


initIO:     ; Initialize Input/Output 

MOV #0XFFFF, W0 

MOV W0, AD1PCFGL    ; Disable analog I/O 

MOV #0x0000, W0     

MOV W0, TRISB     ; Output direction 

NOP 

BCLR TRISB, #1     ; Bit #1 cleared 'low' in TRISB  | Pin RB1 is 
output for LED1 

NOP 

BCLR TRISB, #2     ; Bit #2 cleared 'low' in TRISB  | Pin RB2 is 
output for LED2 

NOP 

BSET TRISB, #7     ; Bit #7 set 'high' in TRISB  | Pin RB7 is 
input for interupt 

NOP 

RETURN       


LED1:     ; Start of function 'LED 1'     

MOV #0xFFFF, W1     ; Blue LED 1 On 

MOV W1, PORTB     

CALL DELAY      

MOV #0x0000, W1     ; Blue LED 1 Off 

MOV W1, PORTB     

CALL DELAY              

GOTO LED1      ; Go to LED1 


DELAY:     ; Start function delay 

MOV #0x0001, W2     ; Set W2 High 

MOV #0x0000, W3     ; Start W3 Low 

again0:       ; Function 'again1' 

ADD #0x0001, W3     ; Add value '1' to regiter 3 

CPSEQ W3, W2     ; Compare W3 to W2- if equal then skip next line 

goto again0      ; Go to again1 

RETURN       ; Return from subroutine 


__INT0interrupt:   ; ISR   

NOP        ; No operation 

BTG PORTB, #7     ; BIT #7 of Port B is toggled(complimented) 

MOV #0x0005, W4 

MOV #0X0000, W5 

again1: 

MOV #0XFFFF, W1 

MOV W1, PORTB     ; Red LED 2 On 

CALL DELAY 

MOV #0X0000, W1 

MOV W1, PORTB     ; Red LED 2 OFF 

CALL DELAY 

INC W5, W5 

CPSEQ W4, W5 

goto again1 

BCLR IFS0, #0     ; BIT #0 of the IFSO is cleared 

NOP 

RETFIE       ; Return from interupt enable 


.end 

如果有人知道如何發送程序計數器來進入中斷服務程序,將不勝感激。

回答

0

當我使用ASM或16位處理器時,我並不熟悉這種格式,所以我無法真正區分所發生的一切或保證有一個明確的解決方案。然而,從我的一般ASM編程經驗中,我知道你必須有一個RESET向量和一個與標籤相關的中斷向量。

ORG 0x000 
<reset vector> 
ORG 0x14 
<INT0Interrupt> 

你看看這個PDF文件,顯示你的微處理器系列的中斷表嗎? INT0中斷向量位於地址0x14,通常情況下,除非您有代碼,否則程序將繼續執行外部指令或正常程序執行,導致不穩定的行爲。

http://ww1.microchip.com/downloads/en/DeviceDoc/70189C.pdf

您在0x202得到的復位指令的事實是由於線索中斷平板電腦在爲0x200結束。 我一直使用ORG彙編指令來確保代碼是它應該在的地方,請嘗試像這樣組織代碼:

ORG 0x000 
    goto program_entry_point 
    ORG 0x014 
    goto INT0Interrupt 

    ORG 0x200 
program_entry_point 
    <device initialization code> 
main_program_loop 
    <your code here> 
    goto main_program_loop 

    ORG 0x400 
INT0Interrupt 
    <ISR Code> 
    RETFIE 

    end