#include<reg52.h> //包含头文件,一般情况不需要改动,
//头文件包含特殊功能寄存器的定义
#define uchar unsigned char
uchar duanma[10]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f}; //共阴管
//uchar duanma [10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,}; 共阳管
uchar weima [6]={0x01,0x02,0x04,0x08,0x10,0x20};
uchar jishu1,jishu2,shi,fen,miao;
uchar xianshi [6]={0,0,0,0,0,0,};
void chushihua (void)
{
TMOD=0x01;
THO=(65536-5000)/256;
TL0=(65536-5000)%256;
AE=1;ET0=1;TR0=1;
}
/*------------------------------------------------
主函数
------------------------------------------------*/
void main (void)
{
shi=23; fen=58; mia =46;
chushihua();
while (1) //主循环
}
void shuzizhong (void)
{
THO=(65536-5000)/256;
TL0=(65536-5000)%256;
xianshi[0] = duanma[shi/10];
xianshi[1] = duanma[shi%10];
xianshi[2] = duanma[fen/10];
xianshi[3] = duanma[fen%10];
xianshi[4] = duanma[miao/10];
xianshi[5] = duanma[miao%10];
//6位数码管动态扫描
jishu1++;
if (jishu1==6) jishu1=0;
P2=weima [jishu1];
P1=xianshi [jishu1];
//时.分.秒,的逻辑关系
jishu2++;
if(jishu2==200)
{
jishu2=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
if(shi==24)
shi=0;
}
}
}
}
|