作者在 2017-04-11 09:12:35 发布以下内容
#include <reg52.h> #include <reg52.h>
typedef unsigned int U16;
typedef unsigned char U8;
U8 num[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,
0x82,0xF8,0x80,0x90,0x7f,0xFF};
sbit LED3=P1^3;
sbit LED2=P1^2;
sbit LED1=P1^1;
sbit LED0=P1^0;
sbit P14=P1^4;
U8 shuma[4]={0};
void T0_Init()
{
TMOD=0x10;
TH1=0xFC;
TL1=0x18;
TR1=1;
}
void refresh()
{
U8 j,flag =0;
static U8 t=0;
for (j=3;j>1;j--)
{
flag=flag|shuma[j];
if(0==flag)
shuma[j]=11;
}
switch(t)
{
case 0:LED0=0;LED1=1;LED2=1;LED3=1;P0=num[shuma[3]];t++;break;
case 1:LED0=1;LED1=0;LED2=1;LED3=1;P0=num[shuma[2]];t++;break;
case 2:LED0=1;LED1=1;LED2=0;LED3=1;P0=num[10];t++;break;
case 3:LED0=1;LED1=1;LED2=0;LED3=1;P0=num[shuma[1]];t++;break;
case 4:LED0=1;LED1=1;LED2=1;LED3=0;P0=num[shuma[0]];t=0;break;
default:break;
}
}
void main()
{
U8 j=0;
U16 n=0,
x=0;
int sum=150;
T0_Init();
while(1)
{
if(1==TF1)
{
TF1=0;
TH1=0xFC;
TL1=0x18;
n++;
refresh();
}
if(100==n)
{
sum--;
shuma[0] =sum%10;
shuma[1] = sum/10%10;
shuma[2] =sum/100%10;
shuma[3] =sum/1000%10; n=0;
}
if(100==sum){ P14=0;}
if(50==sum){P14=1;}
if(0==sum)
sum++;
}
}
typedef unsigned int U16;
typedef unsigned char U8;
U8 num[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,
0x82,0xF8,0x80,0x90,0x7f,0xFF};
sbit LED3=P1^3;
sbit LED2=P1^2;
sbit LED1=P1^1;
sbit LED0=P1^0;
sbit P14=P1^4;
U8 shuma[4]={0};
void T0_Init()
{
TMOD=0x10;
TH1=0xFC;
TL1=0x18;
TR1=1;
}
void refresh()
{
U8 j,flag =0;
static U8 t=0;
for (j=3;j>1;j--)
{
flag=flag|shuma[j];
if(0==flag)
shuma[j]=11;
}
switch(t)
{
case 0:LED0=0;LED1=1;LED2=1;LED3=1;P0=num[shuma[3]];t++;break;
case 1:LED0=1;LED1=0;LED2=1;LED3=1;P0=num[shuma[2]];t++;break;
case 2:LED0=1;LED1=1;LED2=0;LED3=1;P0=num[10];t++;break;
case 3:LED0=1;LED1=1;LED2=0;LED3=1;P0=num[shuma[1]];t++;break;
case 4:LED0=1;LED1=1;LED2=1;LED3=0;P0=num[shuma[0]];t=0;break;
default:break;
}
}
void main()
{
U8 j=0;
U16 n=0,
x=0;
int sum=150;
T0_Init();
while(1)
{
if(1==TF1)
{
TF1=0;
TH1=0xFC;
TL1=0x18;
n++;
refresh();
}
if(100==n)
{
sum--;
shuma[0] =sum%10;
shuma[1] = sum/10%10;
shuma[2] =sum/100%10;
shuma[3] =sum/1000%10; n=0;
}
if(100==sum){ P14=0;}
if(50==sum){P14=1;}
if(0==sum)
sum++;
}
}