CH32V103單片機編程學習1-點亮LED(GPIO輸出)

GPIO時鐘樹:

GPIO輸入輸出模式

連接圖:

GPIO輸出初始化配置(核心板用戶LED連接在PB2):
void GPIO_LED_INIT(void)
{
? ? GPIO_InitTypeDef GPIO_InitStructure = {2};
? ? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //使能時鐘
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽輸出模式
? ? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
? ? GPIO_Init(GPIOB, &GPIO_InitStructure);
}
主程序編寫:
int main(void)
{
????Delay_Init(); //延時初始化
????GPIO_LED_INIT(); //GPIO模式初始化
? ? while(1)
? ? {
????????GPIO_WriteBit(GPIOB, GPIO_Pin_2,?Bit_SET); //GPIO輸出高
? ? ? ? Delay_Ms(250); //延時250ms
????????GPIO_WriteBit(GPIOB, GPIO_Pin_2,?Bit_RESET);?//GPIO輸出低
? ? ? ? Delay_Ms(250); //延時250ms
? ? }
}