#include <stdint.h>
// 定义寄存器地址
#define RCC_APB2ENR *(volatile uint32_t *) 0x40021018
#define GPIOC_CRH *(volatile uint32_t *) 0x40011004
#define GPIOC_ODR *(volatile uint32_t *) 0x4001100C
// 简单的软件延时
void delay(uint32_t count)
{
while (count--)
{
__asm__ volatile("nop");
}
}
int main(void)
{
// 1. 开启 GPIOC 时钟
RCC_APB2ENR |= (1 << 4);
// 2. 配置 PC13 为推挽输出模式 (2MHz)
GPIOC_CRH &= ~(0x0F << 20); // 清除 PC13 配置位
GPIOC_CRH |= (0x02 << 20); // 设置为输出模式
while (1)
{
// 3. 翻转 PC13 的电平 (亮/灭)
GPIOC_ODR ^= (1 << 13);
// 4. 延时 (数值越大,闪烁越慢)
delay(500000);
}
}
Loading
st-nucleo-l031k6
st-nucleo-l031k6