下面是我从0到1000计数,可是为什么我记到6就错了呢,我是哪里错了啊,我是新手水平不高的
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar aa,unmp,qian,bai,shi,ge;
void dingshi();
void dealy(uint z);
void xs(uchar qian,uchar bai,uchar shi,uchar ge);
uchar code table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,
0x07,0x7f,0x6f};
void main()
{
dingshi();
while(1)
{
if(aa==20)
{
aa=0;
unmp++;
if(unmp==1000)
unmp=0;
qian=unmp/1000;
bai=unmp/100%10;
shi=unmp/10%10;
ge=unmp%10;
}
xs(qian,bai,shi,ge);
}
}
void dingshi()
{
EA=1;
ET0=1;
TMOD=0x01;
TR0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
unmp=0;
}
void et0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
}
void xs(uchar qian,uchar bai,uchar shi,uchar ge)
{
P1=table[qian];
P0=0xf7;
dealy(5);
P1=table[bai];
P0=0xfb;
dealy(5);
P1=table[shi];
P0=0xfd;
dealy(5);
P1=table[ge];
P0=0xfe;
dealy(5);
}
void dealy(uint z)
{
uint x,y;
for(x=200;x>0;x--)
for(y=z;y>0;y--);
}
此帖出自
小平头技术问答
void xs(void)
{
switch (aa&3) {
case 0:
P1=table[qian];
P0=0xf7;
break;
case 1:
P1=table[bai];
P0=0xfb;
break;
case 2:
P1=table[shi];
P0=0xfd;
break;
case 3:
P1=table[ge];
P0=0xfe;
break;
}
}
geshibaiqian已经是全局量了没必要在当参数传一次了,aa为扫描控制变量
unsigned int unmp; //16位
while(1)
{
unmp++;
if(unmp==1000) unmp=0;
qian=(unsinged char)(unmp/1000);
bai==(unsinged char)(unmp/100%10);
shi==(unsinged char)(unmp/10%10);
ge=unmp%10;
xs();
}
这几个除比较累,不如把除法变减法
[ 本帖最后由 huo_hu 于 2012-2-4 10:51 编辑 ]一周热门 更多>