由于公司电脑,不能图片与视频
- #include <reg52.h>
- #include"1602.h"
- #include"delay.h"
- #include "ds1302.h"
- #include "key.h"
- #include"dh11.h"
- #include <intrins.h>
- extern uchar S1num,flag,second,minute,hour,week,day,month,year;//秒、分、时、星期、日、月、年
- extern bit keyflag;
- /////////////////////////////////////////////////////
- extern uchar RHL,RHH,CL,CH;
- extern uint m,n;
- /////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////
- uchar code line1_data[] = {"00:00:00 "}; //定义第2行显示的字符
- /*****************读出秒的十进制数***************************/
- uchar readsecond()
- {
- uchar dat;
- dat=read_1302add(0x81);
- second=((dat&0x70)>>4)*10+(dat&0x0f);
- return second;
- }
- /*****************读出分的十进制数***************************/
- uchar readminute()
- {
- uchar dat;
- dat=read_1302add(0x83);
- minute=((dat&0x70)>>4)*10+(dat&0x0f);
- return minute;
- }
- /*****************读出小时的十进制数***************************/
- uchar readhour()
- {
- uchar dat;
- dat=read_1302add(0x85);
- hour=((dat&0x70)>>4)*10+(dat&0x0f);
- return hour;
- }
- /*****************读出天的十进制数***************************/
- uchar readday()
- {
- uchar dat;
- dat=read_1302add(0x87);
- day=((dat&0x70)>>4)*10+(dat&0x0f);
- return day;
- }
- /*****************读出月的十进制数***************************/
- uchar readmonth()
- {
- uchar dat;
- dat=read_1302add(0x89);
- month=((dat&0x70)>>4)*10+(dat&0x0f);
- return month;
- }
- uchar readyear()
- {
- uchar dat;
- dat=read_1302add(0x8d);
- year=((dat&0xf0)>>4)*10+(dat&0x0f);
- return year;
- }
- /************************读出所有时间**********************/
- void readtime()
- {
- readsecond();
- readminute();
- readhour();
- }
- void Timer0Init(void) //50毫秒@12.000MHz
- {
-
- TMOD |= 0x01; //设置定时器模式
- TL0 = 0xB0; //设置定时初值
- TH0 = 0x3C; //设置定时初值
-
- // TR0 = 1; //定时器0开始计时
- EA=1;
- ET0=1;
- }
- void main()
- {
- uchar i;
- Timer0Init();
- LCD_Init(); //初始化液晶
- Delay_ms(20); //延时有助于稳定
- LCD_Clear(); //清屏
- init_1302();
- LCD_Write_Com(0x40|0x80); //设置显示位置为第2行第0列
- i = 0;
- while(line1_data[i] != '\0') //在第2行0~3列显示"****"
- {
- LCD_Write_Data(line1_data[i]); //显示第2行字符
- i++; //指向下一字符
- }
- Delay_ms(1000);
- while(1)
- {
- keyscan();
- if(keyflag==0)
- {
- readtime(); //读取时,分,秒
- write_second(); //写秒
- write_minute(); //写分
- write_hour(); //写时
-
- }
- Delay_ms(100);
- receive();
- }
- }
- void timer0() interrupt 0 //12M/50ms
-
- {
- uint num;
- TL0 = 0xB0; //设置定时初值
- TH0 = 0x3C; //设置定时初值
-
- num++;
- if(num==20) //大致1s
- {
- num=0;
- second1--;
- if(second1<0) //秒到60,分钟加1
- {
- second1=59;
- minute1-1;
- if(minute1<0)//分钟到60,小时加1
- {
- minute1=59;
- hour1-1;
- }
- }
- }
- if(((second1==0)&minute1==0)&hour1==0)
- {
- TR1=0;
- BEEP();
- }
- }
复制代码
|