From 0d1da7900647019cc94eb8098056085a0784892c Mon Sep 17 00:00:00 2001 From: Fabian Schieder Date: Wed, 25 Feb 2026 12:51:53 +0100 Subject: [PATCH] initial commit --- Gyrosensor.uvprojx | 10 ++--- main.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 5 deletions(-) diff --git a/Gyrosensor.uvprojx b/Gyrosensor.uvprojx index 5d4c8a7..72129b3 100644 --- a/Gyrosensor.uvprojx +++ b/Gyrosensor.uvprojx @@ -259,17 +259,17 @@ 0x0 - 0 + 1 0x0 0x0 - 0 + 1 0x0 0x0 - 0 + 1 0x0 0x0 @@ -279,7 +279,7 @@ 0x20000 - 0 + 1 0x0 0x0 @@ -322,7 +322,7 @@ 0 0 0 - 2 + 3 0 0 1 diff --git a/main.c b/main.c index 9877781..6083ebb 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,102 @@ +#include +#include + +void portConfig() +{ + RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; // Takt für Port A + RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; // Takt für Port B + + GPIOA->CRL &= 0x00000000; + GPIOA->CRL |= 0x22222222; // PA0 - PA7 Output + + GPIOB->CRL &= 0x00000000; + GPIOB->CRL |= 0x00000022; // PB0 - PB1 Output +} + +void set7Seg(uint8_t zahl) +{ + const uint8_t segmente[10] = + { + 0b00111111, // 0 + 0b00000110, // 1 + 0b01011011, // 2 + 0b01001111, // 3 + 0b01100110, // 4 + 0b01101101, // 5 + 0b01111101, // 6 + 0b00000111, // 7 + 0b01111111, // 8 + 0b01101111 // 9 + }; + + if (zahl < 10) + { + GPIOA->ODR &= 0xFFFFFF00; + GPIOA->ODR |= segmente[zahl]; + } +} + +void segEnable(uint8_t zahl) +{ + if(zahl == 1) + { + GPIOB->ODR &= 0b00000000; + GPIOB->ODR |= 0b00000001; + } + else if(zahl == 2) + { + GPIOB->ODR &= 0b00000000; + GPIOB->ODR |= 0b00000010; + } +} + +uint8_t varTo7Seg(uint8_t zahl) +{ + uint8_t einer = 0; + uint8_t zehner = 0; + + int i = 0; + + if(zahl > 99) + { + set7Seg(0); + } + else + { + einer = zahl % 10; + zehner = zahl / 10; + } + + for(i = 0; i < 51; i++) + { + segEnable(1); + set7Seg(zehner); + wait_ms(5); + segEnable(2); + set7Seg(einer); + wait_ms(5); + } + + return zahl; +} + int main(void) { + portConfig(); + + uint8_t zahl = 99; + uint16_t tick = 0; + int i = 0; + while(1) + { + for(i = 0; i < 100; i++) + { + varTo7Seg(i); + } + + wait_ms(2000); + i = 0; + } } \ No newline at end of file