Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #*****************************************************************************************
- # Project: switch triggered LEDs
- # File: task2.s
- #
- # Language: ASM
- #
- # Hardware: efiFREE v0.4
- # Processor: Kinetis MKL05Z32LC4
- #
- # Author: Mirza Haroon, Reich Jonas
- # Datum: 28.03.2017
- #
- # Version: 0.1
- # History:
- # 31.10.2014 ML create file
- #
- # Status: under development
- #
- # Description:
- # The use of key 0 toggles the red and yellow and key 3 the green and orange LED.
- #
- # Notes:
- # - default MCU speed at startup is ~ 21 MHz.
- #
- # ToDo:
- # - change the test code to match the description of the program
- #*****************************************************************************************
- .section .vectortable,"a" // vector table at begin of ROM
- .align 2
- .word 0x20000C00 // initial Stack Pointer
- .word 0x00002001 // initial Program Counter
- .space 4
- .word _hardf+1 // hard fault
- .section .exhand,"ax" // section for exception handler
- .align 1
- .syntax unified
- .thumb
- _hardf:
- #--- switch all LEDs off
- LDR r1, =0x400FF000 // load GPIO configuration base register
- LDR r2, =0x0F00 // load mask for all leds
- LDR r0, [r1, #0] // get current value of GPIOA_PDOR
- ORRS r0, r0, r2 // generate new GPIOA_PDOR value
- STR r0, [r1, #0] // switch all leds off
- #--- switch some LEDs on
- LDR r1, =0x400FF000 // load GPIO configuration base register
- LDR r2, =0xFFFFFAFF // load mask for red and green led
- LDR r0, [r1, #0] // get current value of GPIOA_PDOR
- ANDS r0, r0, r2 // generate new GPIOA_PDOR value
- STR r0, [r1, #0] // switch leds on
- .hang:
- B .hang
- #----------------------------------------------------------------------------------------#
- .lp1: // this label is only to nicify the line up in the .lst file
- .ltorg
- #----------------------------------------------------------------------------------------#
- .text // section .text
- .align 1
- .syntax unified
- .thumb
- .thumb_func
- .global init
- .type init, %function
- #----------------------------------------------------------------------------------------#
- init:
- CPSID i // disable all interrupts
- MOVS r0, #0 // initialize the GPRs
- MOVS r1, #0
- MOVS r2, #0
- MOVS r3, #0
- MOVS r4, #0
- MOVS r5, #0
- MOVS r6, #0
- MOVS r7, #0
- MOV r8, r0
- MOV r9, r0
- MOV r10, r0
- MOV r11, r0
- MOV r12, r0
- #--- disable WatchDog
- # SIM_COPC can only be written once after reset
- LDR r1, =0x40048100 // load address of register SIM_COPC
- MOVS r2, 0x0C // load mask
- LDR r0, [r1, #0] // load current value of SIM_COPC
- BICS r0, r0, r2 // apply mask
- STR r0, [r1, #0] // disable watchdog
- #--- enable port clocking
- # all ports are configured at register SIM_SCGC5.
- LDR r1, =0x40048038 // load address of SIM_SCGC5
- LDR r2, =0x0600 // load mask for adjusting port clock gating (A, B)
- LDR r0, [r1, #0] // get current value of SIM_SCGC5
- ORRS r0, r0, r2 // enable clock gating for ports
- STR r0, [r1, #0] // apply settings
- #--- port init
- # LEDs: // to make pins GPIO:
- LDR r1, =0x40049000 // load Port A PCR base address
- LDR r2, =0x0100 // load configuration mask
- STR r2, [r1, #0x20] // apply mask to PORTA_PCR8
- STR r2, [r1, #0x24] // apply mask to PORTA_PCR9
- STR r2, [r1, #0x28] // apply mask to PORTA_PCR10
- STR r2, [r1, #0x2C] // apply mask to PORTA_PCR11
- LDR r1, =0x400FF000 // load GPIO A configuration base register
- LDR r2, =0x0F00 // load mask for all leds
- STR r2, [r1, #0x14] // make led pins output in GPIOA_PDDR
- #--- switch all LEDs off
- LDR r1, =0x400FF000 // load GPIOA_PDOR address
- LDR r2, =0x0F00 // load mask for all leds
- LDR r0, [r1, #0] // get current value of GPIOA_PDOR
- ORRS r0, r0, r2 // generate new GPIOA_PDOR value
- STR r0, [r1, #0] // switch all leds off
- #--- push buttons:
- LDR r1, =0x4004A000 // load Port B PCR base address
- LDR r2, =0x0103 // load configuration mask and enable Pullupresistor
- STR r2, [r1, #0x20] // apply mask to PORTB_PCR8
- STR r2, [r1, #0x2C] // apply mask to PORTB_PCR11
- CPSIE i // enable interrupts globally
- .align 1
- .syntax unified
- .thumb
- .thumb_func
- .global main
- .type main, %function
- #----------------------------------------------------------------------------------------#
- main:
- LDR r3, =0x400FF050
- LDR r0, [r3, #0]
- LDR r4, =0x800 //Vergleichswert für ausgeschalteten Taster 3
- ANDS r0, r0, r4
- CMP r4, r0
- BNE Einschalten1 //Springe zum Unterprogramm, falls Taster gedrückt
- LDR r0, [r3, #0]
- LDR r4, =0x100 //Vergleichswert für ausgeschalteten Taster 0
- ANDS r0, r0, r4
- CMP r4, r0
- BNE Einschalten2 //Springe zum Unterprogramm, falls Taster gedrückt
- B main
- Einschalten1:
- BL delay //10ms verzögerung (Entprellen)
- LDR r1, =0x400FF000
- LDR r5, [r1, #0]
- LDR r6, =0x300
- CMP r5, r6 //Überprüfung ob LEDs an sind
- BEQ Ausschalten1 //Falls ja, springe zum Unterprogramm um auszuschalten
- LDR r6, = 0x0
- CMP r6, r5 //Vergleiche ob alle LEDs an sind
- BEQ Ausschalten1 //Falls ja, springe zum Unterprogramm um auszuschalten
- LDR r1, =0x400FF000
- LDR r2, =0x0C00
- LDR r5, [r1, #0]
- BICS r5, r5, r2
- STR r5, [r1, #0] //Schalte LEDs an
- Schleife1:
- LDR r3, =0x400FF050
- LDR r0, [r3, #0] //Zustand der Taster abfragen
- LDR r4, =0x800
- ANDS r0, r0, r4
- CMP r4, r0
- BNE Schleife1 //Bleibe in Schleife1 solange Taster gedrückt wird
- BL delay //10ms verzögerung (Entprellen)
- B main
- Ausschalten1:
- LDR r1, =0x400FF000
- LDR r2, =0x0C00
- LDR r0, [r1, #0]
- ORRS r0, r0, r2
- STR r0, [r1, #0] //Schalte LEDs aus
- B Schleife1 //Bleibe in Schleife2 solange Taster gedrückt wird
- Einschalten2:
- BL delay //10ms verzögerung nach drücken des Tasters (Entprellen)
- LDR r1, =0x400FF000
- LDR r3, [r1, #0]
- LDR r4, =0x0C00
- CMP r3, r4 //Überprüfung ob LEDs an sind
- BEQ Ausschalten2 //Falls ja, springe zum Unterprogramm um auszuschalten
- LDR r4, = 0x0
- CMP r4, r3 //Vergleiche ob alle LEDs an sind
- BEQ Ausschalten2 //Falls ja, springe zum Unterprogramm um auszuschalten
- LDR r2, =0x0300
- LDR r7, [r1, #0]
- BICS r7, r7, r2
- STR r7, [r1, #0] //Schalte LEDs an
- Schleife2:
- LDR r3, =0x400FF050
- LDR r0, [r3, #0] //Zustand der Taster abfragen
- LDR r4, =0x100
- ANDS r0, r0, r4
- CMP r4, r0
- BNE Schleife2 //Bleibe in Schleife2 solange Taster gedrückt wird
- BL delay //10ms verzögerung (Entprellen)
- B main
- Ausschalten2:
- LDR r5, =0x400FF000
- LDR r4, =0x0300
- LDR r7, [r5, #0]
- ORRS r7, r7, r4
- STR r7, [r1, #0] //Schalte LEDs aus
- B Schleife2
- .align 1
- .syntax unified
- .thumb
- .thumb_func
- .global delay
- .type delay, %function
- #----------------------------------------------------------------------------------------#
- delay:
- MOVS r6, #0
- LDR r7, =0xCD28 //10ms Verzögerung
- .L3:
- ADDS r6, r6, #1
- CMP r6, r7
- BNE .L3
- BX lr
- .align 1
- .global stop
- stop:
- B stop
- #----------------------------------------------------------------------------------------#
- .lp2: // this label is only to nicify the line up in the .lst file
- .ltorg
- #----------------------------------------------------------------------------------------#
- .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement