这是我大一做的51单片机电子时钟设计,用了一个月时间,附件
制作出来的实物图如下:
单片机程序源码:
- #include "lcd1602.h"
- #include "key.h"
- #include "delay.h"
- #include "ds1302.h"
- uchar count;
- void Timer0Init(void) //10毫秒@12.000MHz
- {
- TMOD &= 0xF0; //设置定时器模式
- TMOD |= 0x01; //设置定时器模式
- TL0 = 0xF0; //设置定时初值
- TH0 = 0xD8; //设置定时初值
- TF0 = 0; //清除TF0标志
- ET0 = 1;
- EA = 1;
- }
- void init_system(void)
- {
- init_lcd1602();
- Timer0Init();
- write_string(NIAN_ADD-0X80,0,"20 - - ");
- write_string(SHI_ADD-0XC0,1," : : ");
- InitDS1302();
- }
- void main(void)
- {
- init_system();
- while(1)
- {
- if(flag==0&&flag_r==0)
- {
- fen = DS1302_Rdata(0x83);//从DS1302读取分数据
- write_sfm(3,fen);
- shi = DS1302_Rdata(0x85);//从DS1302读取时数据
- write_sfm(0,shi);
- ri = DS1302_Rdata(0x87); //从DS1302读取日数据
- write_nyr(8,ri);
- yue = DS1302_Rdata(0x89);//从DS1302读取月数据
- write_nyr(5,yue);
- nian = DS1302_Rdata(0x8d); //从DS1302读取年数据
- write_nyr(2,nian);
- week = DS1302_Rdata(0x8b);//从DS1302读取星期数据
- write_week(week);
- miao = DS1302_Rdata(0x81);//从DS1302读取秒数据
- write_sfm(6,miao);
- write_sfm(0,shi); //闹铃
- write_nyr(8,ri);
- write_nyr(5,yue);
- write_nyr(2,nian);
- write_week(week);
- if(shi==ashi&&fen==afen&&miao==amiao)
- {
- TR0 = 1; //定时器0开始计时
- }
- keyscan();
- }
- keyscan();
- }
- }
- void timer0(void) interrupt 1
- {
- TL0 = 0xF0; //设置定时初值
- TH0 = 0xD8; //设置定时初值
- count++;
- if(count==50)
- {
- count=0;
- beep=~beep;
- }
- }
复制代码
里包含电子时钟的单片机源代码,原理图和PCB,都是自己原创,请大家多多指教
全部资料51hei下载地址:
电子时钟(ds1302).7z
(1.79 MB, 下载次数: 73)
|