MPLab汇编语言中断

时间:2015-02-09 20:59:51

标签: assembly interrupt 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

如果有人知道如何发送程序计数器以进入中断服务程序,我们将不胜感激。

1 个答案:

答案 0 :(得分:1)

在使用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
相关问题