initial commit

This commit is contained in:
Schrom01
2022-11-11 08:00:44 +01:00
commit 4344c1c914
5 changed files with 909 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
#include <reg_stm32f4xx.h>
#include <stdint.h>
void adc_init(void)
{
// Clock configuration
RCC->APB2ENR |= 0x00000400;
RCC->APB1ENR |= 0x00000020;
// Analog pin configuration
GPIOF->MODER |= 0x00003000;
// ADC configuration
ADC3->CR1 |= 0x02000000; // Resolution
// -> 8 Bit,
// scan mode
// -> disabled
ADC3->CR2 |= 0x00000002; // Continous
// conversion
// mode ->
// enabled
// Enable ADC conversion
ADC3->CR2 |= 0x00000001; // ADC3 enable
// Select the channel to be read from
ADC3->SMPR2 |= 0x00006000; // Channel 4 sampling
// time -> 144 cycles
ADC3->SQR3 |= 0x00000004; // Channel 4 rank
// -> 1 (?)
}
uint8_t adc_get_value(void)
{
// Start the conversion
ADC3->CR2 |= 0x40000000;
// Wait till conversion is finished
while (!ADC3->SR & 0x00000002) ;
// Return the converted data
return (uint8_t)ADC3->DR & 0x000000ff;
}
+117
View File
@@ -0,0 +1,117 @@
; ------------------------------------------------------------------
; -- _____ ______ _____ -
; -- |_ _| | ____|/ ____| -
; -- | | _ __ | |__ | (___ Institute of Embedded Systems -
; -- | | | '_ \| __| \___ \ Zurich University of -
; -- _| |_| | | | |____ ____) | Applied Sciences -
; -- |_____|_| |_|______|_____/ 8401 Winterthur, Switzerland -
; ------------------------------------------------------------------
; --
; -- main.s
; --
; -- CT1 P08 "Strukturierte Codierung" mit Assembler
; --
; -- $Id: struct_code.s 3787 2016-11-17 09:41:48Z kesr $
; ------------------------------------------------------------------
;Directives
PRESERVE8
THUMB
; ------------------------------------------------------------------
; -- Address-Defines
; ------------------------------------------------------------------
; input
ADDR_DIP_SWITCH_7_0 EQU 0x60000200
ADDR_BUTTONS EQU 0x60000210
; output
ADDR_LED_31_0 EQU 0x60000100
ADDR_7_SEG_BIN_DS3_0 EQU 0x60000114
ADDR_LCD_COLOUR EQU 0x60000340
ADDR_LCD_ASCII EQU 0x60000300
ADDR_LCD_ASCII_BIT_POS EQU 0x60000302
ADDR_LCD_ASCII_2ND_LINE EQU 0x60000314
; ------------------------------------------------------------------
; -- Program-Defines
; ------------------------------------------------------------------
; value for clearing lcd
ASCII_DIGIT_CLEAR EQU 0x00000000
LCD_LAST_OFFSET EQU 0x00000028
; offset for showing the digit in the lcd
ASCII_DIGIT_OFFSET EQU 0x00000030
; lcd background colors to be written
DISPLAY_COLOUR_RED EQU 0
DISPLAY_COLOUR_GREEN EQU 2
DISPLAY_COLOUR_BLUE EQU 4
; ------------------------------------------------------------------
; -- myConstants
; ------------------------------------------------------------------
AREA myConstants, DATA, READONLY
; display defines for hex / dec
DISPLAY_BIT DCB "Bit "
DISPLAY_2_BIT DCB "2"
DISPLAY_4_BIT DCB "4"
DISPLAY_8_BIT DCB "8"
ALIGN
; ------------------------------------------------------------------
; -- myCode
; ------------------------------------------------------------------
AREA myCode, CODE, READONLY
ENTRY
; imports for calls
import adc_init
import adc_get_value
main PROC
export main
; 8 bit resolution, cont. sampling
BL adc_init
BL clear_lcd
main_loop
; STUDENTS: To be programmed
; END: To be programmed
B main_loop
clear_lcd
PUSH {R0, R1, R2}
LDR R2, =0x0
clear_lcd_loop
LDR R0, =ADDR_LCD_ASCII
ADDS R0, R0, R2 ; add index to lcd offset
LDR R1, =ASCII_DIGIT_CLEAR
STR R1, [R0]
ADDS R2, R2, #4 ; increas index by 4 (word step)
CMP R2, #LCD_LAST_OFFSET ; until index reached last lcd point
BMI clear_lcd_loop
POP {R0, R1, R2}
BX LR
write_bit_ascii
PUSH {R0, R1}
LDR R0, =ADDR_LCD_ASCII_BIT_POS
LDR R1, =DISPLAY_BIT
LDR R1, [R1]
STR R1, [R0]
POP {R0, R1}
BX LR
ENDP
ALIGN
; ------------------------------------------------------------------
; End of code
; ------------------------------------------------------------------
END