class done
This commit is contained in:
59
lab8adc/Src/delay.s
Normal file
59
lab8adc/Src/delay.s
Normal file
@@ -0,0 +1,59 @@
|
||||
# delay.s
|
||||
# Trevor Barnes
|
||||
# CE2801-031
|
||||
# Description: A file for handling delay routines
|
||||
|
||||
.syntax unified
|
||||
.cpu cortex-m4
|
||||
.thumb
|
||||
.section .text
|
||||
|
||||
.global msDelay
|
||||
# A subroutine to create a delay of a certain number of milliseconds
|
||||
# Input:
|
||||
# r0: Length of delay (ms)
|
||||
msDelay:
|
||||
|
||||
push {r1,r2,r3,lr}
|
||||
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,pc}
|
||||
|
||||
.global usDelay
|
||||
# about r1 mircoseonds
|
||||
usDelay:
|
||||
# stack
|
||||
push {lr}
|
||||
|
||||
lsl r1, r1, #3
|
||||
|
||||
1:
|
||||
sub r1, r1, #1
|
||||
cmp r1, #0
|
||||
bne 1b
|
||||
|
||||
# return
|
||||
pop {pc}
|
||||
|
||||
|
||||
280
lab8adc/Src/keypad.s
Normal file
280
lab8adc/Src/keypad.s
Normal file
@@ -0,0 +1,280 @@
|
||||
# keypad.s
|
||||
# Trevor Barnes
|
||||
# CE2801-031
|
||||
# Description: Contains routines for the keypad component
|
||||
|
||||
.syntax unified
|
||||
.cpu cortex-m4
|
||||
.thumb
|
||||
.section .text
|
||||
|
||||
.equ RCC_BASE, 0x40023800
|
||||
.equ RCC_AHB1ENR, 0x30
|
||||
.equ RCC_GPIOCEN, 1<<2
|
||||
|
||||
.equ GPIOC_BASE, 0x40020800
|
||||
.equ GPIO_MODER, 0x00
|
||||
.equ GPIO_ODR, 0x14
|
||||
.equ GPIO_IDR, 0x10
|
||||
.equ GPIO_PUPDR, 0x0C
|
||||
.equ GPIO_BSRR, 0x18
|
||||
|
||||
# Row 1
|
||||
.equ k1, 0xEE
|
||||
.equ k2, 0xED
|
||||
.equ k3, 0xEB
|
||||
.equ k4, 0xE7
|
||||
|
||||
# Row 2
|
||||
.equ k5, 0xDE
|
||||
.equ k6, 0xDD
|
||||
.equ k7, 0xDB
|
||||
.equ k8, 0xD7
|
||||
|
||||
# Row 3
|
||||
.equ k9, 0xBE
|
||||
.equ k10, 0xBD
|
||||
.equ k11, 0xBB
|
||||
.equ k12, 0xB7
|
||||
|
||||
# Row 4
|
||||
.equ k13, 0x7E
|
||||
.equ k14, 0x7D
|
||||
.equ k15, 0x7B
|
||||
.equ k16, 0x77
|
||||
|
||||
.global KeyInit
|
||||
# Initialize the keypad GPIO port.
|
||||
# Depending on your scanning algorithm,
|
||||
# there may not be any work to do in this method
|
||||
KeyInit:
|
||||
|
||||
push {r0,r1,r2,lr}
|
||||
|
||||
ldr r1, =RCC_BASE
|
||||
|
||||
ldr r2, [r1, #RCC_AHB1ENR]
|
||||
orr r2, r2, #RCC_GPIOCEN
|
||||
str r2, [r1, #RCC_AHB1ENR]
|
||||
|
||||
# Read current PUPDR state
|
||||
ldr r1, =GPIOC_BASE
|
||||
ldr r2, [r1, #GPIO_PUPDR]
|
||||
|
||||
# Modify and write rows and columns to be "Pull-Up"
|
||||
bfc r2, #0, #16
|
||||
ldr r0, =0x5555
|
||||
orr r2, r2, r0
|
||||
str r2, [r1, #GPIO_PUPDR]
|
||||
|
||||
pop {r0,r1,r2,pc}
|
||||
|
||||
.global KeyGetKeyNoblock
|
||||
# Returns in r0 a numeric code representing
|
||||
# the button on the keypad that was pressed (1 to 16),
|
||||
# or 0 if no button is pressed
|
||||
KeyGetKeyNoblock:
|
||||
|
||||
push {r1,r2,lr}
|
||||
|
||||
bl keypadScan
|
||||
|
||||
mov r1, #0
|
||||
|
||||
ubfx r2, r0, #4, #4
|
||||
|
||||
cmp r2, #0xF
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k1
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k2
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k3
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k4
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k5
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k6
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k7
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k8
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k9
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k10
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k11
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k12
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k13
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k14
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k15
|
||||
beq 1f
|
||||
|
||||
add r1, #1
|
||||
cmp r0, #k16
|
||||
beq 1f
|
||||
|
||||
1:
|
||||
mov r0, r1
|
||||
|
||||
pop {r1,r2,pc}
|
||||
|
||||
|
||||
.global KeyGetKey
|
||||
# Same as KeyGetkeyNoblock, but blocks – that is,
|
||||
# waits until a key is pressed and then returns the key code.
|
||||
# Per discussion in lecture, you may wish to return after said key
|
||||
# is released
|
||||
KeyGetKey:
|
||||
|
||||
push {r1,r2,r3,lr}
|
||||
mov r0, #0
|
||||
1:
|
||||
mov r1, #10
|
||||
bl usDelay
|
||||
bl KeyGetKeyNoblock
|
||||
|
||||
cmp r0, #0
|
||||
beq 1b
|
||||
2:
|
||||
# Row = Input | Col = Output
|
||||
ldr r1, =GPIOC_BASE
|
||||
ldr r2, [r1, #GPIO_MODER]
|
||||
mov r3, #0x0055
|
||||
bfi r2, r3, #0, #16
|
||||
str r2, [r1, #GPIO_MODER]
|
||||
# "0000" -> ODR (Col)
|
||||
ldrb r2, [r1, #GPIO_ODR]
|
||||
mov r3, #0x0
|
||||
bfi r2, r3, #0, #4
|
||||
strb r2, [r1, #GPIO_ODR]
|
||||
# Store input data in r3
|
||||
ldrb r3, [r1, #GPIO_IDR]
|
||||
cmp r3, #0xF0
|
||||
bne 2b
|
||||
|
||||
# Set both back to inputs, (default state)
|
||||
@ ldr r1, =GPIOC_BASE
|
||||
@ ldr r2, [r1, #GPIO_MODER]
|
||||
@ mov r3, #0x0000
|
||||
@ bfi r2, r3, #0, #16
|
||||
@ str r2, [r1, #GPIO_MODER]
|
||||
|
||||
pop {r1,r2,r3,pc}
|
||||
|
||||
|
||||
.global KeyGetChar
|
||||
# Similar to KeyGetkey, but returns the ASCII code corresponding
|
||||
# to the key press.
|
||||
# This method blocks. You should use a data structure in .rodata
|
||||
# to map keys to characters
|
||||
KeyGetChar:
|
||||
|
||||
push {r1,r2,lr}
|
||||
|
||||
bl KeyGetKey
|
||||
sub r0, #1
|
||||
mov r2, r0
|
||||
ldr r1, =keyChars
|
||||
ldrb r0, [r1, r2]
|
||||
|
||||
pop {r1,r2,pc}
|
||||
|
||||
# Waits for input on keypad and returns that value in r0
|
||||
keypadScan:
|
||||
|
||||
push {r1,r2,r3,lr}
|
||||
2:
|
||||
# Row = Input | Col = Output
|
||||
ldr r1, =GPIOC_BASE
|
||||
ldr r2, [r1, #GPIO_MODER]
|
||||
mov r0, #0x0055
|
||||
bfi r2, r0, #0, #16
|
||||
str r2, [r1, #GPIO_MODER]
|
||||
# "0000" -> ODR (Col)
|
||||
ldrb r2, [r1, #GPIO_ODR]
|
||||
mov r3, #0x0
|
||||
bfi r2, r3, #0, #4
|
||||
strb r2, [r1, #GPIO_ODR]
|
||||
# Store input data in r3
|
||||
mov r0, r1
|
||||
mov r1, #5
|
||||
bl usDelay
|
||||
mov r1, r0
|
||||
ldrb r3, [r1, #GPIO_IDR]
|
||||
# R3 = Row IDR
|
||||
#ubfx r3, r2, #4, #4
|
||||
# Row IDR -> Row ODR
|
||||
# ldrb r2, [r1, #GPIO_ODR]
|
||||
# orr r2, r2, r3
|
||||
# strb r2, [r1, #GPIO_ODR]
|
||||
# Delay
|
||||
|
||||
# Row = Output | Col = Input
|
||||
ldr r1, =GPIOC_BASE
|
||||
ldr r2, [r1, #GPIO_MODER]
|
||||
mov r0, #0x5500
|
||||
bfi r2, r0, #0, #16
|
||||
str r2, [r1, #GPIO_MODER]
|
||||
# "0000" -> ODR (Row)
|
||||
ldrb r2, [r1, #GPIO_ODR]
|
||||
mov r0, #0x0
|
||||
bfi r2, r0, #0, #4
|
||||
strb r2, [r1, #GPIO_ODR]
|
||||
mov r0, r1
|
||||
mov r1, #5
|
||||
bl usDelay
|
||||
mov r1, r0
|
||||
# Read IDR (Row & Col)
|
||||
ldrb r0, [r1, #GPIO_IDR]
|
||||
orr r0, r0, r3
|
||||
|
||||
# Set both back to inputs, (default state)
|
||||
@ ldr r1, =GPIOC_BASE
|
||||
@ ldr r2, [r1, #GPIO_MODER]
|
||||
@ mov r3, #0x0000
|
||||
@ bfi r2, r3, #0, #16
|
||||
@ str r2, [r1, #GPIO_MODER]
|
||||
1:
|
||||
pop {r1,r2,r3,pc}
|
||||
|
||||
|
||||
.section .rodata
|
||||
keyChars:
|
||||
.asciz "123A456B789C*0#D"
|
||||
476
lab8adc/Src/lcd.s
Normal file
476
lab8adc/Src/lcd.s
Normal file
@@ -0,0 +1,476 @@
|
||||
# lcd.s
|
||||
# Trevor Barnes
|
||||
# CE2801-031
|
||||
# Description: Contains routines for the LCD component
|
||||
|
||||
.syntax unified
|
||||
.cpu cortex-m4
|
||||
.thumb
|
||||
.section .text
|
||||
|
||||
#Fill in addresses
|
||||
.equ RCC_BASE, 0x40023800
|
||||
.equ RCC_AHB1ENR, 0x30
|
||||
.equ RCC_GPIOAEN, 1<<0
|
||||
.equ RCC_GPIOCEN, 1<<2
|
||||
|
||||
.equ GPIOA_BASE, 0x40020000
|
||||
.equ GPIOC_BASE, 0x40020800
|
||||
.equ GPIO_MODER, 0x00
|
||||
.equ GPIO_ODR, 0x14
|
||||
.equ GPIO_IDR, 0x10
|
||||
.equ GPIO_BSRR, 0x18
|
||||
|
||||
#What pin is each of these?
|
||||
.equ RS, 8 // PC8
|
||||
.equ RW, 9 // PC9
|
||||
.equ E, 10 // PC10
|
||||
|
||||
#Commands for BSRR
|
||||
.equ RS_SET, 1<<RS
|
||||
.equ RS_CLR, 1<<(RS+16)
|
||||
.equ RW_SET, 1<<RW
|
||||
.equ RW_CLR, 1<<(RW+16)
|
||||
.equ E_SET, 1<<E
|
||||
.equ E_CLR, 1<<(E+16)
|
||||
|
||||
#Globally exposed functions
|
||||
.global lcdInit
|
||||
|
||||
#Local helper function
|
||||
PortSetup:
|
||||
push {r1,r2,r3}
|
||||
#Turn on Ports in RCC
|
||||
ldr r1, =RCC_BASE
|
||||
|
||||
ldr r2, [r1, #RCC_AHB1ENR]
|
||||
orr r2, r2, #RCC_GPIOAEN
|
||||
str r2, [r1, #RCC_AHB1ENR]
|
||||
|
||||
ldr r2, [r1, #RCC_AHB1ENR]
|
||||
orr r2, r2, #RCC_GPIOCEN
|
||||
str r2, [r1, #RCC_AHB1ENR]
|
||||
|
||||
#Set DB Pins to Outputs
|
||||
ldr r1, =GPIOA_BASE
|
||||
ldr r2, [r1, #GPIO_MODER]
|
||||
|
||||
movw r3, 0x5500
|
||||
movt r3, 0x0055
|
||||
|
||||
orr r2,r2, r3
|
||||
|
||||
movw r3, 0xAA00
|
||||
movt r3, 0x00AA
|
||||
bic r2, r2, r3
|
||||
|
||||
str r2, [r1, #GPIO_MODER]
|
||||
|
||||
#Set RS RW E Pins to Outputs
|
||||
ldr r1, =GPIOC_BASE
|
||||
ldr r2, [r1, #GPIO_MODER]
|
||||
|
||||
movw r3, 0x0000
|
||||
movt r3, 0x0015
|
||||
|
||||
orr r2,r2, r3
|
||||
|
||||
movw r3, 0x0000
|
||||
movt r3, 0x00EA
|
||||
bic r2, r2, r3
|
||||
str r2, [r1, #GPIO_MODER]
|
||||
|
||||
pop {r1,r2,r3}
|
||||
bx lr
|
||||
|
||||
|
||||
#Writes instruction
|
||||
#RS=0 RW=0 R1-Arg
|
||||
#No returns
|
||||
WriteInstruction:
|
||||
push {r2,r3,lr}
|
||||
|
||||
#Set RS=0,RW=0,E=0
|
||||
|
||||
ldr r2, =GPIOC_BASE
|
||||
|
||||
mov r3, RS_CLR
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
mov r3, RW_CLR
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
mov r3, E_CLR
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
|
||||
#Set E=1
|
||||
mov r3, E_SET
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
|
||||
#Set R1 -> DataBus
|
||||
lsl r1, #4
|
||||
ldr r3, =GPIOA_BASE
|
||||
ldr r2, [r3, #GPIO_ODR]
|
||||
bfc r2, #4, #8
|
||||
orr r2, r2, r1
|
||||
str r2, [r3, #GPIO_ODR ]
|
||||
#Set E=0
|
||||
ldr r2, =GPIOC_BASE
|
||||
mov r3, E_CLR
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
|
||||
#Wait for appropriate delay
|
||||
mov r1, #37
|
||||
bl usDelay
|
||||
pop {r2,r3,pc}
|
||||
|
||||
|
||||
#Writes data
|
||||
#RS=0 RW=0 R1-Arg
|
||||
#No returns
|
||||
WriteData:
|
||||
push {r1,r2,r3,r4,lr}
|
||||
|
||||
#Set RS=1,RW=0,E=0
|
||||
ldr r2, =GPIOC_BASE
|
||||
|
||||
mov r3, #RS_SET
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
mov r3, #RW_CLR
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
mov r3, #E_CLR
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
#Set E=1
|
||||
mov r3, #E_SET
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
#Set R1 -> DataBus
|
||||
lsl r1, #4
|
||||
ldr r3, =GPIOA_BASE
|
||||
ldr r2, [r3, #GPIO_ODR]
|
||||
bfc r2, #4, #8
|
||||
orr r2, r2, r1
|
||||
str r2, [r3, #GPIO_ODR ]
|
||||
#Set E=0
|
||||
ldr r2, =GPIOC_BASE
|
||||
mov r3, #E_CLR
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
#Wait for appropriate delay
|
||||
mov r1, #37
|
||||
bl usDelay
|
||||
pop {r1,r2,r3,r4,pc}
|
||||
|
||||
#Code to intialize the lcd
|
||||
lcdInit:
|
||||
push {r0,r1,lr}
|
||||
|
||||
#Set up Ports
|
||||
bl PortSetup
|
||||
#Wait 40ms
|
||||
mov r0, #40
|
||||
bl msDelay
|
||||
#Write Function Set (0x38)
|
||||
mov r1, 0x38
|
||||
bl WriteInstruction
|
||||
mov r1, #37
|
||||
bl usDelay
|
||||
#Write Function Set (0x38)
|
||||
mov r1, 0x38
|
||||
bl WriteInstruction
|
||||
mov r1, #37
|
||||
bl usDelay
|
||||
#Write Display On/Off(0x0F)
|
||||
mov r1, 0x0F
|
||||
bl WriteInstruction
|
||||
mov r1, #37
|
||||
bl usDelay
|
||||
#Write Display Clear (0x01)
|
||||
mov r1, 0x01
|
||||
bl WriteInstruction
|
||||
mov r1, #2
|
||||
bl msDelay
|
||||
|
||||
#Write Entry Mode Set (0x06)
|
||||
mov r1, 0x06
|
||||
bl WriteInstruction
|
||||
|
||||
mov r1, #37
|
||||
bl usDelay
|
||||
pop {r0,r1,pc}
|
||||
|
||||
.global lcdClear
|
||||
# clears the display
|
||||
# no arguments or return
|
||||
# includes necessary delay
|
||||
lcdClear:
|
||||
push {r0,r1,lr}
|
||||
mov r1, 0x01
|
||||
bl WriteInstruction
|
||||
# Delay for at least 1.52ms
|
||||
mov r0, #2
|
||||
bl msDelay
|
||||
pop {r0,r1,pc}
|
||||
|
||||
|
||||
.global lcdHome
|
||||
# moves cursor to the home position
|
||||
# no arguments or return
|
||||
# includes necessary delay
|
||||
lcdHome:
|
||||
push {r1,lr}
|
||||
mov r1, #0x02
|
||||
bl WriteInstruction
|
||||
mov r0, #2
|
||||
bl msDelay
|
||||
pop {r1,pc}
|
||||
|
||||
.global lcdSetPosition
|
||||
# moves cursor to the position indicated
|
||||
# r0 is the zero-based row and r1 is the zero-based column, no return value
|
||||
# includes necessary delay
|
||||
lcdSetPosition:
|
||||
push {r0,r1,lr}
|
||||
# Sub values to "actual" positions
|
||||
sub r0, r0, #1
|
||||
sub r1, r1, #1
|
||||
# Shift row to actual
|
||||
lsl r0, r0, #6
|
||||
orr r0, r0, r1
|
||||
|
||||
mov r1, #0x80
|
||||
orr r1, r1, r0
|
||||
bl WriteInstruction
|
||||
pop {r0,r1,pc}
|
||||
|
||||
.global lcdPrintString
|
||||
# prints a null terminated string to the display
|
||||
# r0 contains the address of the null terminated string (usually located in .data or .rodata), returns the number of characters written to display in r0
|
||||
# includes necessary delay
|
||||
lcdPrintString:
|
||||
push {r0,r1,r2,r3,lr}
|
||||
|
||||
mov r2, #0
|
||||
loop:
|
||||
ldrb r1, [r0, r2]
|
||||
cmp r1, #0x00
|
||||
beq done
|
||||
bl WriteData
|
||||
add r2, r2, #1
|
||||
b loop
|
||||
done:
|
||||
mov r0, r1
|
||||
pop {r0,r1,r2,r3,pc}
|
||||
|
||||
.global lcdPrintNum
|
||||
# prints a (decimal) number to the display
|
||||
# the number to be printed is in r0, values of 0 to 9999 will print, anything above 9999 should print Err.
|
||||
# includes necessary delay
|
||||
lcdPrintNum:
|
||||
push {r0,r1,r2,r3,r4,lr}
|
||||
|
||||
bl num_to_ASCII
|
||||
# Store num in memory
|
||||
ldr r2, =numToPrint
|
||||
str r0, [r2]
|
||||
# Move cursor to right-most position
|
||||
mov r1, #16
|
||||
writeByte:
|
||||
mov r0, #1
|
||||
bl lcdSetPosition
|
||||
|
||||
mov r4, r0
|
||||
mov r0, #1
|
||||
bl msDelay
|
||||
mov r0, r4
|
||||
|
||||
mov r0, r1
|
||||
ldrb r1, [r2, r3]
|
||||
bl WriteData
|
||||
|
||||
mov r4, r0
|
||||
mov r0, #1
|
||||
bl msDelay
|
||||
mov r0, r4
|
||||
|
||||
add r3, r3, #1
|
||||
cmp r3, #4
|
||||
sub r1, r0, #1
|
||||
cmp r3, #4
|
||||
bne writeByte
|
||||
pop {r0,r1,r2,r3,r4,pc}
|
||||
|
||||
|
||||
.global lcdCursorLocation
|
||||
# Returns the location of the cursor on the LCD (1-32)
|
||||
# Location of cursor is returned in r0
|
||||
lcdCursorLocation:
|
||||
push {r1,lr}
|
||||
|
||||
|
||||
pop {r1,pc}
|
||||
|
||||
|
||||
|
||||
# Takes in a value from 0-9999 and converts it to ASCII
|
||||
# Input:
|
||||
# r0: Input binary value
|
||||
|
||||
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
|
||||
cmp r1, #0
|
||||
# Branch to encode section if shifted 16 times
|
||||
beq encode
|
||||
|
||||
# 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:
|
||||
|
||||
|
||||
b shift_cycle
|
||||
encode:
|
||||
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:
|
||||
# Return value in r0
|
||||
mov r0, r1
|
||||
pop {r1,r2,r3,pc}
|
||||
|
||||
|
||||
.global lcdBusyWait
|
||||
# Loops until the busy flag is 0
|
||||
lcdBusyWait:
|
||||
|
||||
push {r0,r1,r2,r3,lr}
|
||||
|
||||
ldr r1, =GPIOA_BASE
|
||||
ldr r2, [r1, #GPIO_MODER]
|
||||
|
||||
mov r3, #0
|
||||
|
||||
orr r2, r2, r3
|
||||
|
||||
movw r3, 0xFF00
|
||||
movt r3, 0x00FF
|
||||
bic r2, r2, r3
|
||||
|
||||
str r2, [r1, #GPIO_MODER]
|
||||
|
||||
#Set RS=0, RW=1, E=1
|
||||
ldr r2, =GPIOC_BASE
|
||||
|
||||
mov r3, #RS_CLR
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
mov r3, #RW_SET
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
mov r3, #E_SET
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
busy:
|
||||
#Set E=
|
||||
mov r3, #E_SET
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
#Set Databus -> R1
|
||||
ldr r3, =GPIOA_BASE
|
||||
ldr r1, [r3, #GPIO_IDR]
|
||||
#Set E=0
|
||||
ldr r2, =GPIOC_BASE
|
||||
mov r3, #E_CLR
|
||||
str r3, [r2, #GPIO_BSRR]
|
||||
|
||||
mov r2, #0x0010
|
||||
and r1, r2
|
||||
lsr r1, #4
|
||||
# Are we still busy?
|
||||
cmp r1, #1
|
||||
beq busy
|
||||
|
||||
# Return DB port to original mode
|
||||
ldr r1, =GPIOA_BASE
|
||||
ldr r2, [r1, #GPIO_MODER]
|
||||
|
||||
movw r3, 0x5500
|
||||
movt r3, 0x0055
|
||||
|
||||
orr r2,r2, r3
|
||||
|
||||
movw r3, 0xAA00
|
||||
movt r3, 0x00AA
|
||||
bic r2, r2, r3
|
||||
|
||||
str r2, [r1, #GPIO_MODER]
|
||||
|
||||
pop {r0,r1,r2,r3,pc}
|
||||
|
||||
|
||||
.section .data
|
||||
numToPrint:
|
||||
.word 0
|
||||
@@ -1,26 +1,69 @@
|
||||
.syntax unified
|
||||
.cpu cortex-m4
|
||||
.thumb
|
||||
.section
|
||||
.text
|
||||
# main.s
|
||||
# Trevor Barnes
|
||||
# CE2801-031
|
||||
.syntax unified
|
||||
.cpu cortex-m4
|
||||
.thumb
|
||||
.section .text
|
||||
|
||||
.global main
|
||||
.equ RCC_BASE, 0x40023800
|
||||
.equ RCC_AHB1ENR, 0x30
|
||||
.equ RCC_APB2ENR, 0x44
|
||||
.equ GPIOB_EN, 1<<1
|
||||
.equ ADC1_EN, 1<<8
|
||||
|
||||
.equ GPIOB_BASE, 0x40020400
|
||||
.equ GPIO_MODER, 0x00
|
||||
.equ GPIO_ODR, 0x14
|
||||
|
||||
.equ ADC1_BASE, 0x40012000
|
||||
.equ ADC_SR, 0x00
|
||||
.equ ADC_CR2, 0x08
|
||||
.equ ADC_SQR3, 0x34
|
||||
.equ ADC_DR, 0x4C
|
||||
|
||||
.global main
|
||||
main:
|
||||
|
||||
#initialize components
|
||||
bl lcdInit
|
||||
bl keyInit
|
||||
bl KeyInit
|
||||
bl timerInit
|
||||
#bl adc_init
|
||||
|
||||
#Send a single character to adjust the mode of the datalogger
|
||||
# ['1']['2']['3']['A'] |1 2 3 4 |
|
||||
# ['4']['5']['6']['B'] |5 6 7 8 |
|
||||
# ['7']['8']['9']['C'] |9 10 11 12|
|
||||
# ['*']['0']['#']['D'] |13 14 15 16|
|
||||
|
||||
|
||||
1: bl keyGetkeyNoblock
|
||||
# Enable GPIOB in RCC
|
||||
ldr r0, =RCC_BASE
|
||||
ldr r1, [r0, #RCC_AHB1ENR]
|
||||
orr r1, r1, #GPIOB_EN
|
||||
str r1, [r0, #RCC_AHB1ENR]
|
||||
|
||||
# Enable ADC1 in RCC
|
||||
ldr r1, [r0, #RCC_APB2ENR]
|
||||
orr r1, r1, #ADC1_EN
|
||||
str r1, [r0, #RCC_APB2ENR]
|
||||
|
||||
# Temperature Analog on PB0
|
||||
ldr r0, =GPIOB_BASE
|
||||
ldr r1, [r0, #GPIO_MODER]
|
||||
mov r2, #0b11
|
||||
bfi r1, r2, #0, #2
|
||||
str r1, [r0, #GPIO_MODER]
|
||||
|
||||
# Turn on ADC1
|
||||
ldr r0, =ADC1_BASE
|
||||
ldr r1, [r0, #ADC_CR2]
|
||||
orr r1, r1, #(1<<0)
|
||||
str r1, [R0, #ADC_CR2]
|
||||
|
||||
# ADC Channel 8
|
||||
ldr r1, [r0, #ADC_SQR3]
|
||||
mov r2, #8
|
||||
bfi r1, r2, #0, #5
|
||||
str r1, [r0, #ADC_SQR3]
|
||||
|
||||
mainLoop:
|
||||
|
||||
bl conversionLoop
|
||||
bl KeyGetKeyNoblock
|
||||
|
||||
# '*' Buffer on/off
|
||||
cmp r0, #13
|
||||
@@ -34,7 +77,7 @@ main:
|
||||
cmp r0, #8
|
||||
beq setBufferSize
|
||||
|
||||
# 'D' Toggle Between displaying temperatures C or F
|
||||
# 'D' Toggle Between displaying temperatures in C or F
|
||||
cmp r0, #16
|
||||
beq toggleTemp
|
||||
|
||||
@@ -47,4 +90,94 @@ main:
|
||||
beq continuousMode
|
||||
|
||||
#loop that will finish what chosen option and then ask for another instruction
|
||||
b 1b
|
||||
b mainLoop
|
||||
|
||||
conversionLoop:
|
||||
|
||||
push {r0, r1, lr}
|
||||
|
||||
ldr r0, =ADC1_BASE
|
||||
ldr r1, [r0, #ADC_CR2]
|
||||
orr r1, r1, #(1<<30)
|
||||
str r1, [r0, #ADC_CR2]
|
||||
|
||||
1:
|
||||
ldr r1, [r0, #ADC_SR]
|
||||
ands r1, r1, #(1<<1)
|
||||
beq 1b
|
||||
|
||||
pop {r0,r1, pc}
|
||||
|
||||
|
||||
buffer:
|
||||
|
||||
push {lr}
|
||||
|
||||
|
||||
|
||||
pop {pc}
|
||||
|
||||
setInterval:
|
||||
|
||||
push {lr}
|
||||
|
||||
# Prompt user for input
|
||||
|
||||
# Store value next typed value on LCD
|
||||
|
||||
# Set interval to stored value
|
||||
|
||||
pop {pc}
|
||||
|
||||
setBufferSize:
|
||||
|
||||
push {lr}
|
||||
|
||||
# Prompt user for two digit input
|
||||
|
||||
# Store the next two typed values on LCD
|
||||
|
||||
# Set buffer size to stored value
|
||||
|
||||
pop {pc}
|
||||
|
||||
toggleTemp:
|
||||
|
||||
push {lr}
|
||||
|
||||
# Alter voltage to degree calculation
|
||||
|
||||
pop {pc}
|
||||
|
||||
displayBufferedResults:
|
||||
|
||||
push {lr}
|
||||
|
||||
# Print whatever the most recent results are
|
||||
|
||||
# Scroll through all items in buffer
|
||||
|
||||
pop {pc}
|
||||
|
||||
continuousMode:
|
||||
|
||||
push {lr}
|
||||
|
||||
# Print periodic results until return button is pushed
|
||||
|
||||
pop {pc}
|
||||
|
||||
|
||||
bufferedResults:
|
||||
.asciz ""
|
||||
|
||||
intervalSet:
|
||||
.asciz "Type Sample Interval (1-9 seconds):"
|
||||
interval:
|
||||
.byte 0
|
||||
bufferSize:
|
||||
.byte 0
|
||||
.section .rodata
|
||||
|
||||
startMsg:
|
||||
.asciz "Select Mode"
|
||||
|
||||
@@ -1,31 +1,38 @@
|
||||
.syntax unified
|
||||
.cpu cortex-m4
|
||||
.thumb
|
||||
.section
|
||||
.text
|
||||
# timer.s
|
||||
# Trevor Barnes
|
||||
# CE2801-031
|
||||
.syntax unified
|
||||
.cpu cortex-m4
|
||||
.thumb
|
||||
.section .text
|
||||
|
||||
.global timerInit
|
||||
.equ CCMR_OCC1M_PWM, 0x18
|
||||
.equ CCMR_OC1PE, 1<<4
|
||||
.equ AFRL_TIM3_CH1_EN, 1<<4
|
||||
.equ AFRL_OFFSET, 0x20
|
||||
.equ CCMR_OFFSET, 0x18
|
||||
.equ TIM3_BASE, 0x24
|
||||
|
||||
.global timerInit
|
||||
timerInit:
|
||||
push {r0-r4, lr}
|
||||
#Alt func low reg for TIM3
|
||||
ldr r1, [r0, #AFRL_OFFSET]
|
||||
bic r1, #16, #4
|
||||
bfc r1, #16, #4
|
||||
orr r1, r1, #AFRL_TIM3_CH1_EN
|
||||
str r1, [r0, #AFRL_OFFSET]
|
||||
|
||||
#Enable CCMR1 for preload and set pwm
|
||||
#Allows for the modification of the pulse
|
||||
|
||||
ldr r0, =TIM3_BASE
|
||||
ldr r1, [r0, #CCMR_OFFSET]
|
||||
bfc r1, #4, #3
|
||||
mov r2, #CCMR_OCC1M_PWM
|
||||
orr r2, r2, #CCMR_OCC1PE
|
||||
orr r2, r2, #CCMR_OC1PE
|
||||
orr r1, r1, r2
|
||||
str r1, [r0, #CCMR_OFFSET]
|
||||
|
||||
#Enable CCER to for TIM3 (TIC)
|
||||
#Every 10 seconds, sample
|
||||
|
||||
|
||||
pop{r0, r4}
|
||||
|
||||
|
||||
bx lr
|
||||
|
||||
Reference in New Issue
Block a user