标题:
基于51单片机的数字时钟仿真
[打印本页]
作者:
chen_qiuping
时间:
2017-5-14 17:50
标题:
基于51单片机的数字时钟仿真
基于51单片机的数字时钟
0.png
(29.3 KB, 下载次数: 64)
下载附件
2017-5-14 18:11 上传
0.png
(65.41 KB, 下载次数: 62)
下载附件
2017-5-14 18:11 上传
单片机源程序如下:
#include<reg51.h>
char code led_mod[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
int second,min,hour;
int setmin=0,sethour=0;
int currentmin,currenthour;
bit flag=0;
bit timeflag=1;
bit time24to12=1;
bit amorpm=0;
sbit P16=P1^6;
unsigned char status;
void delay(int time)
{
int i;
for(;time>0;time--)
for(i=0;i<250;i++);
}
int0_key() interrupt 0{
flag=1;
status=P0;
}
void sound(int n)
{
int i=0;
P16=1;
while(i<n)
{
P16=!P16;
i++;
}
}
void main()
{
int time;
IP=0x01;
IT0=1;
EX0=1;
EA=1;
second=50;
currentmin=58;
min=currentmin;
currenthour=20;
hour=currenthour;
while(1)
{
time=0;
if(second>59)
{
second=0;
currentmin++;
min++;
}
if(min>59)
{
min=0;
hour++;
}
if(hour>23)
{
hour=0;
}
if(currentmin>59)
{
currentmin=0;
sound(10);
currenthour++;
}
if(currenthour>23)
{
currenthour=0;
}
while(time<50)
{
P1=0x01;
P2=~led_mod[second/10];
delay(1);
P1=0x02;
P2=~led_mod[second%10];
delay(1);
P1=0x04;
P2=~led_mod[min/10];
delay(1);
P1=0x08;
P2=~led_mod[min%10];
delay(1);
P1=0x10;
P2=~led_mod[hour/10];
delay(1);
P1=0x20;
P2=~led_mod[hour%10];
delay(1);
time++;
}
P1=0x00;
P2=0x00;
if(!timeflag)
delay(100);
second++;
if(currentmin==setmin&¤thour==sethour)
{
sound(10);
}
if(flag)
{
switch(status){
case 0:min++;
status=0x06;
break;
case 1:hour++;
status=0x06;
break;
case 2:if(timeflag)
{
currentmin=min;
min=setmin;
currenthour=hour;
hour=sethour;
}
else
{
setmin=min;
min=currentmin;
sethour=hour;
hour=currenthour;
}
timeflag=!timeflag;
status=0x06;
break;
case 3:if(time24to12)
{
if(currenthour>12)
amorpm=0;
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
C51的数字时钟.rar
(16.92 KB, 下载次数: 70)
2017-5-14 17:49 上传
点击文件名下载附件
数字时钟
下载积分: 黑币 -5
作者:
tuling
时间:
2017-12-27 12:24
好文件!谢谢分享
作者:
55555666
时间:
2018-5-24 21:52
好文件
作者:
eccw
时间:
2018-6-7 17:47
很好,谢谢分享
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1