我用t0定时器 2秒跳一次
当23的时候 变回0
0 3 6 8 18 21的时候 灯依次从全亮 到四分之一亮 然后 一半 然后全亮

这个是仿真图
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar dis[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar h,sh,gh;
uchar timer=0;
uint i,j,k;
uint a,b,c;
main(void)
{
TMOD=0x01;
ET0=1;
EA=1;
TR0=1;
h=0;
P1=0x00;
sh=h/10;
gh=h%10;
P3=0x26;
P0=dis[gh];
for(i=167;i>0;i--)
for(j=171;j>0;j--)
for(k=16;k>0;k--)
for(i=167;i>0;i--)
for(j=171;j>0;j--)
for(k=16;k>0;k--)
P3=0x06;
P3=0x16;
P0=dis[sh];
for(i=167;i>0;i--)
for(j=171;j>0;j--)
for(k=16;k>0;k--)
for(i=167;i>0;i--)
for(j=171;j>0;j--)
for(k=16;k>0;k--)
if(h==3)
{
P1=0x0f;
}
if(h==6)
{
P1=0xcf;
}
if(h==8)
{
P1=0xff;
}
if(h==18)
{
P1=0xcf;
}
if(h==21)
{
P1=0x0f;
}
if(h==0)
{
P1=0x00;
}
}
void int_T0() interrupt 1 using 0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
timer++;
if(timer==40)
{
timer=0;
h++;
}
if(h==24)
{
h=0;
}
}
当23的时候 变回0
0 3 6 8 18 21的时候 灯依次从全亮 到四分之一亮 然后 一半 然后全亮

这个是仿真图
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar dis[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar h,sh,gh;
uchar timer=0;
uint i,j,k;
uint a,b,c;
main(void)
{
TMOD=0x01;
ET0=1;
EA=1;
TR0=1;
h=0;
P1=0x00;
sh=h/10;
gh=h%10;
P3=0x26;
P0=dis[gh];
for(i=167;i>0;i--)
for(j=171;j>0;j--)
for(k=16;k>0;k--)
for(i=167;i>0;i--)
for(j=171;j>0;j--)
for(k=16;k>0;k--)
P3=0x06;
P3=0x16;
P0=dis[sh];
for(i=167;i>0;i--)
for(j=171;j>0;j--)
for(k=16;k>0;k--)
for(i=167;i>0;i--)
for(j=171;j>0;j--)
for(k=16;k>0;k--)
if(h==3)
{
P1=0x0f;
}
if(h==6)
{
P1=0xcf;
}
if(h==8)
{
P1=0xff;
}
if(h==18)
{
P1=0xcf;
}
if(h==21)
{
P1=0x0f;
}
if(h==0)
{
P1=0x00;
}
}
void int_T0() interrupt 1 using 0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
timer++;
if(timer==40)
{
timer=0;
h++;
}
if(h==24)
{
h=0;
}
}