Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ LED Fun & Stuff
- LDR R0, =0x44e000AC @ Address of CM_PER_CPIO1_CLKCTRL
- MOV R1, #0x2 @ Enable value for GPIO1 module
- STR R1, [R0] @ Enable GPIO1 module
- LDR R1, =0x4804C000 @ GPIO1 base address
- MOV R0, #0x01E00000 @ Toggle pins 21-24 value
- STR R0, [R1, #0x190] @ Clear pins 21-24 of GPIO1
- LDR R2, [R1, #0x134] @ Read GPIO1 OE register
- BIC R2, R2, R0 @ Modify value, clearing bits 21-24
- STR R2, [R1, #0x134] @ Write back to OE reg.
- LDR R0, =LEDStatus @ Load state variable.
- LEDLoop:
- MOV R2, #0x10000000 @ Some big delay constant
- BL LEDFun @ Call LED-twiddling function
- SUBS R0, R0, #1 @ Decrement LEDStatus
- MOVEQ R0, #6 @ If LEDStatus = 0, reset to 6
- D: SUBS R2, #1 @ Decrement delay constant
- BNE D @ Wait in delay loop
- B LEDLoop @ Return to LED cycle.
- LEDFun: STMFD SP!, {R0-R2, LR} @ Store registers used
- LDR R1, =0x4804C000 @ Load GPIO1 base address. (Is this necessary?)
- MOVS R0, R0 @ Update flags
- BEQ StateZero @ If in State Zero, branch to StateZero.
- CMP R0, #6 @ If in State Six,
- BEQ StateSix @ then branch to StateSix
- CMP R0, #5 @ And so on.
- BEQ StateFive
- CMP R0, #4
- BEQ StateFour
- CMP R0, #3
- BEQ StateThree
- CMP R0, #2
- BEQ StateTwo
- CMP R0, #1
- BEQ StateOne
- @ In these State branches, R0 is loaded with the
- @ pins to be Set, and R2 with the pins to be Cleared.
- @ If R0 = 0, all pins should be Cleared, so R0 is not
- @ updated. After R0 and R2 are loaded, program branches
- @ to LEDTog, which handles clearing, setting, and exiting.
- StateZero:
- MOV R2, #0x01E00000 @ Clear all value
- B LEDTog
- StateSix:
- MOV R2, #0x00400000 @ Clear LED1 value
- MOV R0, #0x00200000 @ Set LED0 value
- B LEDTog
- StateFive:
- MOV R2, #0x00200000 @ Clear LED0 value
- MOV R0, #0x00400000 @ Set LED1 value
- B LEDTog
- StateFive:
- MOV R2, #0x00200000 @ Clear LED0 value
- MOV R0, #0x00400000 @ Set LED1 value
- B LEDTog
- StateFour:
- MOV R2, #0x00400000 @ Clear LED1 value
- MOV R0, #0x00800000 @ Set LED2 value
- B LEDTog
- StateThree:
- MOV R2, #0x00800000 @ Clear LED2 value
- MOV R0, #0x01000000 @ Set LED3 value
- B LEDTog
- StateTwo:
- MOV R2, #0x01000000 @ Clear LED3 value
- MOV R0, #0x00800000 @ Set LED2 value
- B LEDTog
- StateOne:
- MOV R2, #0x00800000 @ Clear LED2 value
- MOV R0, #0x00400000 @ Set LED1 value
- B LEDTog
- LEDTog:
- STR R2, [R1, #0x190] @ Clear LEDs indicated by R2
- STR R0, [R1, #0x194] @ Set LEDs indicated by R0
- LDMFD SP!, {R0-R2, PC} @ Restore registers, move LR to PC
- @ GPIO1 base address: 0x4804C000
- @ GPIO1 OutputEnable offset: 0x134
- @ GPIO1 ClearDataOut offset: 0x190
- @ GPIO1 SetDataOut offset: 0x194
- @ For enabling all four outputs, 0x01E0 0000 will toggle bits 21-24.
- @ For individual toggling:
- @ LED0 (pin 21): 0x0020 0000
- @ LED1 (pin 22): 0x0040 0000
- @ LED2 (pin 23): 0x0080 0000
- @ LED3 (pin 24): 0x0100 0000
- .align 2
- .data
- LEDStatus: .word 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement