STM32閃爍燈(2023/7/19)

1.添加Delay庫文件,新建文件夾,增加Delay的.c和.h文件

2.編寫代碼
#include "stm32f10x.h" // Device header
#include "Delay.h"
int main(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
//GPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_RESET);
//GPIO_ResetBits(GPIOC,GPIO_Pin_13);
while(1)
{
GPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_RESET);
//如果想要通過寫0、1來賦值高低電平,可以通過GPIO_WriteBit(GPIOC,GPIO_Pin_13,(BitAction)0);強(qiáng)制類型轉(zhuǎn)換
//GPIO_ResetBits(GPIOC,GPIO_Pin_13);這種寫法同樣可以達(dá)到賦值低電平的效果
Delay_ms(100);
GPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_SET);
//GPIO_WriteBit(GPIOC,GPIO_Pin_13,(BitAction)1);強(qiáng)制類型轉(zhuǎn)換
//GPIO_setBits(GPIOC,GPIO_Pin_13);
Delay_ms(100);
}
}

3.燒錄程序

浙公網(wǎng)安備 33010602011771號