当前位置:   article > 正文

汇编实现流水灯

汇编实现流水灯

1.使能时钟:

  1. @1使能GPIO的外设时钟
  2. ldr r0,=0x50000A28
  3. ldr r1,[r0]
  4. orr r1,r1,#(0x3<<4)//使能第4,5位
  5. str r1,[r0]

2.设置为输出模式

  1. @设置GPIOE10为输出模式
  2. ldr r0,=0x50006000
  3. ldr r1,[r0]
  4. bic r1,r1,#(0x3<<20)
  5. orr r1,r1,#(0x1<<20)
  6. str r1,[r0]
  7. @GPIOE8
  8. ldr r0,=0x50006000
  9. ldr r1,[r0]
  10. bic r1,r1,#(0x3<<16)
  11. orr r1,r1,#(0x1<<16)
  12. str r1,[r0]
  13. @GPIOF10
  14. ldr r0,=0x50007000
  15. ldr r1,[r0]
  16. bic r1,r1,#(0x3<<20)
  17. orr r1,r1,#(0x1<<20)
  18. str r1,[r0]

3.设置为推挽输出

  1. @设置PE10为推挽输出
  2. ldr r0,=0x50006004
  3. ldr r1,[r0]
  4. bic r1,r1,#(0x1<<10)
  5. str r1,[r0]
  6. ldr r0,=0x50007004
  7. ldr r1,[r0]
  8. bic r1,r1,#(0x1<<10)
  9. str r1,[r0]
  10. ldr r0,=0x50006004
  11. ldr r1,[r0]
  12. bic r1,r1,#(0x1<<8)
  13. str r1,[r0]

4.设置为低速输出

  1. @设置PE10为低速输出
  2. ldr r0,=0x50006008
  3. ldr r1,[r0]
  4. bic r1,r1,#(0x3<<20)
  5. str r1,[r0]
  6. ldr r0,=0x50006008
  7. ldr r1,[r0]
  8. bic r1,r1,#(0x3<<16)
  9. str r1,[r0]
  10. @GPIOF10
  11. ldr r0,=0x50007008
  12. ldr r1,[r0]
  13. bic r1,r1,#(0x3<<20)
  14. str r1,[r0]

5封装开关灯指令

  1. light1_off:
  2. ldr r0,=0x50006014
  3. ldr r1,[r0]
  4. bic r1,r1,#(0x1<<10)
  5. str r1,[r0]
  6. mov pc,lr
  7. light2_up:
  8. @点亮灯
  9. ldr r0,=0x50006014
  10. ldr r1,[r0]
  11. orr r1,r1,#(0x1<<8)
  12. str r1,[r0]
  13. mov pc,lr
  14. light2_off:
  15. ldr r0,=0x50006014
  16. ldr r1,[r0]
  17. bic r1,r1,#(0x1<<8)
  18. str r1,[r0]
  19. mov pc,lr
  20. light3_up:
  21. @点亮灯
  22. ldr r0,=0x50007014
  23. ldr r1,[r0]
  24. orr r1,r1,#(0x1<<10)
  25. str r1,[r0]
  26. mov pc,lr
  27. light3_off:
  28. ldr r0,=0x50007014
  29. ldr r1,[r0]
  30. bic r1,r1,#(0x1<<10)
  31. str r1,[r0]
  32. mov pc,lr

6封装delay

  1. delay:
  2. ldr r3,=0x10000000
  3. delay1:
  4. cmp r3,#0
  5. subne r3,r3,#1
  6. bne delay1
  7. mov pc,lr

7.功能逻辑实现

  1. bl loop
  2. loop:
  3. bl light3_off
  4. bl light1_up
  5. bl delay
  6. bl light1_off
  7. bl light2_up
  8. bl delay
  9. bl light2_off
  10. bl light3_up
  11. bl delay
  12. b loop
  13. .end

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/635811
推荐阅读
相关标签
  

闽ICP备14008679号