Advertisement
tom_burgess

LED Control ARM

Mar 1st, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.07 KB | None | 0 0
  1. start      
  2.             BL longpulse
  3.             BL longpulse
  4.             BL longpulse
  5.             BL shortpulse
  6.             BL shortpulse
  7.             BL shortpulse
  8.             B start
  9.  
  10. longpulse   PUSH {LR}
  11.             BL ledon
  12.             MOV R0,#2000
  13.             BL delay
  14.            
  15.             BL ledoff
  16.             MOV R0,#1000
  17.             BL delay
  18.            
  19.             POP {LR}
  20.             BX LR
  21.  
  22. shortpulse  PUSH {LR}
  23.             BL ledon
  24.             MOV R0,#200
  25.             BL delay
  26.            
  27.             BL ledoff
  28.             MOV R0,#1000
  29.             BL delay
  30.            
  31.             POP {LR}
  32.             BX LR
  33.  
  34. ; delay subroutine - blocks for the number of milliseconds in R0.  
  35. delay   PUSH {lr}
  36.         PUSH {R0}
  37.         PUSH {R1}
  38. delayo  MOV R1,#3200        ; Start of outer loop, counts down from R0.
  39. delayi  SUB R1,#0x01        ; Start of inner loop, counts down from 3200 (takes ~1ms).
  40.         CMP R1,#0x00
  41.         BNE delayi          ; End of inner loop
  42.         SUB R0,#1           ; Subtract 1 from number of milliseconds.
  43.         CMP R0,#0           ; Check if we got to 0ms.
  44.         BNE delayo          ; If not, go around the inner loop again...
  45.         POP {R1}
  46.         POP {R0}
  47.         POP {lr}
  48.         BX  LR                  ; Otherwise return.
  49.  
  50. ; ledon subroutine - switches the LED on.
  51. ledon  
  52.         PUSH {lr}
  53.         PUSH {R1}
  54.         PUSH {R2}
  55.         PUSH {R0}
  56.         LDR R0,=0x40020000  ; Put GPIOA register Base Address in R0 (see page 38 RM0368).
  57.         LDR R1,[R0, #0x14]  ; Load the current value of port A ODR (base+0x14) into R1.
  58.         MOV R2,#1               ; 1 of 3 lines to do a 'R1=R1|(1<<5)'
  59.         LSL R2,#5               ; 2 of 3 lines to do a 'R1=R1|(1<<5)'
  60.         ORR R1,R2                   ; 3 of 3 lines to do a 'R1=R1|(1<<5)'          
  61.         STR R1,[R0, #0x14]  ; Store new value for port A ODR with 5th bit set.
  62.         POP {R0}
  63.         POP {R2}
  64.         POP {R1}
  65.         POP {lr}
  66.         BX  LR
  67.            
  68. ; ledoff subroutine - switches the LED off.
  69. ledoff  PUSH {lr}  
  70.         PUSH {R1}
  71.         PUSH {R2}      
  72.         PUSH {R0}
  73.         LDR R0,=0x40020000  ; Put GPIOA register Base Address in R0 (see page 38 RM0368).
  74.         LDR R1,[R0, #0x14]  ; Load the current value of port A ODR (base+0x14) into R1.
  75.         MOV R2,#1               ; 1 of 3 lines to clear the 5th bit of R1.
  76.         LSL R2,#5               ; 2 of 3 lines to clear the 5th bit of R1.
  77.         BIC R1,R2                   ; 3 of 3 lines to clear the 5th bit of R1.     
  78.         STR R1,[R0, #0x14]  ; Store new value for port A ODR with 5th bit set.
  79.         POP {R0}
  80.         POP {R2}
  81.         POP {R1}
  82.         POP {lr}
  83.         BX  LR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement