Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 8.63 KB | None | 0 0
  1. #*****************************************************************************************
  2. #   Project:    switch triggered LEDs
  3. #   File:       task2.s
  4. #
  5. #   Language:   ASM
  6. #
  7. #   Hardware:   efiFREE v0.4
  8. #   Processor:  Kinetis MKL05Z32LC4
  9. #
  10. #   Author:     Mirza Haroon, Reich Jonas
  11. #   Datum:      28.03.2017
  12. #
  13. #   Version:    0.1
  14. #   History:
  15. #       31.10.2014  ML  create file
  16. #
  17. #   Status:     under development
  18. #
  19. #   Description:
  20. #       The use of key 0 toggles the red and yellow and key 3 the green and orange LED.
  21. #
  22. #   Notes:
  23. #       - default MCU speed at startup is ~ 21 MHz.
  24. #
  25. #   ToDo:
  26. #       - change the test code to match the description of the program
  27. #*****************************************************************************************
  28.  
  29.  
  30.     .section .vectortable,"a"   // vector table at begin of ROM
  31.  
  32.     .align  2
  33.     .word   0x20000C00      // initial Stack Pointer
  34.     .word   0x00002001      // initial Program Counter
  35.     .space  4
  36.     .word   _hardf+1        // hard fault
  37.  
  38.  
  39.  
  40.     .section .exhand,"ax"   // section for exception handler
  41.  
  42.     .align  1
  43.     .syntax unified
  44.     .thumb
  45. _hardf:
  46. #--- switch all LEDs off
  47.     LDR     r1, =0x400FF000     // load GPIO configuration base register
  48.     LDR     r2, =0x0F00         // load mask for all leds
  49.     LDR     r0, [r1, #0]        // get current value of GPIOA_PDOR
  50.     ORRS    r0, r0, r2          // generate new GPIOA_PDOR value
  51.     STR     r0, [r1, #0]        // switch all leds off
  52.  
  53. #--- switch some LEDs on
  54.     LDR     r1, =0x400FF000     // load GPIO configuration base register
  55.     LDR     r2, =0xFFFFFAFF     // load mask for red and green led
  56.     LDR     r0, [r1, #0]        // get current value of GPIOA_PDOR
  57.     ANDS    r0, r0, r2          // generate new GPIOA_PDOR value
  58.     STR     r0, [r1, #0]        // switch leds on
  59. .hang:
  60.     B       .hang
  61.  
  62. #----------------------------------------------------------------------------------------#
  63. .lp1:           // this label is only to nicify the line up in the .lst file
  64.     .ltorg
  65. #----------------------------------------------------------------------------------------#
  66.  
  67.  
  68.     .text                   // section .text
  69.  
  70.     .align  1
  71.     .syntax unified
  72.     .thumb
  73.     .thumb_func
  74.     .global init
  75.     .type   init, %function
  76. #----------------------------------------------------------------------------------------#
  77. init:
  78.     CPSID   i               // disable all interrupts
  79.  
  80.     MOVS    r0, #0          // initialize the GPRs
  81.     MOVS    r1, #0
  82.     MOVS    r2, #0
  83.     MOVS    r3, #0
  84.     MOVS    r4, #0
  85.     MOVS    r5, #0
  86.     MOVS    r6, #0
  87.     MOVS    r7, #0
  88.     MOV     r8, r0
  89.     MOV     r9, r0
  90.     MOV     r10, r0
  91.     MOV     r11, r0
  92.     MOV     r12, r0
  93.  
  94.  
  95. #--- disable WatchDog
  96. # SIM_COPC can only be written once after reset
  97.     LDR     r1, =0x40048100     // load address of register SIM_COPC
  98.     MOVS    r2, 0x0C            // load mask
  99.     LDR     r0, [r1, #0]        // load current value of SIM_COPC
  100.     BICS    r0, r0, r2          // apply mask
  101.     STR     r0, [r1, #0]        // disable watchdog
  102.  
  103.  
  104. #--- enable port clocking
  105. # all ports are configured at register SIM_SCGC5.
  106.     LDR     r1, =0x40048038     // load address of SIM_SCGC5
  107.     LDR     r2, =0x0600         // load mask for adjusting port clock gating (A, B)
  108.     LDR     r0, [r1, #0]        // get current value of SIM_SCGC5
  109.     ORRS    r0, r0, r2          // enable clock gating for ports
  110.     STR     r0, [r1, #0]        // apply settings
  111.  
  112.  
  113. #--- port init
  114. # LEDs:                         // to make pins GPIO:
  115.     LDR     r1, =0x40049000     // load Port A PCR base address
  116.     LDR     r2, =0x0100         // load configuration mask
  117.     STR     r2, [r1, #0x20]     // apply mask to PORTA_PCR8
  118.     STR     r2, [r1, #0x24]     // apply mask to PORTA_PCR9
  119.     STR     r2, [r1, #0x28]     // apply mask to PORTA_PCR10
  120.     STR     r2, [r1, #0x2C]     // apply mask to PORTA_PCR11
  121.  
  122.     LDR     r1, =0x400FF000     // load GPIO A configuration base register
  123.     LDR     r2, =0x0F00         // load mask for all leds
  124.     STR     r2, [r1, #0x14]     // make led pins output in GPIOA_PDDR
  125.  
  126. #--- switch all LEDs off
  127.     LDR     r1, =0x400FF000     // load GPIOA_PDOR address
  128.     LDR     r2, =0x0F00         // load mask for all leds
  129.     LDR     r0, [r1, #0]        // get current value of GPIOA_PDOR
  130.     ORRS    r0, r0, r2          // generate new GPIOA_PDOR value
  131.     STR     r0, [r1, #0]        // switch all leds off
  132.  
  133. #--- push buttons:
  134.     LDR     r1, =0x4004A000     // load Port B PCR base address
  135.     LDR     r2, =0x0103         // load configuration mask and enable Pullupresistor
  136.     STR     r2, [r1, #0x20]     // apply mask to PORTB_PCR8
  137.     STR     r2, [r1, #0x2C]     // apply mask to PORTB_PCR11
  138.     CPSIE   i                   // enable interrupts globally
  139.  
  140.  
  141.  
  142.     .align  1
  143.     .syntax unified
  144.     .thumb
  145.     .thumb_func
  146.     .global main
  147.     .type   main, %function
  148. #----------------------------------------------------------------------------------------#
  149. main:
  150.  
  151.     LDR     r3, =0x400FF050
  152.     LDR     r0, [r3, #0]
  153.     LDR     r4, =0x800          //Vergleichswert für ausgeschalteten Taster 3
  154.     ANDS    r0, r0, r4
  155.     CMP     r4, r0
  156.     BNE     Einschalten1        //Springe zum Unterprogramm, falls Taster gedrückt
  157.  
  158.     LDR     r0, [r3, #0]
  159.     LDR     r4, =0x100          //Vergleichswert für ausgeschalteten Taster 0
  160.     ANDS    r0, r0, r4
  161.     CMP     r4, r0
  162.     BNE     Einschalten2        //Springe zum Unterprogramm, falls Taster gedrückt
  163.  
  164.     B       main
  165.  
  166. Einschalten1:
  167.  
  168.     BL      delay               //10ms verzögerung (Entprellen)
  169.     LDR     r1, =0x400FF000
  170.     LDR     r5, [r1, #0]
  171.     LDR     r6, =0x300
  172.     CMP     r5, r6              //Überprüfung ob LEDs an sind
  173.     BEQ     Ausschalten1        //Falls ja, springe zum Unterprogramm um auszuschalten
  174.     LDR     r6, = 0x0
  175.     CMP     r6, r5              //Vergleiche ob alle LEDs an sind
  176.     BEQ     Ausschalten1        //Falls ja, springe zum Unterprogramm um auszuschalten
  177.  
  178.     LDR     r1, =0x400FF000
  179.     LDR     r2, =0x0C00
  180.     LDR     r5, [r1, #0]
  181.     BICS    r5, r5, r2
  182.     STR     r5, [r1, #0]        //Schalte LEDs an
  183.  
  184. Schleife1:
  185.     LDR     r3, =0x400FF050
  186.     LDR     r0, [r3, #0]        //Zustand der Taster abfragen
  187.     LDR     r4, =0x800
  188.     ANDS    r0, r0, r4
  189.     CMP     r4, r0
  190.     BNE     Schleife1          //Bleibe in Schleife1 solange Taster gedrückt wird
  191.     BL      delay              //10ms verzögerung (Entprellen)
  192.     B       main
  193.  
  194. Ausschalten1:
  195.  
  196.     LDR     r1, =0x400FF000
  197.     LDR     r2, =0x0C00
  198.     LDR     r0, [r1, #0]
  199.     ORRS    r0, r0, r2
  200.     STR     r0, [r1, #0]        //Schalte LEDs aus
  201.     B       Schleife1           //Bleibe in Schleife2 solange Taster gedrückt wird
  202.  
  203. Einschalten2:
  204.  
  205.     BL      delay               //10ms verzögerung nach drücken des Tasters (Entprellen)
  206.     LDR     r1, =0x400FF000
  207.     LDR     r3, [r1, #0]
  208.     LDR     r4, =0x0C00
  209.     CMP     r3, r4              //Überprüfung ob LEDs an sind
  210.     BEQ     Ausschalten2        //Falls ja, springe zum Unterprogramm um auszuschalten
  211.     LDR     r4, = 0x0
  212.     CMP     r4, r3              //Vergleiche ob alle LEDs an sind
  213.     BEQ     Ausschalten2        //Falls ja, springe zum Unterprogramm um auszuschalten
  214.  
  215.     LDR     r2, =0x0300
  216.     LDR     r7, [r1, #0]
  217.     BICS    r7, r7, r2
  218.     STR     r7, [r1, #0]        //Schalte LEDs an
  219.  
  220. Schleife2:
  221.     LDR     r3, =0x400FF050
  222.     LDR     r0, [r3, #0]        //Zustand der Taster abfragen
  223.     LDR     r4, =0x100
  224.     ANDS    r0, r0, r4
  225.     CMP     r4, r0
  226.     BNE     Schleife2           //Bleibe in Schleife2 solange Taster gedrückt wird
  227.     BL      delay               //10ms verzögerung (Entprellen)
  228.     B       main
  229.  
  230. Ausschalten2:
  231.  
  232.     LDR     r5, =0x400FF000
  233.     LDR     r4, =0x0300
  234.     LDR     r7, [r5, #0]
  235.     ORRS    r7, r7, r4
  236.     STR     r7, [r1, #0]        //Schalte LEDs aus
  237.     B       Schleife2
  238.  
  239.     .align  1
  240.     .syntax unified
  241.     .thumb
  242.     .thumb_func
  243.     .global delay
  244.     .type   delay, %function
  245. #----------------------------------------------------------------------------------------#
  246. delay:
  247.     MOVS    r6, #0
  248.     LDR     r7, =0xCD28             //10ms Verzögerung
  249. .L3:
  250.     ADDS    r6, r6, #1
  251.     CMP     r6, r7
  252.     BNE     .L3
  253.     BX      lr
  254.  
  255.  
  256.  
  257.     .align 1
  258.     .global stop
  259. stop:
  260.     B       stop
  261.  
  262.  
  263. #----------------------------------------------------------------------------------------#
  264. .lp2:           // this label is only to nicify the line up in the .lst file
  265.     .ltorg
  266. #----------------------------------------------------------------------------------------#
  267.  
  268.     .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement