首页 > 其他分享 >Keil51单片机数码管鬼影显示问题

Keil51单片机数码管鬼影显示问题

时间:2022-11-11 21:01:12浏览次数:40  
标签:10 Keil51 单片机 LedChar break 数码管 LedBuff Sec 0xFF

Keil51单片机数码管鬼影显示问题

所为的鬼影就是程序逻辑正确,但电路逻辑有问题。就是按程序逻辑,前一个数字显示后,直接显示下一组数字,因为没清干净,导致瞬间残留;

处理的办法,就是有就显示,没有就让数码管处于关闭状态。

while(1)
{


if (cnt >= 100)
{


cnt = 0; //time length control
Sec++; //1x1000ms=1 second


switch (j)
{


case 0:
{


if (Sec>9)
{
j++;

}
else
{
LedBuff[0] = LedChar[Sec%10];  //正常显示
LedBuff[1] = 0xFF;   //关闭显示
LedBuff[2] = 0xFF;   //关闭显示
LedBuff[3] = 0xFF;   //关闭显示
LedBuff[4] = 0xFF;    //关闭显示
LedBuff[5] = 0xFF;     //关闭显示
};
};break;


case 1:
{


if (Sec>99)
{
j++;
}
else
{
LedBuff[0] = LedChar[Sec%10];
LedBuff[1] = LedChar[Sec/10%10];
LedBuff[2] = 0xFF;
LedBuff[3] = 0xFF;
LedBuff[4] = 0xFF;
LedBuff[5] = 0xFF;
};
};break;


case 2:
{


if (Sec>999)
{
j++;
}
else
{
LedBuff[0] = LedChar[Sec%10];
LedBuff[1] = LedChar[Sec/10%10];
LedBuff[2] = LedChar[Sec/100%10];
LedBuff[3] = 0xFF;
LedBuff[4] = 0xFF;
LedBuff[5] = 0xFF;
};
};break;


case 3:
{


if (Sec>9999)
{
j++;
}
else
{
LedBuff[0] = LedChar[Sec%10];
LedBuff[1] = LedChar[Sec/10%10];
LedBuff[2] = LedChar[Sec/100%10];
LedBuff[3] = LedChar[Sec/1000%10];
LedBuff[4] = 0xFF;
LedBuff[5] = 0xFF;
};
};break;


case 4:
{


if (Sec>99999)
{
j++;
}
else
{
LedBuff[0] = LedChar[Sec%10];
LedBuff[1] = LedChar[Sec/10%10];
LedBuff[2] = LedChar[Sec/100%10];
LedBuff[3] = LedChar[Sec/1000%10];
LedBuff[4] = LedChar[Sec/10000%10];
LedBuff[5] = 0xFF;
};
};break;


case 5:
{


if (Sec>999999)
{
j=0;
Sec = 0;
}
else
{
LedBuff[0] = LedChar[Sec%10];
LedBuff[1] = LedChar[Sec/10%10];
LedBuff[2] = LedChar[Sec/100%10];
LedBuff[3] = LedChar[Sec/1000%10];
LedBuff[4] = LedChar[Sec/10000%10];
LedBuff[5] = LedChar[Sec/100000%10];
};
};break;
default: break;


};


};


};

标签:10,Keil51,单片机,LedChar,break,数码管,LedBuff,Sec,0xFF
From: https://www.cnblogs.com/gucun-blog/p/16881979.html

相关文章