新手入门
- 积分
- 18
- 金钱
- 18
- 注册时间
- 2018-11-16
- 在线时间
- 7 小时
|

楼主 |
发表于 2019-1-15 15:27:29
|
显示全部楼层
我试过了,用计数的方式是可以解决了但需要把
if (GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_2) == KEY_ON)
给改掉
用着个结构给先处理下端口的取值问题
u8 Key_Scan(GPIO_TypeDef* GPIOx,u16 GPIO_Pin)
{
/*¼ì2aêÇ·ñóD°′¼ü°′Ï */
if(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin) == KEY_ON )
{
/*Ñóê±Ïû¶¶*/
Delay(50000);
if(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin) == KEY_ON )
{
/*μè′y°′¼üêí·Å */
while(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin) == KEY_ON);
return KEY_ON;
}
else
return KEY_OFF;
}
else
return KEY_OFF;
}
改为
if (Key_Scan(GPIOC,GPIO_Pin_2) == KEY_ON)
最终是这个主程序
// if (Key_Scan(GPIOC,GPIO_Pin_2) == KEY_ON)
// {
// Delay(1000000);
// status=status+1;
// }
// if(status>2)
// {
// status=0;
// }
// if (status==0)
// {
// {GPIO_SetBits(GPIOC, GPIO_Pin_1);}
// }
// if (status==1)
// {
// {GPIO_ResetBits(GPIOC, GPIO_Pin_1);}
// }
// if (status==2)
// {
// {GPIO_ResetBits(GPIOC, GPIO_Pin_1);
// Delay(1000000);
// GPIO_SetBits(GPIOC, GPIO_Pin_1);
// Delay(500000);}
// }
但现在我想把这写东西给做成一个可调用的形式
只需要把输入端口一写,然后进行计数的判断。
改成主函数如下
// if (任意端口==0)
// {
// {GPIO_SetBits(GPIOC, GPIO_Pin_1);}
// }
// if (任意端口==1)
// {
// {GPIO_ResetBits(GPIOC, GPIO_Pin_1);}
// }
// if (任意端口==2)
// {
// {GPIO_ResetBits(GPIOC, GPIO_Pin_1);
// Delay(1000000);
// GPIO_SetBits(GPIOC, GPIO_Pin_1);
// Delay(500000);}
// }
|
|