标题:
单片机数码管电子钟程序以及Proteus仿真
[打印本页]
作者:
峙毅
时间:
2022-4-9 15:48
标题:
单片机数码管电子钟程序以及Proteus仿真
写的电子钟程序,里面包含了程序文件,proteus仿真电路图,程序语言上有些不足,仅供参考。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
51hei.gif
(101 KB, 下载次数: 90)
下载附件
2022-4-9 18:07 上传
单片机源程序如下:
程序如下:
#include<reg51.h>
unsigned char dat[6]={0};
unsigned char duan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char wei[6]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
unsigned char num=0;
unsigned char s=0;
unsigned char m=0;
unsigned char h=0;
sbit button1=P3^0;
sbit button2=P3^2;
sbit button3=P3^5;
sbit button4=P3^7;
sbit bee = P1^0;
void delay()
{
unsigned int i;
for(i=0;i<100;i++);
}
void Bee()
{
bee = 1;
delay();
bee = 0;
delay();
}
void KEY_scan()
{
if(button1 == 0)
{
h++;
while(button1 == 0);
}
if(button2 == 0)
{
h--;
while(button2 == 0);
}
if(button3 == 0)
{
m++;
while(button3 == 0);
}
if(button4 == 0)
{
m--;
while(button4 == 0);
}
}
void display()
{
static unsigned char i = 0;
dat[0]=h/10;
dat[1]=h%10;
dat[2]=m/10;
dat[3]=m%10;
dat[4]=s/10;
dat[5]=s%10;
{
P2=wei[i];
P0=duan[dat[i]];
i++;
if(i>=6)
i = 0;
}
}
unsigned char dz_js(void)
{
num++;
if(num==100)
{
num=0;
s++;
if(s>=60)
{
s = 0;
m++;
}
if(m>=60)
{
m = 0;
h++;
}
if(h>=24)
h=0;
}
return(s,m,h);
}
void T1_svr() interrupt 3
{
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
dz_js();
display();
}
void main()
{
TMOD=0x10;
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
ET1 = 1;
EA = 1;
TR1 = 1;
while(1)
{
bee = 0;
KEY_scan();
if(m == 59)
Bee();
}
}
复制代码
Keil代码与Proteus仿真下载:
电子钟.7z
(60.06 KB, 下载次数: 36)
2022-4-9 15:48 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
harryjet
时间:
2023-2-15 15:58
初学者的学习好资料,收下谢谢了!
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1