|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar i=0;
uchar Data[]={8,8,8,8,0,0,0,0};
//===========================函数声明================================
void delay(uint Time);
void display(uchar Data[]);
//============================主函数=================================
void main()//主函数
{
//---------------------------系统初始化--------------------------
unsignedlong int count=0;
uintt=0;
while(1)//死循环
{
for(t=0;t<10;t++)
{
display(Data);
}
//-------------计数自加1--------------
Data[7]++;
if(Data[7]>9)
{
Data[7]=0;
Data[6]++;
if(Data[6]>9)
{
Data[6]=0;
Data[5]++;
if(Data[5]>9)
{
Data[5]=0;
Data[4]++;
if(Data[4]>9)
{
Data[4]=0;
}
}
}
}
}
}
void display(uchar Data[])
{
ucharcode seg[]={
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,
0xa1,0x86,0x8e,0xbf,0xff};
ucharcode Bit[]={
0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
uchari=0;//记录显在哪位上。
ucharTime=0; //延时计数。
ucharlight=255;
for(i=0;i<8;i++)//有8位数码管
{
//---------段选------------
P2=0xf9;//选择段选开关。
P0=seg[Data];//送段选码。
WR=0;//开
WR=1;//关
//---------位选------------
P2=0xf8;
P0=Bit;
WR=0;
WR=1;
//延时
Time=light;
while(Time--);
light=light/2;
//---------消影------------
P2=0xf8;
P0=0xff;
WR=0;
WR=1;
}
} |
|