2021年9月7号更新:
这里的驱动比较简单,后续的驱动放置于gitee上,可以直接下载和观看,地址为:
[链接地址](https://gitee.com/linyuehai/stm32-f103-rc-proect.git)
里面的驱动为标准库,都测试可行,附有注意事项。
、、、、、、、、、、、分割线、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
led.c
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);//ʹÄÜGPIOFʱÖÓ
//GPIOF9,F10³õʼ»¯ÉèÖÃ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;//LED0ºÍLED1¶ÔÓ¦IO¿Ú
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//ÆÕͨÊä³öģʽ
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//ÉÏÀ
GPIO_Init(GPIOF, &GPIO_InitStructure);//³õʼ»¯GPIO
}
void LED0_On(void)
{
GPIO_ResetBits(GPIOF,GPIO_Pin_9); //LED0¶ÔÓ¦Òý½ÅGPIOF.9ÀµÍ£¬ÁÁ µÈͬLED0=0;
}
void LED0_Off(void)
{
GPIO_SetBits(GPIOF,GPIO_Pin_9);
}
void LED1_On(void)
{
GPIO_ResetBits(GPIOF,GPIO_Pin_10); //LED0¶ÔÓ¦Òý½ÅGPIOF.10ÀµÍ£¬ÁÁ µÈͬLED0=0;
}
void LED1_Off(void)
{
GPIO_SetBits(GPIOF,GPIO_Pin_10);
}
beep.c
void BEEP_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed=GPIO_High_Speed;
GPIO_Init(GPIOF,&GPIO_InitStructure);
}
void BEEP_Off(void)
{
GPIO_ResetBits(GPIOF,GPIO_Pin_8);
}
void BEEP_On(void)
{
GPIO_SetBits(GPIOF,GPIO_Pin_8);
}
key.c
void KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOE,ENABLE);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;
GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOE,&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_DOWN;
GPIO_Init(GPIOA,&GPIO_InitStruct);
}
//ʹÓÃkey_upÀ´±£´æÉÏÒ»´Î°´¼ü°´ÏµÄ״̬
//Èç¹ûmodeΪ0£¬key_upµÄ¸³ÖµÎªÒ»´ÎÐԵģ¬ÓëÉÏ´ÎÎÞ¹