Search
#include "stm32f4xx.h" #define setbit(reg, bit) ((reg) |= (1U << (bit))) #define clearbit(reg, bit) ((reg) &= (~(1U << (bit)))) #define togglebit(reg, bit) ((reg) ^= (1U << (bit))) #define getbit(reg, bit) (((reg) & (1U << (bit))) >> (bit)) void initLED(void) { setbit(RCC->AHB1ENR, 0); setbit(GPIOA->MODER, 10); } void initTIM2(void) { /* * TIM2 je pripojen ke sbernici APB1, ktera bezi na 16MHz * frekvence pred TIM2 je zvojnasobena PLL */ setbit(RCC->APB1ENR, 0); /* enable Clock for TIM2 */ TIM2->PSC = ?; /* prescaler - doplnte podle potreby */ TIM2->ARR = ?; /* autoreload - doplnte podle potreby */ setbit(TIM2->CR1, 0); /* enable TIM2 */ clearbit(TIM2->SR, 0); /* status TIM2 */ } int main(void) { initLED(); initTIM2(); while(1) { /* test na UEV (update event) */ if(getbit(TIM2->SR, 0)) { togglebit(GPIOA->ODR, 5); /* vraceni status bitu na log 0 */ clearbit(TIM2->SR, 0); } } }