写出 stm32f103 控制 led 灯闪烁的 代码
时间: 2023-10-10 22:06:53 浏览: 69
Sure, the code for controlling an LED on the STM32F103 microcontroller would look something like this:
```
#include "stm32f103xb.h" // Include the appropriate header file for your device
int main(void)
{
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN; // Enable GPIOC clock
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; // Enable TIM3 clock
GPIOC->CRH |= GPIO_CRH_MODE13_0; // Configure PC13 as push-pull output
GPIOC->CRH &= ~GPIO_CRH_CNF13; // Configure PC13 as GPIO
TIM3->PSC = 7200; // Set prescaler to 7200
TIM3->ARR = 1000; // Set auto-reload value to 1000
TIM3->CR1 |= TIM_CR1_CEN; // Enable timer
while(1)
{
TIM3->CNT = 0; // Reset timer counter
while(TIM3->CNT < 500); // Wait for 1/2 second
GPIOC->BSRR |= GPIO_BSRR_BS13; // Turn on LED
TIM3->CNT = 0; // Reset timer counter
while(TIM3->CNT < 500); // Wait for 1/2 second
GPIOC->BSRR |= GPIO_BSRR_BR13; // Turn off LED
}
return 0;
}
```
Note that this is just sample code and you would need to modify it to fit your specific hardware setup.
阅读全文