下面是我从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--);
}
此帖出自
小平头技术问答
{
aa=0;
}
有经验的都用if(aa>=20)
{
aa=0;
}
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
void delayms(uint);
void display(uchar,uchar,uchar,uchar);
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar qian,bai,shi,ge;
uint num,num1,num2;
sbit dula=P2^0;
sbit wela=P2^1;
void main()
{
TMOD=0x11;
TH0=(65536-45872)/256;
TH0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display(qian,bai,shi,ge);
}
}
void display(uchar qian,uchar bai,uchar shi,uchar ge)
{
wela=1;
P1=0x08;
wela=0;
P1=0x00;
dula=1;
P1=~table[qian];
dula=0;
delayms(1);
wela=1;
P1=0x04;
wela=0;
P1=0x00;
dula=1;
P1=~table[bai];
dula=0;
delayms(1);
wela=1;
P1=0x02;
wela=0;
P1=0x00;
dula=1;
P1=~table[shi];
dula=0;
delayms(1);
wela=1;
P1=0x01;
wela=0;
P1=0x00;
dula=1;
P1=~table[ge];
dula=0;
delayms(1);
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void T0_time() interrupt 1
{
TH0=(65536-45872)/256;
TH0=(65536-45872)%256;
num2++;
if(num2==2)
{
num2=0;
num++;
if(num==1001)
num=0;
qian=num/1000;
bai=num/100;
shi=num%100/10;
ge=num%10;
}
}
{
TH0=(65536-45872)/256;
TH0=(65536-45872)%256;
num2++;
if(num2==2) 这里应该是 if(num2==20) 记到20是一秒
void main()
{
dingshi();
while(1);
}
一周热门 更多>