我目前正在处理 lpc2378 上的一些 ARM 汇编程序,但是我编写了一个循环来控制炉子的温度;我相信我需要实现某种中断处理来完成我的项目。
当应用程序运行时,它进入一个循环,等待 Button_1 输入,然后循环继续并经过各个阶段,但无法等待 Button_2 输入以使应用程序运行。
所以这里有几个问题,中断处理程序究竟是如何工作的?以及如何将它实现到我的应用程序中。
这是我的 Button_1 代码:
;=========================================================================
; Wait for BUT1 to be pressed
;=========================================================================
WaitBUT1
STMFD r13!,{r0,r5,r14} ; Push r0, r5 and LR
WaitForBUT1Pressed
ldr r0, = IO0PIN ; Address of FIO0PIN register
ldr r1, [r0] ; Read FIO0PIN in to r1
ands r1, r1, # B1_MASK ; Mask out BUT1
beq BUT1Pressed ; Exit LED toggle loop if button is pressed
B WaitForBUT1Pressed
BUT1Pressed
LDMFD r13!,{r0,r5,r14} ; Pop r0, r5 and LR
mov pc, r14 ; Put link register back into PC
和我的 Button_2 代码:
;=========================================================================
; Wait for BUT2 to be pressed
;=========================================================================
WaitBUT2
STMFD r13!,{r0,r5,r14} ; Push r0, r5 and LR
WaitForBUT2Pressed
ldr r0, = IO0PIN ; Address of FIO0PIN register
ldr r1, [r0] ; Read FIO0PIN in to r1
ands r1, r1, # B2_MASK ; Mask out BUT1
beq BUT2Pressed ; Exit LED toggle loop if button is pressed
B WaitForBUT2Pressed
BUT2Pressed
LDMFD r13!,{r0,r5,r14} ; Pop r0, r5 and LR
mov pc, r14 ; Put link register back into PC
还有我的炉子控制回路:
LoopStart
BL WaitBUT1 ; wait until button 1 is pressed
BL heaterOn ; turn heater on
BL systemLedOn ; turn system LED on
BL readTemp ; Check ADC for temp
BL checkTemp ; Count down, check ADC for temp
CMP r3, #5 ; Compare timer with delay
BGT errorVal
SUBS r4, r2, r7 ;Performs r7 = r4 - r2 and sets condition register
BEQ LoopStart ; if equal nothing to do
BGT overTemp ; r7 < 0 case
BL errorLedOn
BL heaterOn
BL FanOff
B LoopStart
overTemp
BL errorLedOn
BL heaterOff
BL FanOn
B LoopStart
BL WaitBUT2
BL FanOff
BL errorLedOff
BL systemLedOff
BL heaterOff
B LoopStart
提前致谢。