Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f1xx.h"
- #include "stm32f1xx_ll_bus.h"
- #include "stm32f1xx_ll_gpio.h"
- void GPIO_config(void) {
- LL_GPIO_InitTypeDef GPIO_InitStruct;
- LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC);
- LL_GPIO_DeInit(GPIOC);
- // PC13 - LED
- LL_GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.Pin = LL_GPIO_PIN_13;
- GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
- GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
- GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
- GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
- LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- }
- void TIM2_config(void) {
- RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
- TIM2->PSC = 1000;
- TIM2->ARR = 1000;
- TIM2->DIER |= TIM_DIER_UIE;
- TIM2->SR &= ~TIM_SR_UIF;
- TIM2->EGR |= TIM_EGR_UG;
- NVIC_EnableIRQ(TIM2_IRQn);
- TIM2->CR1 |= TIM_CR1_CEN;
- }
- void TIM2_IRQHandler(void) {
- TIM2->SR &= ~TIM_SR_UIF;
- if (GPIOC->ODR & GPIO_ODR_ODR13) GPIOC->BSRR |= GPIO_BSRR_BR13; else GPIOC->BSRR |= GPIO_BSRR_BS13;
- }
- int main(void) {
- GPIO_config();
- TIM2_config();
- GPIOC->BSRR |= GPIO_BSRR_BR13;
- for (;;);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement