标题:
数字钟的proteus仿真电路及C语言程序设计
[打印本页]
作者:
随风z
时间:
2018-11-29 18:36
标题:
数字钟的proteus仿真电路及C语言程序设计
例4 数字钟的proteus仿真电路及C语言程序设计
2.png
(14.68 KB, 下载次数: 34)
下载附件
2018-11-29 18:35 上传
1.png
(30.12 KB, 下载次数: 26)
下载附件
2018-11-29 18:35 上传
单片机源程序如下:
#include <REG51.H>
#define uint unsigned int
#define uchar unsigned char
uint sec;
uint min=23;
uint hour=8;
uint tcnt;
unsigned char table[]=
{0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,
0x40,0x00};
//共阴数码管 0-9 '-'
void display(unsigned char a,unsigned char b,unsigned char c);
//显示延时 函数
void delay(unsigned int z)
{
unsigned int x;
unsigned char y;
for(x=z;x>0;x--)
for(y=200;y>0;y--);
}
void display()
{
P3=0xfe;P2=0x00;
P2=table[sec%10];
delay(3);
P3=0xfd;P2=0x00;
P2=table[sec/10];
delay(3);
P3=0xfb;P2=0x00;
P2=table[10];
delay(3);
P3=0xf7;P2=0x00;
P2=table[min%10];
delay(3);
P3=0xef;P2=0x00;
P2=table[min/10];
delay(3);
P3=0xdf;P2=0x00;
P2=table[10];
delay(3);
P3=0xbf;P2=0x00;
P2=table[hour%10];
delay(3);
P3=0x7f;P2=0x00;
P2=table[hour/10];
delay(3);
}
main()
{
TMOD=0x02; //设置模式为定时器T0的模式2 (8位自动重装计数初值的计数值)
TH0=0x06; //设置计数器初值,靠TH0存储重装的计数值X0=256-250=6
TL0=0x06;
TR0=1; //启动T0
ET0=1; //开启定时器T0中断允许
EA=1;
while(1)
{
display();
}
}
void t0(void)interrupt 1 using 0 //t0的中断程序
{
tcnt++;
if(tcnt==4000)//定时器的定时计数,4000次250us为1秒
{
tcnt=0;
sec++;
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
}
}
复制代码
所有资料51hei提供下载:
数字钟的proteus仿真电路及C语言程序设计.rar
(50.94 KB, 下载次数: 35)
2018-11-29 18:36 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
10555317823
时间:
2019-6-24 14:03
楼主的是好东西啊
作者:
zzsd
时间:
2021-4-29 18:12
怎么把初始时间设为12.00.00
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1