working demo

This commit is contained in:
Trevor Barnes
2019-10-08 16:47:05 -05:00
parent c5042a621f
commit cbe00ffd95
14 changed files with 3667 additions and 1873 deletions

View File

@@ -0,0 +1,38 @@
# delay.s
# Trevor Barnes
# CE2801-031
# Description: A file for handling delay routines
.global delay_ms
# A subroutine to create a delay of a certain number of milliseconds
# Input:
# r0: Length of delay (ms)
delay_ms:
push {r1,r2,r3}
mov r3,r0
ms_delay:
# 250 iterations = 1/16 of a millisecond
mov r2, #0x10
# Loop 16 times
1:
# 250
mov r1, #0xFA
# Loop 250 times
2:
sub r1, #1
cmp r1, #0
bne 2b
sub r2, #1
cmp r2, #0
bne 1b
sub r0, #1
cmp r0, #0
bne ms_delay
mov r0,r3
pop {r1,r2,r3}
bx lr

View File

@@ -23,3 +23,104 @@
.equ GPIO_MODER, 0x00
# GPIO Output Data Register
.equ GPIO_ODR, 0x14
.global num_to_LED_init
# Initializes the GPIO port pins to be outputs
num_to_LED_init:
# Store registers before use
push {r1,r2,r3}
ldr r1, =RCC_BASE
# Read, Modify, Write
ldr r2, [r1, #RCC_AHB1ENR]
orr r2, r2, #RCC_GPIOBEN
str r2, [r1, #RCC_AHB1ENR]
# Enable PB5-PB10, PB12-PB15 to be outputs
ldr r1, =GPIOB_BASE
ldr r2, [r1, #GPIO_MODER]
movw r3, #0x5400
movt r3, #0x5515
orr r2, r2, r3
movw r3, #0xA800
movt r3, #0xAA2A
bic r2, r2, r3
str r2, [r1, #GPIO_MODER]
# Return the original register values
pop {r1,r2,r3}
# Branch back to link location
bx lr
.global LED_test_loop
LED_test_loop:
push {r0,r1,r2,lr}
bl num_to_LED_init
ldr r1, =GPIOB_BASE
loop:
ldr r2,[r1,#GPIO_ODR]
orr r2,r2,#0x0020
str r2,[r1,#GPIO_ODR]
mov r0, #0x3E8
bl delay_ms
ldr r2,[r1,#GPIO_ODR]
bic r2,r2,#0x0020
str r2,[r1,#GPIO_ODR]
mov r0, #0x3E8
bl delay_ms
b loop
pop {r0,r1,r2,pc}
.global num_to_LED
# Takes in a 10-bit value and displays it on the LEDs in binary
# Input:
# r0: Input binary value
num_to_LED:
push {r1,r2,lr}
bl num_to_LED_init
# Extract "pre-PB11" bit field
ubfx r1, r0, #0, #6
# extract "post-PB11" bit field
ubfx r2, r2, #6, #4
# Clear input register
mov r0, #0
# Insert bit field PB5-PB10
bfi r0, r1, #5, #6
# Insert bit field PB12-PB15
bfi r0, r2, #12, #4
# Clear register values before use
mov r1, #0
mov r2, #0
ldr r1, =GPIOB_BASE
ldr r2,[r1,#GPIO_ODR]
bfc r2,#0,#16
str r2,[r1,#GPIO_ODR]
ldr r2,[r1,#GPIO_ODR]
orr r2,r2,r0
str r2,[r1,#GPIO_ODR]
pop {r1,r2,pc}
bx lr

View File

@@ -12,4 +12,136 @@
.global main
main:
mov r0, #0
mov r1, #0
mov r2, #0
main_loop:
mov r0, #1234
bl num_to_ASCII
mov r1, r0
# r1 is 4 character ASCII value
mov r0, #500
# Display 1
ubfx r0, r1, #24, #8
bl num_to_LED
mov r0, #500
bl delay_ms
# Display 2
ubfx r0, r1, #16, #8
bl num_to_LED
mov r0, #500
bl delay_ms
# Display 3
ubfx r0, r1, #8, #8
bl num_to_LED
mov r0, #500
bl delay_ms
# Display 4
ubfx r0, r1, #0, #8
bl num_to_LED
mov r0, #500
bl delay_ms
b main_loop
end:
b end
.global num_to_ASCII
# Takes in a value from 0-9999 and converts it to ASCII
# Input:
# r0: Input binary value
# Output:
# r1: Output 4 ASCII characters
num_to_ASCII:
# If outside of range, return ASCII "Err."
push {r1,r2,r3,lr}
cmp r0,#0
blt out_of_range
@ cmp r0,#9999
@ bgt out_of_range
# Normal conversion behavior
mov r1, #16
lsl r0, #3
sub r1, #3
shift_cycle:
lsl r0, #1
sub r1, #1
# Verify Each Nibble is less than or equal to 4
ubfx r2, r0, #16, #4
# If value is less than or equal to 4, then skip to next nibble
cmp r2, #4
ble 2f
add r2, #3
bfi r0, r2, #16, #4
2: ubfx r2, r0, #20, #4
# If value is less than or equal to 4, then skip to next nibble
cmp r2, #4
ble 3f
add r2, #3
bfi r0, r2, #20, #4
3: ubfx r2, r0, #24, #4
# If value is less than or equal to 4, then skip to next nibble
cmp r2, #4
ble 4f
add r2, #3
bfi r0, r2, #24, #4
4: ubfx r2, r0, #28, #4
# If value is less than or equal to 4 skip to end
cmp r2, #4
ble end_verify_nibbles
add r2, #3
bfi r0, r2, #28, #4
end_verify_nibbles:
# If value hasn't been shifted 16 times, shift again
cmp r1, #0
bne shift_cycle
mov r3, #3
# Encode BCD numbers to ASCII
# Extract ones nibble
ubfx r2, r0, #16, #4
# Insert ones nibble
bfi r1, r2, #0, #4
# Insert 3 in front of nibble for ASCII encoding
bfi r1, r3, #4, #4
# Extract tens nibble
ubfx r2, r0, #20, #4
# Insert tens nibble
bfi r1, r2, #8, #4
# Insert 3 in front of nibble for ASCII encoding
bfi r1, r3, #12, #4
# Extract hundreds nibble
ubfx r2, r0, #24, #4
# Insert hundreds nibble
bfi r1, r2, #16, #4
# Insert 3 in front of nibble for ASCII encoding
bfi r1, r3, #20, #4
# Extract thousands nibble
ubfx r2, r0, #28, #4
# Insert thousands nibble
bfi r1, r2, #24, #4
# Insert 3 in front of nibble for ASCII encoding
bfi r1, r3, #28, #4
b end_ASCII
out_of_range:
# Insert ASCII "Err."
movw r1, #0x722E
movt r1, #0x4572
end_ASCII:
mov r0, r1
pop {r1,r2,r3,lr}
bx lr