Advertisement
Guest User

Untitled

a guest
Dec 14th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.88 KB | None | 0 0
  1. @ LED Fun & Stuff
  2.  
  3. LDR R0, =0x44e000AC     @ Address of CM_PER_CPIO1_CLKCTRL
  4. MOV R1, #0x2                @ Enable value for GPIO1 module
  5. STR R1, [R0]                @ Enable GPIO1 module
  6. LDR R1, =0x4804C000     @ GPIO1 base address
  7. MOV R0, #0x01E00000     @ Toggle pins 21-24 value
  8. STR R0, [R1, #0x190]        @ Clear pins 21-24 of GPIO1
  9. LDR R2, [R1, #0x134]        @ Read GPIO1 OE register
  10. BIC R2, R2, R0              @ Modify value, clearing bits 21-24
  11. STR R2, [R1, #0x134]        @ Write back to OE reg.
  12. LDR R0, =LEDStatus      @ Load state variable.
  13. LEDLoop:
  14.     MOV R2, #0x10000000 @ Some big delay constant
  15.     BL LEDFun               @ Call LED-twiddling function
  16.     SUBS R0, R0, #1     @ Decrement LEDStatus
  17.         MOVEQ R0, #6        @ If LEDStatus = 0, reset to 6
  18. D:  SUBS R2, #1         @ Decrement delay constant
  19.         BNE D               @ Wait in delay loop
  20.     B LEDLoop               @ Return to LED cycle.
  21.    
  22. LEDFun: STMFD SP!, {R0-R2, LR}  @ Store registers used
  23.     LDR R1, =0x4804C000 @ Load GPIO1 base address.  (Is this necessary?)
  24.     MOVS R0, R0         @ Update flags
  25.         BEQ StateZero   @ If in State Zero, branch to StateZero.
  26.     CMP R0, #6              @ If in State Six,
  27.         BEQ StateSix        @ then branch to StateSix
  28.     CMP R0, #5              @ And so on.
  29.         BEQ StateFive
  30.     CMP R0, #4
  31.         BEQ StateFour
  32.     CMP R0, #3
  33.         BEQ StateThree
  34.     CMP R0, #2
  35.         BEQ StateTwo
  36.     CMP R0, #1
  37.         BEQ StateOne
  38.    
  39.     @ In these State branches, R0 is loaded with the
  40.     @ pins to be Set, and R2 with the pins to be Cleared.
  41.     @ If R0 = 0, all pins should be Cleared, so R0 is not
  42.     @ updated.  After R0 and R2 are loaded, program branches
  43.     @ to LEDTog, which handles clearing, setting, and exiting.
  44.     StateZero:
  45.         MOV R2, #0x01E00000 @ Clear all value
  46.         B LEDTog
  47.     StateSix:
  48.         MOV R2, #0x00400000 @ Clear LED1 value
  49.         MOV R0, #0x00200000 @ Set LED0 value
  50.         B LEDTog
  51.     StateFive:
  52.         MOV R2, #0x00200000 @ Clear LED0 value
  53.         MOV R0, #0x00400000 @ Set LED1 value
  54.         B LEDTog
  55.     StateFive:
  56.         MOV R2, #0x00200000 @ Clear LED0 value
  57.         MOV R0, #0x00400000 @ Set LED1 value
  58.         B LEDTog
  59.     StateFour:
  60.         MOV R2, #0x00400000 @ Clear LED1 value
  61.         MOV R0, #0x00800000 @ Set LED2 value
  62.         B LEDTog
  63.     StateThree:
  64.         MOV R2, #0x00800000 @ Clear LED2 value
  65.         MOV R0, #0x01000000 @ Set LED3 value
  66.         B LEDTog
  67.     StateTwo:
  68.         MOV R2, #0x01000000 @ Clear LED3 value
  69.         MOV R0, #0x00800000 @ Set LED2 value
  70.         B LEDTog
  71.     StateOne:
  72.         MOV R2, #0x00800000 @ Clear LED2 value
  73.         MOV R0, #0x00400000 @ Set LED1 value
  74.         B LEDTog
  75.  
  76.     LEDTog:
  77.         STR R2, [R1, #0x190]    @ Clear LEDs indicated by R2
  78.         STR R0, [R1, #0x194]    @ Set LEDs indicated by R0
  79.         LDMFD SP!, {R0-R2, PC}  @ Restore registers, move LR to PC
  80.  
  81. @ GPIO1 base address: 0x4804C000
  82. @ GPIO1 OutputEnable offset: 0x134
  83. @ GPIO1 ClearDataOut offset: 0x190
  84. @ GPIO1 SetDataOut offset: 0x194
  85. @ For enabling all four outputs, 0x01E0 0000 will toggle bits 21-24.
  86. @ For individual toggling:
  87. @ LED0 (pin 21): 0x0020 0000
  88. @ LED1 (pin 22): 0x0040 0000
  89. @ LED2 (pin 23): 0x0080 0000
  90. @ LED3 (pin 24): 0x0100 0000       
  91.  
  92. .align 2
  93. .data
  94. LEDStatus: .word 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement