使用N32G45x芯片点灯的示例代码
#include "N32G45x.h"int main() {
// 使能GPIO时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
// 配置GPIOA的第0号引脚为推挽输出模式
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
while(1) {
// 点亮LED
GPIO_SetBits(GPIOA, GPIO_Pin_0);
// 延时
for(int i = 0; i < 1000000; ++i);
// 熄灭LED
GPIO_ResetBits(GPIOA, GPIO_Pin_0);
// 延时
for(int i = 0; i < 1000000; ++i);
}
}
这段代码使用N32G45x芯片的GPIOA的第0号引脚(对应板上的LED)来控制点亮和熄灭。首先,代码使能了GPIOA的时钟,然后配置GPIOA的第0号引脚为推挽输出模式。接着,进入一个无限循环,在循环中交替点亮和熄灭LED,并通过延时函数实现LED闪烁效果。
页:
[1]