【问题标题】:MPLab Interrupt in Assembly Language汇编语言中的 MPLab 中断
【发布时间】:2015-02-09 20:59:50
【问题描述】:

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

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

【问题讨论】:

    标签: assembly interrupt mplab


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2019-09-25
      • 1970-01-01
      • 1970-01-01
      • 2010-12-24
      • 2011-10-22
      • 2013-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多