[英]MSP430 - Assembly using jmp from BUTTON_ISR
I currently have this BUTTON_ISR set up to increment r9 ( which holds what mode the program is currently in ) and then if the mode is 0 or 1 it will jump to a loop that flashes the red led and if it is in mode 2 or 3 it will just go to an empty loop so the light doesn't flash. 我目前已将此BUTTON_ISR设置为递增r9 ( 它保持程序当前处于哪种模式 ),然后,如果该模式为0或1,它将跳到一个闪烁红色LED的循环,并且它处于模式2或3它只会进入一个空循环,因此指示灯不会闪烁。 However, my button only works once so I can get to mode 1 but then after that when I press the button on my board, nothing happens.
但是,我的按钮只能工作一次,因此我可以进入模式1,但是之后,当我按板上的按钮时,什么也没有发生。 Anyone know why this code is breaking my button?
有人知道为什么这段代码破坏了我的职责吗? I think it has something to do with jumping out of button isr instead of using reti but I am unsure how to fix this, thanks.
我认为这与退出按钮isr而不是使用reti有关,但是我不确定如何解决此问题,谢谢。
BUTTON_ISR:
push r15
push r14
; button code here
inc r9
.Ldebounce:
bit.b #0x08, &P1IN
jnz .Ldebounce
mov #120, r15
call #delay_ms
bic.b #BIT3, &P1IFG
pop r14
pop r15
cmp #0, r9
jeq .Lloop
cmp #1, r9
jeq .Lloop
cmp #2, r9
jeq .Loff
cmp #3, r9
jeq .Loff
mov #0, r9
jmp .Lloop
reti
Your decisions using the values of R9 are being performed within the interrupt handler and based upon the value in the R9 register you perform a jump to the labels .Lloop
or .Loff
. 您将在中断处理程序中使用R9的值进行决策,并根据R9寄存器中的值执行跳转到标签
.Lloop
或.Loff
。 There is no way for these routines to return to the interrupt function that you have here and even more important your last jump is an unconditional jump leaving no way back to the RETI
end of interrupt function. 这些例程无法返回到此处具有的中断功能,更重要的是,最后一次跳转是无条件跳转,无法返回中断函数的
RETI
结束。
You should have a short interrupt function that sets a mode value preferably in RAM and some main background code that polls this location to see what action is to be taken. 您应该具有一个短中断功能,该功能最好在RAM中设置一个模式值,并具有一些轮询该位置以查看将要采取的操作的主要背景代码。 Using the R9 register in the way that you have is going to fail if your interrupt function ever returns and the R9 register is used by any of your main code.
如果中断函数返回并且R9寄存器被任何主代码使用,则将R9寄存器以失败的方式使用。 This failure will be either that the value of the R9 register could be changed between interrupts so the incrementing sequence that you expect will not happen, or your main code will fail because the value in R9 is incremented at some random time in the middle of some calculation.
失败的原因可能是在中断之间可以更改R9寄存器的值,从而不会发生您期望的递增序列,或者您的主代码将失败,因为R9中的值会在某个中间的某个随机时间递增计算。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.