title: ARM Assembly - Basic Interrupt Handling
body: <p>I'm currently messing around with some ARM Assembler on the lpc2378, I've wrote a loop to control a furnace's temperature, however; I believe I need to implement some kind of interrupt handling to complete my project.</p>
  
  <p>When the application runs, it enters a loop, which waits for Button_1 input, the loop then carries on and goes through various stages but it cannot reach wait for Button_2 input for the application to function.</p>
  
  <p>So a couple of questions here, how exactly does the interrupt handler work? and how could I implement it into my application.</p>
  
  <p>Here is my Button_1 code:</p>
  
  <pre><code>;=========================================================================
  ; 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
  </code></pre>
  
  <p>and my Button_2 code:</p>
  
  <pre><code>;=========================================================================
  ; 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
  </code></pre>
  
  <p>and also my furnace control loop:</p>
  
  <pre><code>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 &lt; 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
  </code></pre>
  
  <p>Thanks in advance.</p>