嵌入式:STM32F407驱动重写

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µÄ¸³ÖµÎªÒ»´ÎÐԵģ¬ÓëÉÏ´ÎÎÞ¹
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值