




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、.#include<reg52.h>#define LCD_Date P0 #define uchar unsigned char #define uint unsigned int#define N 2#define MS 10sbit RS=P20;sbit RW=P21;sbit E=P22;sbit DQ=P23;sbit Beep=P24;sbit LED=P37;sbit clock_rst=P25;sbit clock_clk=P26;sbit clock_dat=P27;sbit K0=P30;sbit K1=P31;sbit K2=P32;sbit K3=P33;
2、sbit K4=P34;sbit K5=P35;sbit K6=P36;uchar code tab=0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f;uint Temp_Value;bit bdata Flag=0;bit bdata Flag_1302=0;bit bdata Flag_Speaker=0;bit bdata Flag_Beep=0;uchar Date,Month,Year,Sec, Min, Hour,Week,Count;uchar Min_Speaker,Hour_Speaker,Latter=0,BeepNum=0;/*/void d
3、elay_6us(uchar us)while(us-);/*/void delay_1ms(uint ms)uint i,j;for(i=ms;i>0;i-)for(j=122;j>0;j-);/*/void LCD_Check_Busy()doLCD_Date=0xff;E=0;RS=0;RW=1;E=1;delay_1ms(1);while(LCD_Date&0x80);/*/void LCD_Write_com(uchar wcom)LCD_Check_Busy();E=0;RS=0;RW=0;LCD_Date=wcom;E=1;delay_1ms(1);E=0;/
4、*/*uchar LCD_Read_date()LCD_Check_Busy();E=0;RS=1;RW=1;E=1;delay_1m(1);return LCD_Date;*/*/void LCD_Write_date(uchar wdate)LCD_Check_Busy();E=0;RS=1;RW=0;LCD_Date=wdate;E=1;delay_1ms(1);E=0;/*/void LCD_Init()LCD_Write_com(0x38);delay_1ms(1);LCD_Write_com(0x08);delay_1ms(1);LCD_Write_com(0x01);delay_
5、1ms(1);LCD_Write_com(0x02);delay_1ms(1);LCD_Write_com(0x06);delay_1ms(1);LCD_Write_com(0x0c);delay_1ms(1);/*/void Init_18b20()DQ=1;delay_6us(2);DQ=0;delay_6us(100);DQ=1;delay_6us(50);/*/void Write_18b20(uchar wdate)uchar i;for(i=0;i<8;i+)DQ=0;delay_6us(2);DQ=wdate&0x01;delay_6us(30);wdate=wda
6、te>>1;DQ=1;/*/uchar Read_18b20()uchar i,rdate=0;for(i=0;i<8;i+)DQ=0;delay_6us(2);DQ=1;rdate=rdate>>1;if(DQ=1)rdate=rdate|0x80;delay_6us(30);DQ=1;return(rdate);/*/void Get_Temperature()uchar High,Low;Init_18b20();Write_18b20(0xcc);Write_18b20(0x44);delay_1ms(30);Init_18b20();Write_18b2
7、0(0xcc);Write_18b20(0xbe);Low=Read_18b20();High=Read_18b20(); Temp_Value=High;Temp_Value=Temp_Value<<8;Temp_Value=Temp_Value|Low;if(Temp_Value<=0x0fff)Flag=0;else Flag=1;Temp_Value=Temp_Value+1;Temp_Value=Temp_Value*0.625+0.5;/*/void Display_18b20()uchar Bai,Shi,Ge,Point; Get_Temperature();
8、delay_6us(10);Bai=Temp_Value/1000+0x30;Shi=Temp_Value/100%10+0x30;Ge=Temp_Value/10%10+0x30;Point=Temp_Value%10+0x30;if(Bai=0x30)Bai=0x20;if(Shi!=0x30 && Flag=1)Bai=0x2d;if(Shi=0x30)if(Flag=0)Shi=0x20;else Shi=0x2d; LCD_Write_com(0xc0+9);LCD_Write_date(Bai);LCD_Write_date(Shi);LCD_Write_date(
9、Ge);LCD_Write_date('.');LCD_Write_date(Point);/*/void Write_1302_clock(uchar wdate)uchar i; for(i=0;i<8;i+)clock_clk=0;clock_dat=wdate&0x01;wdate>>=1;clock_clk=1;/*/uchar Read_1302_clock()uchar i,rdate=0;for(i=0;i<8;i+)clock_clk=0;rdate>>=1;if(clock_dat=1)rdate=rdate|0x
10、80;clock_clk=1;return rdate;/*/void Write_1302_byte(uchar reg,uchar wdate)clock_rst=0;clock_clk=0;clock_rst=1;Write_1302_clock(reg);Write_1302_clock(wdate);clock_rst=0;clock_clk=0;/*/uchar Read_1302_byte(uchar reg2)uchar rdate;clock_rst=0;clock_clk=0;clock_rst=1;Write_1302_clock(reg2);rdate=Read_130
11、2_clock();return rdate;/*/void Init_1302()Write_1302_byte(0x8e,0x00);delay_1ms(1);Write_1302_byte(0x80,0x80); /暂停delay_1ms(1);Write_1302_byte(0x86,Date); /datedelay_1ms(1);Write_1302_byte(0x88,Month);/monthdelay_1ms(1);Write_1302_byte(0x8a,Week); /weekdelay_1ms(1);Write_1302_byte(0x8c,Year); /yearde
12、lay_1ms(1);Write_1302_byte(0x84,Hour);delay_1ms(1);Write_1302_byte(0x82,Min);delay_1ms(1);Write_1302_byte(0x80,Sec);delay_1ms(1);Write_1302_byte(0x90,0xa0);delay_1ms(1);Write_1302_byte(0x8e,0x80);delay_1ms(1);/*/void Read_1302()Week=Read_1302_byte(0x8b); /dayHour=Read_1302_byte(0x85); /hourMin=Read_
13、1302_byte(0x83); /minSec=Read_1302_byte(0x81);/sec Date=Read_1302_byte(0x87);/dateMonth=Read_1302_byte(0x89);/monthYear=Read_1302_byte(0x8d);/year/*/void Display_1302()uchar l,h;LCD_Write_com(0x80+0);if(Flag_1302=1 && Latter>=N && Count=2)if(Latter=N)Latter=0;LCD_Write_date(0x20);
14、LCD_Write_date(0x20);else h=(Hour>>4)+0x30;l=(Hour&0x0f)+0x30;LCD_Write_date(h);LCD_Write_date(l);LCD_Write_date(':');if(Flag_1302=1 && Latter>=N && Count=1)if(Latter=N)Latter=0;LCD_Write_date(0x20);LCD_Write_date(0x20);else h=(Min>>4)+0x30;l=(Min&0x0f)
15、+0x30;LCD_Write_date(h);LCD_Write_date(l);LCD_Write_date(':'); if(Flag_1302=1 && Latter>=N && Count=0)if(Latter=N)Latter=0;LCD_Write_date(0x20);LCD_Write_date(0x20);else h=(Sec>>4)+0x30;l=(Sec&0x0f)+0x30;LCD_Write_date(h);LCD_Write_date(l);LCD_Write_com(0x80+9);
16、if(Flag_1302=1 && Latter>=N && Count=3)if(Latter=N)Latter=0;LCD_Write_date(0x20);else l=(Week&0x0f)+0x30;LCD_Write_date(l);LCD_Write_com(0xc0+0);if(Flag_1302=1 && Latter>=N && Count=4)if(Latter=N)Latter=0;LCD_Write_date(0x20);LCD_Write_date(0x20);else h=(Dat
17、e>>4)+0x30;l=(Date&0x0f)+0x30;LCD_Write_date(h);LCD_Write_date(l);LCD_Write_date('/');if(Flag_1302=1 && Latter>=N && Count=5)if(Latter=N)Latter=0;LCD_Write_date(0x20);LCD_Write_date(0x20);else h=(Month>>4)+0x30;l=(Month&0x0f)+0x30;LCD_Write_date(h);LCD_
18、Write_date(l);LCD_Write_date('/');if(Flag_1302=1 && Latter>=N && Count=6)if(Latter=N)Latter=0;LCD_Write_date(0x20);LCD_Write_date(0x20);else h=(Year>>4)+0x30;l=(Year&0x0f)+0x30;LCD_Write_date(h);LCD_Write_date(l);/*/void Display_Speaker()uchar l_Speaker,h_Speaker
19、;LCD_Write_com(0x80+11);if(Flag_Speaker=1)if(Latter>=N && Count=2)if(Latter=N)Latter=0;LCD_Write_date(0x20);LCD_Write_date(0x20);else h_Speaker=(Hour_Speaker>>4)+0x30;l_Speaker=(Hour_Speaker&0x0f)+0x30;LCD_Write_date(h_Speaker);LCD_Write_date(l_Speaker);LCD_Write_date(':'
20、;);if(Latter>=N && Count=1)if(Latter=N)Latter=0;LCD_Write_date(0x20);LCD_Write_date(0x20);else h_Speaker=(Min_Speaker>>4)+0x30;l_Speaker=(Min_Speaker&0x0f)+0x30; LCD_Write_date(h_Speaker);LCD_Write_date(l_Speaker);if(Flag_Speaker=0)LCD_Write_date(0x20);LCD_Write_date(0x20);LCD_W
21、rite_date(0x20);LCD_Write_date(0x20);LCD_Write_date(0x20);/*/uchar Up(uchar time)uchar high_up,low_up;low_up=time&0x0f;high_up=time>>4;low_up+;if(low_up=10)low_up=0;high_up+;if(high_up=6 && (Count=0 | Count=1) | (high_up=10 && Count=6)high_up=0;if(high_up=0 && low_u
22、p=8 && Count=3)low_up=1;high_up<<=4;time=high_up|low_up;if(time=0x24 && Count=2 && Flag_1302=1)time=0;if(time=0x13 && Count=5)time=0x01;if(Count=4 && time=0x32 && (Month=0x01 | Month=0x03 | Month=0x05 | Month=0x07 | Month=0x08 | Month=0x10 | Mont
23、h=0x12)time=0x01;if(Count=4 && time=0x31 && (Month=0x02 | Month=0x04 | Month=0x06 | Month=0x09 | Month=0x11)time=0x01;return time;/*/uchar Down(uchar time)uchar high_down,low_down;low_down=time&0x0f;high_down=time>>4; if(Count=0 | Count=1)if(low_down=0)low_down=9;if(high_do
24、wn=0)high_down=5;elsehigh_down-;else low_down-;if(Count=2)if(low_down=0)if(high_down=0)time=0x23;goto loop1;elselow_down=9;high_down-;else low_down-;if(Count=3)if(low_down=1)low_down=7;else low_down-;if(Count=4)if(time=1 && (Month=0x01 | Month=0x03 | Month=0x05 | Month=0x07 | Month=0x08 | Mo
25、nth=0x10 | Month=0x12)time=0x31;goto loop1;else if(time=1 && (Month=0x02 | Month=0x04 | Month=0x06 | Month=0x09 | Month=0x11)time=0x30;goto loop1;else if(low_down=0)low_down=9;high_down-;else low_down-;if(Count=5)if(low_down=0)low_down=9;high_down-;else if(time=1)time=0x12;goto loop1;else lo
26、w_down-;if(Count=6)if(low_down=0)low_down=9;if(high_down=0)high_down=9;elsehigh_down-;else low_down-;high_down<<=4;high_down=high_down&0xf0;time=high_down|low_down;loop1:return time;/*/void Key()if(K0=0)/delay_1ms(10);if(K0=0)Count=0;Flag_1302=1;Write_1302_byte(0x8e,0x00);delay_1ms(1);Writ
27、e_1302_byte(0x80,0x80); /暂停P1=tabCount;while(K0=0);if(K1=0)/delay_1ms(10);if(K1=0)Count=1;Flag_Speaker=1;P1=tabCount;while(K1=0);if(K2=0 && (Flag_Speaker=1 | Flag_1302=1)/delay_1ms(10);if(K2=0 && (Flag_Speaker=1 | Flag_1302=1)Count+;if(Count=7 && Flag_1302=1)Count=0;if(Count=
28、3 && Flag_Speaker=1)Count=1;P1=tabCount;while(K2=0);if(K3=0 && (Flag_Speaker=1 | Flag_1302=1)/delay_1ms(10);if(K3=0 && (Flag_Speaker=1 | Flag_1302=1)if(Count=0 && Flag_1302=1)Count=6;else if(Count=1 && Flag_Speaker=1)Count=2;elseCount-;P1=tabCount;while(K3=0);
29、if(K4=0 && (Flag_Speaker=1 | Flag_1302=1) /add/delay_1ms(10);if(K4=0 && (Flag_Speaker=1 | Flag_1302=1)if(Count=0)/secSec=Up(Sec);if(Count=1)if(Flag_1302=1)Min=Up(Min);if(Flag_Speaker=1)Min_Speaker=Up(Min_Speaker);if(Count=2)if(Flag_1302=1)Hour=Up(Hour);if(Flag_Speaker=1)Hour_Speaker=
30、Up(Hour_Speaker);if(Count=3)Week=Up(Week);if(Count=4)Date=Up(Date);if(Count=5)Month=Up(Month);if(Count=6)Year=Up(Year);/while(K4=0);if(K5=0 && (Flag_Speaker=1 | Flag_1302=1)/sub/delay_1ms(10);if(K5=0 && (Flag_Speaker=1 | Flag_1302=1)if(Count=0)/secSec=Down(Sec);if(Count=1)if(Flag_130
31、2=1)Min=Down(Min); if(Flag_Speaker=1)Min_Speaker=Down(Min_Speaker);if(Count=2)if(Flag_1302=1)Hour=Down(Hour);if(Flag_Speaker=1)Hour_Speaker=Down(Hour_Speaker);if(Count=3)Week=Down(Week);if(Count=4)Date=Down(Date);if(Count=5)Month=Down(Month);if(Count=6)Year=Down(Year);/while(K5=0);if(K6=0 &&
32、 (Flag_Speaker=1 | Flag_1302=1)/sub/delay_1ms(10);if(K6=0 && (Flag_Speaker=1 | Flag_1302=1)if(Flag_1302=1)Flag_1302=0;Init_1302();if(Flag_Speaker=1)Flag_Speaker=0;P1=0xff;while(K6=0);/*/void Speaker()if(Min=Min_Speaker && Hour=Hour_Speaker)Flag_Beep=1;LED=0;TR0=1; TR1=1;elseFlag_Beep=0;LED=1;TR0=0; TR1=0;/*/#define TIME0 20#define TIME1 1700void Ini
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 药店员工合同协议书(二零二五年度)-药品销售与顾客服务专项
- 2025年度橱柜行业品牌孵化与培育合同
- 2025年砸墙工程安全教育培训及考核协议合同
- 2025年度酒店客房改造与租赁合同
- 直播带货商家与MCN机构2025年度战略合作合同
- 代驾服务与汽车维修合同
- 家具定制设计风格确认协议
- 多功能厅建设造价咨询合同
- 会议交通接送服务合同
- 2025至2030年中国时尚女装包数据监测研究报告
- 2024至2030年中国钱币类收藏品行业市场前景调查及投融资战略研究报告
- 三级安全培训考试题附参考答案(满分必刷)
- 高一英语完形填空专项训练100(附答案)及解析
- 机房基础设施运行维护管理标准规范
- 老年心房颤动诊治中国专家共识(2024)解读
- 部编版八年级上册历史期中复习重点总结
- 2024年扬州市职业大学单招职业适应性测试题库1套
- 消防安全技术综合能力要点概述
- DL-T 5148-2021水工建筑物水泥灌浆施工技术条件-PDF解密
- 道路施工安全隐患及防范措施
- 新生儿鱼鳞病个案护理
评论
0/150
提交评论