//头文件
#include#define uchar unsigned char//宏定义
#define uint unsigned int
sbit key1=P3^5; //位声明
sbit key2=P3^6;
sbit key3=P3^7;
sbit fmq=P2^0;
uchar code table[]={0x3f,0x06,0x5b,//数码管显示的数值
0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,
0xbf,0x86,0xdb,//带小数点的数值
0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
void jia(); //函数声明
void jian();
uchar table_1[6]; //定义数组,数组内含有6个数值
uchar table_2[6];
uchar shi=23,fen=59,miao=50; //显示初始值
uchar shi1,fen1,miao1,shi2,fen2,miao2,shi3,fen3,miao3;//定义全局变量
uchar flag,flag1,cnt,count;//定义全局变量
void delay(uchar i) //延时函数,用于动态扫描数码管
{
uchar x,y;
for(x=i;x>0;x--)
for(y=110;y>0;y--);
}
void init() //初始化函数
{
TMOD=0X01; //工作方式1
TH0=(65536-50000)/256; //定时时间为:50ms
TL0=(65536-50000)%256;
ET0=1; //打开定时器
EA=1; //开总中断
TR0=1; //启动定时器
}
void display() //显示子函数,用于显示时间数值
{
uchar i,j;
table_1[0]=miao%10; //分离秒的各位与十位
table_1[1]=miao/10;
table_1[2]=fen%10+11; //分离分的各位与十位
table_1[3]=fen/10;
table_1[4]=shi%10+11; //分离时的各位与十位
table_1[5]=shi/10;
j=0x7f; //从秒到时的扫描
for(i=0;i<6;i++)
{
P2=j;
P0=table[table_1[i]];//显示数值
delay(10);
j=_cror_(j,1);//循环右移
}