本帖最后由 冰封小肥牛 于 2013-1-9 21:40 编辑
此程序的思想是让六个数码管同时显示123456789这几个数字,本人决定不用定时器,但是他发现要在数字变化时加个延时函数(例如1变化为2),但是当我加在shuaxin();这个函数下时这个程序运行起来只有第六个数码管在变化,减少延时时间则都显示8;请问如何才能控制数字变换的速度但又不影响他的刷新的频率。 #include <reg52.h>
typedef unsigned char uchar;
typedef unsigned int uint;sbit ENLED1 = P1^4;
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
uchar code table[] = {0xc0,0xf9,0xa4,0xb0,0x99, //定义的数码管数组
0x92,0x82,0xf8,0x80,0x90};
uchar t = 0,i;void delay(uint xms) //延时函数
{
uint i,j;
for(i = xms;i>0;i--)
for(j = 110;j>0;j--);
}void shuaxin() //数码管的动态刷新
{
static uint j = 0;
switch(j)
{
case 0:ADDR0 = 0;ADDR1 = 0;ADDR2 = 0;j++; P0 = table[t];break;
case 1:ADDR0 = 1;ADDR1 = 0;ADDR2 = 0;j++; P0 = table[t];break;
case 2:ADDR0 = 0;ADDR1 = 1;ADDR2 = 0;j++; P0 = table[t];break;
case 3:ADDR0 = 1;ADDR1 = 1;ADDR2 = 0;j++; P0 = table[t];break;
case 4:ADDR0 = 0;ADDR1 = 0;ADDR2 = 1;j++; P0 = table[t];break;
case 5:ADDR0 = 1;ADDR1 = 0;ADDR2 = 1;j = 0; P0 = table[t];break;
default:break;
}
}void main() //主函数
{
uchar j = 0;
ENLED1 = 0;ADDR3 = 1;
while(1)
{
shuaxin();
delay(100);
if(t <10)
{
t ++;
}
else {t = 0;}
}
} |