stm32 调试正常,下载运行不正常

来源:互联网 发布:卡卡软件下载 编辑:程序博客网 时间:2024/04/30 08:27

我就想实现51的双向IO口的功能,目前已经实现,结果是开漏输出加外部上拉。但中途出现了一些问题。


最先就写了如下代码

//初始化等等

while(1)

{

GPIO_SetBits(GPIOC,GPIO_Pin_5);//置高引脚

if (GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_5))//读入引脚
{
GPIO_SetBits(GPIOF,GPIO_Pin_6);//开灯
}
else
{
GPIO_ResetBits(GPIOF,GPIO_Pin_6);//关灯
}
GPIO_ResetBits(GPIOC,GPIO_Pin_5);//拉低引脚

}

下载运行,完全不行,没哪个功能可以


于是用示波器查看,电平保持不变,进行调试,怪了,每一步的功能都能实现

这下有点恼了,绞尽脑汁苦想,于是想到时间问题,改为如下代码


GPIO_SetBits(GPIOC,GPIO_Pin_5);
delay_ms(50);
if (GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_5))
{
GPIO_SetBits(GPIOF,GPIO_Pin_6);
delay_ms(50);
}
else
{
GPIO_ResetBits(GPIOF,GPIO_Pin_6);
delay_ms(50);
}
GPIO_ResetBits(GPIOC,GPIO_Pin_5);
delay_ms(50);


下载运行程序奇迹般的成功了。于是乎又一个一个删除延时,最后就是


GPIO_SetBits(GPIOC,GPIO_Pin_5);
delay_ms(50);
if (GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_5))
{
GPIO_SetBits(GPIOF,GPIO_Pin_6);
}
else
{
GPIO_ResetBits(GPIOF,GPIO_Pin_6);
}
GPIO_ResetBits(GPIOC,GPIO_Pin_5);
delay_ms(50);