2019-07-15 16:35发布
zy18419 发表于 2015-7-17 20:35 不好使,只有7个LED灯亮了并且蜂鸣器一直响, 之前我也是
求大神指教 发表于 2015-7-17 21:13 #include #define uchar unsigned char #define uint unsigned int
最多设置5个标签!
#include<math.h>
#define uchar unsigned char
#define uint unsigned int
uchar code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar sec1,sec2,sec3,sec4,sec,arcsec,num;
void delay();//延时函数
void main()
{
sec=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
EA=1;
TR0=1;
while(1)
{
arcsec=abs(99-sec);
// sec1=sec/10;
// sec2=sec%10;
// sec3=arcsec/10;
// sec4=arcsec%10;
P2=0x01;
P0=dispcode[sec/10];
delay();
P2=0x02;
P0=dispcode[sec%10];
delay();
P2=0x10;
P0=dispcode[arcsec/10];
delay();
P2=0x20;
P0=dispcode[arcsec%10];
delay();
}
}
void int0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
if(num==20)
{
num=0;
sec++;
if(sec>99)sec=0;
}
}
void delay()
{
unsigned int i;
for(i=0;i<125;i++);
} 最佳答案
不至于吧 我这是共阳 注意i-o口就好了
#define uchar unsigned char
#define uint unsigned int
uchar num, num1,num2,shi,ge,count;
uint a=0xfe;
sbit wela=P2^7;
sbit dula=P2^6;
uchar code table[]=
{0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
};
void delay(uint z)
{ uint i,j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar shi,uchar ge)
{
dula=1;
P0=table[shi];
dula=0;
wela=0xfe;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
wela=0xff;
wela=1;
P0=0xfd;
wela=1;
delay(5);
}
void display(uchar shi,uchar ge);
void delay(uint z);
void main()
{ TMOD=0x11;
TH0=(65535-45872)/256;
TL0=(65535-45872)%256;
TH1=(65535-45872)/256;
TL1=(65535-45872)%256;
EA=1;
ET0=1;
ET1=1;
TR1=1;
TR0=1;
while(1)
{
display(shi,ge);
}
}
void T0_time() interrupt 1
{
TH0=(65535-45872)/256;
TL0=(65535-45872)%256;
num1++;
if(num1==20)
{num1=0;
num++;
if (num==60)
num=0;
shi=num/10;
ge=num%10; }
}
void T1_time() interrupt 3
{ TH1=(65535-45872)/256;
TL1=(65535-45872)%256;
num2++;
if(num2==20)
{
count++;
num2=0;
if(count<8) a=a>>1;
else a=a<<1;
if(count==15)
{
count=0;
a=0xfe;
}
P1=a;
}
}
注意十位,个位的显示。
这个也不好使。。算了我放弃这个程序了= =
一周热门 更多>