以下是在原来的程序上改的,你试一下看看:
#include
#include
#define uchar unsigned char //分号去掉
#define uint unsigned int //分号去掉
uchar ge,shi,bai,aa,bb,cc;
uint x,y,z;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void display(bai,shi,ge,aa,bb,cc);
void delay(z);
void main()
{
while(1)
{
display(6,5,4,3,2,1);
}
}
void display(bai,shi,ge,aa,bb,cc)
{
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
dula=1;
P0=table[aa];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(1);
dula=1;
P0=table[bb];
dula=0;
P0=0xef;
wela=1;
P0=0xef;
wela=0;
delay(1);
dula=1;
P0=table[cc];
dula=0;
P0=0xbf;
wela=1;
P0=0xdf;
wela=0;
delay(1);
}
void delay(z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
这里后边少个大括号
dula=0;
P0=0xef;
wela=1;
P0=0xef;
wela=0;
delay(1);
dula=1;
这里也不对
我给你一个程序 你可以试一试 对比一下 看看是不是比你那个程序要好一些
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar cnt;
uchar code SEG7[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code ACT[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
//uchar SEG_DATA[0]={6,5,4,3,2,1};
sbit dual=P2^6;
sbit wela=P2^7;
void Init()
{
TMOD=0x11;
TH0=0xfd;//-(1000/256);
TL0=0x18;//-(1000%256);
ET0=1;
TR0=1;
TH1=0xe3;//-(7500/256);
TL1=0xb4;//-(7500%256);
ET1=1;
TR1=1;
EA=1;
}
void main()
{
Init();
while(1)
{
}
}
void time1(void) interrupt 3
{
TH1=0xe3;//-(7500/256);
TL1=0xb4;//-(7500%256);
if(++cnt>5)cnt=0;
switch(cnt)
{
case 0:dula=1;P0=SEG7[6];dula=0;P0=0xff;wela=1;P0=ACT[cnt];wela=0;break;
case 1:dula=1;P0=SEG7[5];dula=0;P0=0xff;wela=1;P0=ACT[cnt];wela=0;break;
case 2:dula=1;P0=SEG7[4];dula=0;P0=0xff;wela=1;P0=ACT[cnt];wela=0;break;
case 3:dula=1;P0=SEG7[3];dula=0;P0=0xff;wela=1;P0=ACT[cnt];wela=0;break;
case 4:dula=1;P0=SEG7[2];dula=0;P0=0xff;wela=1;P0=ACT[cnt];wela=0;break;
case 5:dula=1;P0=SEG7[1];dula=0;P0=0xff;wela=1;P0=ACT[cnt];wela=0;break;
default:break;
}
}