Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. .text
  2. .global _start
  3. _start:
  4. LDR R8, =0xFF200000 // LEDR port address
  5. LDR R9, =0xFF200050 // KEY port address
  6. LDR R4, =0xFFFEC600 // base address of timer
  7.  
  8. MOV R1, #1 // initial on values
  9. MOV R5, #512 //initial on values
  10. MOV R2, #0 // direction values (0/1)
  11. MAIN:
  12. EOR R1,R1,R5
  13. CMP R1,#48
  14. EOREQ R2,R2,#1
  15. STR R1, [R8] // write to LED and turn on LEDR0
  16. LDR R6, [R9] // read key values
  17. CMP R6, #8 // check if KEY3 is pressed (1000)
  18. BLEQ KEYPRESS // routine to stop LEDRs
  19.  
  20. CMP R5, #512 // see if LEDR9 is up (0b10 0000 0000)
  21. MOVEQ R2, #1 // change direction variable (right)
  22.  
  23. CMP R5, #1 // if LEDR0 is up (0b1)
  24. MOVEQ R2, #0 // chagne direction variable (left)
  25.  
  26. SUB R1,R1,R5
  27. CMP R2, #0
  28. LSREQ R1, #1
  29. LSLEQ R5, #1
  30. LSLNE R1, #1
  31. LSRNE R5, #1
  32.  
  33. BL DELAY // use clock to slow down
  34. B MAIN // loop main program
  35.  
  36. // we need two routines to take care of press key
  37. WAIT: BL DELAY
  38. LDR R6, [R9] // Read Key status
  39. CMP R6, #8 // is key3 pressed
  40. BNE WAIT // if key 3 is not pressed, keep waiting
  41. MOV R3, #0 // if pressed, set R3 to 0
  42. B KEYPRESS
  43. // routine to make delay
  44. DELAY: LDR R0,=50000000 // how many clock cycles before the delay finishes
  45. STR R0, [R4] // put this in the timer base address (start value)
  46. MOV R0, #0b011 // no prescale, no interrupt, autoreload, start
  47. STR R0, [R4, #8] // put this in control register
  48. LOOP: LDR R0, [R4, #0xC] // fetch interrrupt status
  49. CMP R0, #0 // is counter done? (0 is not done)
  50. BEQ LOOP // loop until counter reports done
  51. STR R0, [R4, #0xC] // reset interrupt status to 0
  52. MOV PC, LR // finish counting, exit DELAY subroutine
  53.  
  54. KEYPRESS:
  55. LDR R6, [R9] // read from KEYs
  56. CMP R6, #0 // Keys not pressed?
  57. BNE KEYPRESS // if key is pressed, loop until its not
  58. CMP R3, #8 // the previously registered state of key press (key3 down)
  59. BEQ WAIT // if the key was pressed, go into wait
  60. BNE MAIN // if the previous state was not pressed, go back to main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement