; *********************************************************************** ; * * ; * Flash the LEDs on the DSLMU Microcontroller Board * ; * Second Version * ; * * ; *********************************************************************** ; ; Author: John Zaitseff ; Date: 20th June, 2003 ; Version: 1.7 ; ; This program, when run on the DSLMU Microcontroller Board, flashes the ; LEDs on and off. A high-level (pseudo-code) version of the program is: ; ; program main ; ; const ; Value1 = 0b11111111 /* Value to turn LEDs on */ ; Value2 = 0b00000000 /* Value to turn LEDs off */ ; WaitVal = 10000 /* Number of loops to wait */ ; ; address ; LED_port = 0x10000000 /* Address of the eight LEDs */ ; ; do { ; LED_port := Value1 ; delay(WaitVal) ; LED_port := Value2 ; delay(WaitVal) ; } forever ; ; function delay (integer DelayVal) ; ; while DelayVal > 0 ; DelayVal := DelayVal - 1 ; ; where Value1 is the value to turn ON all of the LEDs, Value2 is the ; value to turn OFF all of the LEDs and WaitVal is the number of loops ; to repeat whilst waiting. ; ----------------------------------------------------------------------- ; Constant values used in this program .equ LED_port, 0x10000000 ; Location of LED port .equ Value1, 0b11111111 ; Value to turn LEDs on .equ Value2, 0b00000000 ; Value to turn LEDs off .equ WaitVal, 10000 ; Number of loops to wait ; ----------------------------------------------------------------------- ; Assembly-language preamble .text ; Executable code follows _start: .global _start ; "_start" is required by the linker .global main ; "main" is our main program b main ; ----------------------------------------------------------------------- ; Start of the main program main: ; Entry to the function "main" ; Although "main" is technically a function, this particular ; function has an infinite loop and so never returns to its caller. ldr r4, =LED_port ; Load the address of the LED port ; (ie, the value of the constant ; LED_port) into register R4 main_loop: ; Start of the infinite loop ; Turn the LEDs on mov r5, #Value1 ; Load the value Value1 into R5 strb r5, [r4] ; and store this value (a byte) to ; the address in R4 (the LED port) ; Wait for the specified period of time ldr r0, =WaitVal ; Pass the parameter, WaitVal, in R0 bl delay ; Call the function "delay" ; Turn the LEDs off mov r5, #Value2 ; Load the value Value2 into R5 strb r5, [r4] ; and store this value (a byte) ; Wait again for the specified period of time ldr r0, =WaitVal ; Load the parameter into R0 bl delay ; Call the function b main_loop ; Branch back to main_loop, ie, run ; forever ; ----------------------------------------------------------------------- ; Function "delay": delay program execution by wasting time in a loop delay: ; This function expects R0 to contain the number of loops for ; which to wait. It does not return any meaningful values. The ; value in R0 is destroyed. All other registers are preserved. delay_1: subs r0, r0, #1 ; Decrement the number of loops to go bne delay_1 ; and repeat if it is not yet zero mov pc, lr ; Return to the caller ; ----------------------------------------------------------------------- .end