#include<regx52.h>
#include"BUZZER.h"
#include"Key.h"
#include"Delay.h"
void _yuanze();
void _shu_ma_guan();
//自定义时间初始量
#define S 13
#define F 57
#define M 58
#define N 2 //闹钟响铃时长
sbit duan=P2^0; //段选
sbit wei=P2^1; //位选
sbit K1=P2^3; //按键1 小时自增
sbit K2=P2^4; //按键2 分钟自增
sbit K3=P2^5; //按键3 秒自增
sbit K4=P2^6; //按键4 时间暂停
sbit BUZZER=P2^7;
sbit K5=P3^2; //按键5显示 闹钟/时间
//段选的断码数码管显示的数字 0 1 2 3 4 5 6 7 8 9
unsigned duan_[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned gong_neng[]={0xff,0xfe,0xfd,0xfb};
unsigned int miao=M,fen=F,shi=S,Keynum;
unsigned int a=0,x,y;
//闹钟提示音
void nao_z()
{
if(shi==x && fen==y && miao<=N)
{
BUZZER=1;
BUZZER=0;
}
else
BUZZER=1;
}
//按键控制 自增函数
void yuanze()
{
Keynum=Key(); //接引按键扫描模块“Key.c”函数的返回值Keynumber
//通过分支语句对不同按键对 秒K1, 分K2, 时K3, 启动计时器K1, 关闭计时器K4 实行调节
switch(Keynum)
{
case 3:miao++;Keynum=0;if (miao>=60) miao=0;break ;
case 2:fen++;Keynum=0;if (fen>=60) fen=0;break;
case 1:shi++;Keynum=0;if (shi>=24) shi=0;break;
case 4:Keynum=0;TR0=~TR0;break; //按键K4,停止定时器,启动定时器
}
}
//按键控制自减函数
void yuanze1()
{
Keynum=Key(); //接引按键扫描模块“Key.c”函数的返回值Keynumber
//通过分支语句对不同按键对 秒K1, 分K2, 时K3, 启动计时器K1, 关闭计时器K4 实行调节
switch(Keynum)
{
case 3:miao--;Keynum=0;if (miao<=0) miao=59;break ;
case 2:fen--;Keynum=0;if (fen<=0) fen=59;break;
case 1:shi--;Keynum=0;if (shi<=0) shi=23;break;
case 4:TR0=~TR0;break; //按键K4,停止定时器,启动定时器
}
}
unsigned int shi_=S,fen_=F-3,miao_,Keynum_;
//数码管,显示。
void shu_ma_guan()
{
//位选读入数据/第一个数码管/锁存数据 /段选读入数据/小时的十位/锁存数据/防止篡位 /消影
wei=1;P0=0xfe;wei=0; duan=1;if(a==3)P0=duan_[shi_/10];else P0=duan_[shi/10];duan=0;Delay(1);P0=0xff;
//小时的个位
wei=1;P0=0xfd;wei=0; duan=1;if(a==3)P0=duan_[shi_%10];else P0=duan_[shi%10];duan=0;Delay(1);P0=0xff;
//分隔符
wei=1;P0=0xfb;wei=0; duan=1;P0=0x40;duan=0;Delay(1);P0=0xff;
//分的十位
wei=1;P0=0xf7;wei=0; duan=1;if(a==3)P0=duan_[fen_/10];else P0=duan_[fen/10];duan=0;Delay(1);P0=0xff;
//分的个位
wei=1;P0=0xef;wei=0; duan=1;if(a==3)P0=duan_[fen_%10];else P0=duan_[fen%10];duan=0;Delay(1);P0=0xff;
//分隔符
wei=1;P0=0xdf;wei=0; duan=1;P0=0x40;duan=0;Delay(1);P0=0xff;
//秒的十位
wei=1;P0=0xbf;wei=0; duan=1;if(a==3)P0=duan_[miao_/10];else P0=duan_[miao/10];duan=0;Delay(1);P0=0xff;
//秒的个位
wei=1;P0=0x7f;wei=0; duan=1;if(a==3)P0=duan_[miao_%10];else P0=duan_[miao%10];duan=0;Delay(1);P0=0xff;
}
void main()
{
TMOD=0x01; //选择定时器工作模式T0 0000 0001
TH0=(65535-50000)/256; //高位寄存器== TH0=15535/256;//65535-50000=50000us=50ms
TL0=(65535-50000)%256; //低位寄存器== TL0=15535%256;
//中断系统
EA=1; //总中断开关
ET0=1; //中断允许控制位 计数器T0溢出中断允许控制位
TF0=0; //中断请求位
//外部中断
EX0=1;
IT0=1;
while(1)
{
nao_z();
if(a==1){yuanze();shu_ma_guan();} //按键控制自增模式
if(a==2){yuanze1();shu_ma_guan();} //按键控制自减函数
if(a==3){_yuanze();shu_ma_guan();} //按键闹钟定时模式
}
}
//中断服务子程序 定时器0
void Timer1_Routine() interrupt 1
{
static unsigned int n;//静态储存
//进行中断重新赋值,下次运行也为1ms
TR0=1;
TH0=(65535-50000)/256; //高位寄存器
TL0=(65535-50000)%256; //低位寄存器
n++;
if(n>=20) //每隔一秒运行
{
n=0;
miao++; //秒自增
if(miao>=60) //秒为60,秒清零,分自增1
{
miao=0;
fen++;
if(fen>=60) //分为60,分清零,小时自增1
{
fen=0;
shi++;
Buzzer_Time(100); //整点提醒蜂鸣器工作
if(shi>=24) //小时为24时,小时清零
{
shi=0;
}
}
}
}
}
//中断服务程序 外部中断0
void Init0_Routine() interrupt 0
{
++a;
if(a>=4) a=1;
P1=gong_neng[a];
}
//unsigned int shi_=S,fen_=F-3,miao_,Keynum_;
//按键控制闹钟 自增函数
void _yuanze()
{
Keynum_=Key(); //接引按键扫描模块“Key.c”函数的返回值Keynumber
//通过分支语句对不同按键对 秒K1, 分K2, 时K3, 启动计时器K1, 关闭计时器K4 实行调节
switch(Keynum_)
{
case 2:fen_++;Keynum_=0;if (fen_>=60) fen_=0;break;
case 1:shi_++;Keynum_=0;if (shi_>=24) shi_=0;break;
}
x=shi_;y=fen_;
}
没有合适的资源?快使用搜索试试~ 我知道了~
AT89C51+proteus+74hc573数字时钟
共34个文件
lst:7个
obj:5个
c:4个
需积分: 5 8 下载量 72 浏览量
2023-09-03
23:57:00
上传
评论
收藏 184KB ZIP 举报
温馨提示
主控C51,使用锁存器74HC573数码管控制
资源推荐
资源详情
资源评论
收起资源包目录
AT89C51+proteus+74hc573数字时钟.zip (34个子文件)
AT89C51+proteus+74hc573数字时钟
程序
BUZZER.c 301B
Key.c 433B
Objects
Delay.obj 873B
数字时钟.build_log.htm 1KB
Timber0.obj 3KB
Key.obj 3KB
数字时钟 17KB
数字时钟.lnp 190B
main.obj 13KB
BUZZER.obj 3KB
nao_zhong.__i 148B
数字时钟.hex 4KB
Key.h 70B
BUZZER.h 113B
Listings
NZ.lst 1KB
nao_zhong.lst 3KB
main.lst 13KB
数字时钟.m51 13KB
Key.lst 2KB
BUZZER.lst 2KB
Delay.lst 1KB
Timber0.lst 3KB
数字时钟.uvproj 14KB
Delay.h 84B
Delay.c 126B
数字时钟.uvgui.Administrator 91KB
main.c 5KB
数字时钟.uvopt 6KB
仿真
新工程.pdsprj 24KB
Last Loaded 新工程.pdsbak 23KB
Project Backups
新工程 [Proteus 8.9].pdsprj 23KB
新工程 [20230903, 23-50-10].pdsprj 24KB
新工程 [20230903, 23-50-09].pdsprj 24KB
Backup Of 新工程.pdsbak 23KB
共 34 条
- 1
资源评论
喜·き
- 粉丝: 159
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功