程序猿的第一个demo,点亮一个LED
根据原理图的LED来进行设置引脚
这里我选择的是PA8
初始化LED引脚,设置为输出模式
void LED_Init(void)
{
GPIO_InitType GPIO_InitStructure;
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
GPIO_InitStruct(&GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_8;
GPIO_InitStructure.GPIO_Current = GPIO_DC_4mA;
GPIO_InitStructure.GPIO_Pull = GPIO_No_Pull;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
}
//led ctrl
void LED_Set(u8 mode)
{
if(mode)
{
GPIO_SetBits(GPIOA,GPIO_PIN_8);
}
else
{
GPIO_ResetBits(GPIOA,GPIO_PIN_8);
}
}
int main()
{
LED_Init();
while(1)
{
LED_Set(0);
Delay_MS(500);
LED_Set(1);
Delay_MS(500);
}
}
|