数码管显示时间Word格式.docx
- 文档编号:7119067
- 上传时间:2023-05-07
- 格式:DOCX
- 页数:15
- 大小:16.22KB
数码管显示时间Word格式.docx
《数码管显示时间Word格式.docx》由会员分享,可在线阅读,更多相关《数码管显示时间Word格式.docx(15页珍藏版)》请在冰点文库上搜索。
#defineSecondLSA=1;
LSC=0
#defineThirdLSA=0;
LSB=1;
#defineFourthLSA=1;
#defineFifthLSA=0;
LSC=1
#defineSixthLSA=1;
#defineSeventhLSA=0;
#defineEighthLSA=1;
ucharcodeDIG_CODE[16]={
0x03f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//0、1、2、3、4、5、6、7、8、9、A、b、C、d、E、F的显示码
ucharTime=0;
ucharmiao1=0,miao2=0,fen1=0,fen2=0,shi1=0,shi2=0;
charSetmiao1=-1,Setmiao2=0,Setfen1=0,Setfen2=0,Setshi1=0,Setshi2=0;
voidTimerConfiguration();
voiddelayms(ucharx);
voidTimer();
//时间显示
voidSetingTime();
//时间设置
voidClock();
//闹铃
voidSetingClock();
//闹铃时间设置
voidSetingClockDisplay();
//闹钟设置显示
voidDelay(unsignedinti);
//蜂鸣器所用延时
main()
{
ucharNum=1;
Beep=0;
TimerConfiguration();
while
(1)
{
if(K4==0)//通过K4来选择是计时还是设置闹铃
{
delayms
(1);
if(K4==0)
{
Num++;
while(!
K4);
}
}
if(Num==2)
Num=0;
}
if(Num)
SetingClock();
else
SetingTime();
Timer();
Clock();
}
}
voidSetingTime()//时间设置
if(K1==0)
{
delayms
(1);
if(K1==0)
miao1++;
while(!
K1);
else
{
if(K2==0)
if(K2==0)
fen1++;
K2);
if(K3==0)
if(K3==0)
shi1++;
K3);
voidTimer()//时间显示
if(Time==20||Time>
20)//每秒miao1++
Time=0;
else//显示:
在第一位显示秒的个位
P0=0x00;
First;
P0=DIG_CODE[miao1];
if(miao1==10)
miao1=0;
miao2++;
else//显示秒的十位
Second;
P0=DIG_CODE[miao2];
if(miao2==6)
miao2=0;
P0=0x00;
//显示第三位的“-”
Third;
P0=0x40;
if(fen1==10)
fen1=0;
fen2++;
else//显示分的个位
Fourth;
P0=DIG_CODE[fen1];
if(fen2==6)
fen2=0;
else//分的十位
Fifth;
P0=DIG_CODE[fen2];
}
//显示第六位的“-”
Sixth;
if(shi1==10)
shi1=0;
shi2++;
else//显示时的个位
Seventh;
P0=DIG_CODE[shi1];
//P0=0x00;
if(shi2==2)
shi2=0;
else//显示时的十位
Eighth;
P0=DIG_CODE[shi2];
voidSetingClock()//闹铃时间设置
SetingClockDisplay();
//闹钟设置显示
/*************通过按键来设置闹铃时间**********/
Setmiao1++;
{
Setfen1++;
Setshi1++;
/***********时间的进位设置******************/
if(Setmiao1==10)
Setmiao1=0;
Setmiao2++;
if(Setmiao2==6)
Setmiao2=0;
Setfen1++;
if(Setfen1==10)
Setfen1=0;
Setfen2++;
}
if(Setfen2==6)
Setfen2=0;
Setshi1++;
if(Setshi1==10)
Setshi1=0;
Setshi2++;
if((Setshi2==2)&
&
(Setshi1==3))//即23时
Setshi2=0;
voidClock()//闹铃
if((Setmiao1==miao1)&
(Setmiao2==miao2)&
(Setfen1==fen1)&
(Setfen2==fen2)&
(Setshi1==shi1)&
(Setshi2==shi2))
while
(1)
Beep=1;
Delay(5);
Beep=0;
voidSetingClockDisplay()//闹钟设置显示
P0=0x00;
First;
P0=DIG_CODE[Setmiao1];
Second;
P0=DIG_CODE[Setmiao2];
Fourth;
P0=DIG_CODE[Setfen1];
Fifth;
P0=DIG_CODE[Setfen2];
Seventh;
P0=DIG_CODE[Setshi1];
Eighth;
P0=DIG_CODE[Setshi2];
voidTimerConfiguration()//中断的设置
TMOD=0x01;
//选择工作方式1
TH0=0x3C;
//设置初始值,定时50MS
TL0=0xB0;
EA=1;
//打开总中断
ET0=1;
//打开定时器0中断
TR0=1;
//启动定时器0
/*******************************************************************************
*函数名:
Timer0()
*函数功能:
定时器0中断函数
*输入:
无
*输出:
*******************************************************************************/
voidTimer0()interrupt1
//设置初始值
Time++;
voiddelayms(ucharx)//x*10毫秒
uchara,b,c;
for(c=x;
c>
0;
c--)
for(b=38;
b>
b--)
for(a=130;
a>
a--);
voidDelay(unsignedinti)//蜂鸣器用延时函数
charj;
for(i;
i>
0;
i--)
for(j=200;
j>
j--);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数码管 显示 时间
![提示](https://static.bingdoc.com/images/bang_tan.gif)