Advertisement
Guest User

Untitled

a guest
Jul 31st, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include "stm32f1xx.h"
  2. #include "stm32f1xx_ll_bus.h"
  3. #include "stm32f1xx_ll_gpio.h"
  4.  
  5. void GPIO_config(void) {
  6. LL_GPIO_InitTypeDef GPIO_InitStruct;
  7. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC);
  8. LL_GPIO_DeInit(GPIOC);
  9.  
  10. // PC13 - LED
  11. LL_GPIO_StructInit(&GPIO_InitStruct);
  12. GPIO_InitStruct.Pin = LL_GPIO_PIN_13;
  13. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  14. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  15. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  16. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  17. LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  18. }
  19.  
  20. void TIM2_config(void) {
  21. RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
  22.  
  23. TIM2->PSC = 1000;
  24. TIM2->ARR = 1000;
  25. TIM2->DIER |= TIM_DIER_UIE;
  26.  
  27. TIM2->SR &= ~TIM_SR_UIF;
  28. TIM2->EGR |= TIM_EGR_UG;
  29.  
  30. NVIC_EnableIRQ(TIM2_IRQn);
  31. TIM2->CR1 |= TIM_CR1_CEN;
  32. }
  33.  
  34. void TIM2_IRQHandler(void) {
  35. TIM2->SR &= ~TIM_SR_UIF;
  36. if (GPIOC->ODR & GPIO_ODR_ODR13) GPIOC->BSRR |= GPIO_BSRR_BR13; else GPIOC->BSRR |= GPIO_BSRR_BS13;
  37. }
  38.  
  39. int main(void) {
  40. GPIO_config();
  41. TIM2_config();
  42.  
  43. GPIOC->BSRR |= GPIO_BSRR_BR13;
  44.  
  45. for (;;);
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement