0% found this document useful (0 votes)
2 views

Assignment4_Michael (1)

The document is an assembly code for an embedded system that initializes a SysTick timer and controls GPIO pins to manage LED states. It cycles through turning on a red, green, and blue LED, waits for 5 seconds between each state, and finally turns on all LEDs before repeating the sequence. The code also includes a subroutine to wait for 5 seconds using the SysTick timer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment4_Michael (1)

The document is an assembly code for an embedded system that initializes a SysTick timer and controls GPIO pins to manage LED states. It cycles through turning on a red, green, and blue LED, waits for 5 seconds between each state, and finally turns on all LEDs before repeating the sequence. The code also includes a subroutine to wait for 5 seconds using the SysTick timer.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ASSIGNMENT-4

ECN-343

.data

.text

.global main

main:

// Initialize SysTick Timer

LDR R0, =0xE000E010 // Base address of SysTick

LDR R1, =0x00000000 // Load with 0 for current value

STR R1, [R0] // Clear current value

LDR R1, =50000 // Load count value for 1 second (assuming 50 MHz clock)

STR R1, [R0, #4] // Set reload value

MOV R1, #7 // Enable SysTick and interrupt

STR R1, [R0, #0] // Control register

// Initialize GPIO for LEDs

LDR R2, =0x48000000 // Base address of GPIO port (modify as needed)

LDR R3, =0x00000000 // Clear LED states

STR R3, [R2] // Set GPIO mode (configure pins as output)

loop:

// Wait for 5 seconds

BL wait_5_seconds

// Turn on RED LED

LDR R3, =0x00000001 // Set RED LED on

STR R3, [R2] // Update GPIO state

// Wait for 5 more seconds (total 10 seconds)

BL wait_5_seconds

// Turn off RED LED, turn on GREEN LED


LDR R3, =0x00000002 // Set GREEN LED on

STR R3, [R2] // Update GPIO state

// Wait for 5 more seconds (total 15 seconds)

BL wait_5_seconds

// Turn off GREEN LED, turn on BLUE LED

LDR R3, =0x00000004 // Set BLUE LED on

STR R3, [R2] // Update GPIO state

// Wait for 5 more seconds (total 20 seconds)

BL wait_5_seconds

// Turn on all LEDs

LDR R3, =0x00000007 // Set all LEDs on

STR R3, [R2] // Update GPIO state

// Wait for 5 more seconds (total 25 seconds)

BL wait_5_seconds

// Turn off all LEDs

LDR R3, =0x00000000 // Clear all LEDs

STR R3, [R2] // Update GPIO state

// Repeat the sequence

B loop

wait_5_seconds:

MOV R4, #5 // Load counter for 5 seconds

wait_loop:

// Wait for SysTick to count down

LDR R1, =0xE000E018 // Current value register

wait_check:

LDR R0, [R1] // Read current value


CMP R0, #0 // Check if the counter has reached zero

BNE wait_check // If not zero, wait

// Decrement the second counter

SUBS R4, R4, #1 // Subtract 1 from the second counter

BNE wait_loop // Repeat until 5 seconds have passed

BX LR // Return from subroutine

You might also like