




已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/*52单片机与ds12b887,ds18b20综合使用,1602显示*/#include#include #define uchar unsigned char #define uint unsigned intsbit dula=P26;sbit wela=P27;sbit rs=P35;sbit wr=P36;sbit E=P34;sbit s1=P30;sbit s2=P31;sbit s3=P32;sbit s4=P32;/闹钟查看键sbit rd=P37;sbit beep=P23;sbit dscs=P14;sbit dsas=P15;sbit dswr=P16;sbit dsds=P17;sbit dsirq=P33;sbit JD=P06;sbit BF=P07;sbit DQ=P22;bit flag1,flag_ri;uchar count,s1num,flag,t0_num;uchar miao,shi,fen,year,month,day,week,amiao,afen,ashi,time;void write_ds(uchar,uchar);/函数申明void set_alarm(uchar,uchar,uchar);void read_alarm();uchar read_ds(uchar);void set_time();uchar code table= 20 - - ;uchar code table1= : : ;uchar code digit10=0123456789; uchar code Error=Error!Check!; uchar code Temp=Temp:; uchar code Cent=*C;uchar read_ds(uchar add) uchar ds_date;dsas=1;dsds=1;dswr=1;dscs=0;P0=add;dsas=0;dsds=0;P0=0xff;ds_date=P0;dsds=1;dsas=1;dscs=1;return ds_date;void write_ds(uchar add,uchar date)dscs=0;dsas=1;dsds=1;dswr=1;P0=add;dsas=0;dswr=0;P0=date;dswr=1;dsas=1;dscs=1;void set_time()write_ds(4,10);write_ds(2,32);void set_alarm(uchar ashi,uchar afen,uchar amiao)write_ds(1,amiao);write_ds(3,afen);write_ds(5,ashi);void delay(uint z)uint x,y;for(x=z;x0;x-)for(y=110;y0;y-);void delay1ms() unsigned char i,j; for(i=0;i4;i+) for(j=0;j33;j+) ; void delaynms(unsigned char n) unsigned char i;for(i=0;in;i+) delay1ms(); void di() beep=0;delay(100);beep=1;void didi() beep=0;delay(50);beep=1;delay(100);beep=0;delay(50);beep=1;void write_com(uchar com)rs=0;E=0;P0=com;delay(5);E=1;delay(5);E=0;void write_date(uchar date)rs=1;E=0;P0=date;delay(5);E=1;delay(5);E=0;void init()uchar num;EA=1;EX1=1;IT1=1;flag1=0;t0_num=0;s1num=0;week=1;dula=0;wela=0;E=0;rd=0;/以下几行在首次设置DS12C887时使用,以后不必再写入write_ds(0x0A,0x20);write_ds(0x0B,0x26);/设置24小时模式,数据二进制格式set_time();/设置上电默认时间/-*/write_com(0x38);/1602液晶初始化write_com(0x0c);write_com(0x06);write_com(0x01);write_com(0x80);for(num=0;num15;num+)/写入液晶固定部分显示write_date(tablenum);delay(1);write_com(0x80+0x40);for(num=0;num11;num+)write_date(table1num);delay(1);void write_sfm(uchar add,uchar date)uchar shi,ge;shi=date/10;ge=date%10;write_com(0x80+0x40+add);write_date(0x30+shi);write_date(0x30+ge);bit BusyTest(void) bit result;rs=0; wr=1; E=1; _nop_(); _nop_(); _nop_(); _nop_(); result=BF; E=0; return result; void WriteInstruction (unsigned char dictate) while(BusyTest()=1); rs=0; wr=0; E=0; _nop_(); _nop_(); P0=dictate; _nop_(); _nop_(); _nop_(); _nop_(); E=1; _nop_(); _nop_(); _nop_(); _nop_(); E=0; void WriteAddress(unsigned char x) WriteInstruction(x|0x80); void WriteData(unsigned char y) while(BusyTest()=1); rs=1; wr=0; E=0; P0=y; _nop_(); _nop_(); _nop_(); _nop_(); E=1; _nop_(); _nop_(); _nop_(); _nop_(); E=0; void LcdInitiate(void) delaynms(15); WriteInstruction(0x38); delaynms(5); WriteInstruction(0x38);delaynms(5); WriteInstruction(0x38); delaynms(5); WriteInstruction(0x0c); delaynms(5); WriteInstruction(0x06); delaynms(5); WriteInstruction(0x01); delaynms(5); bit Init_DS18B20(void) bit flag; DQ = 1; for(time=0;time2;time+) ; DQ = 0; for(time=0;time200;time+) ; DQ = 1; for(time=0;time10;time+); flag=DQ; for(time=0;time200;time+) ; return (flag); uchar ReadOneChar(void) unsigned char i=0;unsigned char dat; for (i=0;i=1; _nop_(); DQ = 1; for(time=0;time2;time+) ; if(DQ=1) dat|=0x80; elsedat|=0x00; for(time=0;time8;time+); return(dat); WriteOneChar(unsigned char dat)unsigned char i=0;for (i=0; i8; i+) DQ =1; _nop_(); DQ=0; DQ=dat&0x01; for(time=0;time10;time+); DQ=1; for(time=0;time=1; for(time=0;time4;time+); void display_error(void) unsigned char i; WriteAddress(0x00); i = 0; while(Errori != 0) WriteData(Errori); i+; delaynms(100); while(1) ;void display_dot(void) WriteAddress(0x4c); WriteData(.); delaynms(50); void display_cent(void) unsigned char i; WriteAddress(0x4e); i = 0; while(Centi != 0) WriteData(Centi); i+; delaynms(50); void display_temp1(unsigned char x) unsigned char j,k,l; j=x/100; k=(x%100)/10; l=x%10; WriteAddress(0x4a); WriteData(digitk); WriteData(digitl); delaynms(50); void display_temp2(unsigned char x) WriteAddress(0x4d); WriteData(digitx); delaynms(50); void ReadyReadTemp(void) Init_DS18B20(); WriteOneChar(0xCC); WriteOneChar(0x44); for(time=0;time100;time+) ;Init_DS18B20(); WriteOneChar(0xCC); WriteOneChar(0xBE); void write_nyr(uchar add,char date)/1602液晶刷新年月日函数3为年,6为分,9为秒char shi,ge;shi=date/10;ge=date%10;write_com(0x80+add);write_date(0x30+shi);write_date(0x30+ge);void write_week(char we)/写液晶星期显示函数write_com(0x80+12);switch(we)case 1:write_date(M);delay(5);write_date(O);delay(5);write_date(N);break;case 2:write_date(T);delay(5);write_date(U);delay(5);write_date(E);break;case 3:write_date(W);delay(5);write_date(E);delay(5);write_date(D);break;case 4:write_date(T);delay(5);write_date(H);delay(5);write_date(U);break;case 5:write_date(F);delay(5);write_date(R);delay(5);write_date(I);break;case 6:write_date(S);delay(5);write_date(A);delay(5);write_date(T);break;case 7:write_date(S);delay(5);write_date(U);delay(5);write_date(N);break;void keyscan()if(flag_ri=1)if(s1=0)|(s2=0)|(s3=0)|(s4=0)delay(5);if(s1=0)|(s2=0)|(s3=0)|(s4=0)while(!(s1&s2&s3&s4); di();flag_ri=0; if(s1=0)delay(5);if(s1=0)s1num+;if(flag1=1)if(s1num=4)s1num=1;flag=1;while(!s1);di();switch(s1num)case 1: write_com(0x80+0x40+6); write_com(0x0f);break;case 2: write_com(0x80+0x40+3);break;case 3: write_com(0x80+0x40+0);break;case 4: write_com(0x80+12);break;case 5: write_com(0x80+9);break;case 6: write_com(0x80+6);break;case 7: write_com(0x80+3);break;case 8: s1num=0;write_com(0x0c);flag=0;write_ds(0,miao);write_ds(2,fen);write_ds(4,shi);write_ds(6,week);write_ds(7,day);write_ds(8,month);write_ds(9,year);break;if(s1num!=0)if(s2=0)delay(1);if(s2=0)while(!s2);di();switch(s1num)case 1:miao+;if(miao=60)miao=0;write_sfm(10,miao);write_com(0x80+0x40+6); break;case 2:fen+;if(fen=60)fen=0;write_sfm(7,fen);write_com(0x80+0x40+3); break;case 3:shi+;if(shi=24)shi=0;write_sfm(4,shi);write_com(0x80+0x40+0); break;case 4:week+;if(week=8)week=1;write_week(week);write_com(0x80+12);break;case 5:day+;if(day=32)day=1;write_nyr(9,day);write_com(0x80+9);break;case 6:month+;if(month=13)month=1;write_nyr(6,month);write_com(0x80+6);break;case 7:year+;if(year=100)year=0;write_nyr(3,year);write_com(0x80+3);break;if(s3=0)delay(1);if(s3=0)while(!s3);di();switch(s1num)case 1:miao-;if(miao=-1)miao=59;write_sfm(6,miao);write_com(0x80+0x40+6);break; case 2:fen-;if(fen=-1)fen=59;write_sfm(3,fen);write_com(0x80+0x40+3);break;case 3:shi-;if(shi=-1)shi=23;write_sfm(0,shi);write_com(0x80+0x40+0);break;case 4:week-;if(week=0)week=7;write_week(week);write_com(0x80+12);break;case 5:day-;if(day=0)day=31;write_nyr(9,day);write_com(0x80+9);break;case 6:month-;if(month=0)month=12;write_nyr(6,month);write_com(0x80+6);break;case 7:year-;if(year=-1)year=99;write_nyr(3,year);write_com(0x80+3);break;if(s4=0)delay(5);if(s4=0)flag1=flag1;while(!s4);di();if(flag1=0)flag=0;write_com(0x80+0x40);write_date( );write_date( );write_com(0x0c);write_ds(1,miao);write_ds(3,fen);write_ds(5,shi);elseread_alarm();miao=amiao;fen=afen;shi=ashi;write
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 贵金属轧延精密轧延工艺考核试卷及答案
- 建筑施工安全生产实务注册安全工程师考试(初级)试题及答案指导(2025年)
- 粪污厌氧消化技术改造方案考核试卷及答案
- 骆驼养殖绿色生产工艺考核试卷及答案
- 幼儿园3-6岁儿童学习与发展指南试题及答案
- 特种玻璃激光切割增强工艺考核试卷及答案
- 2025年初级社会工作师真题及答案
- 石油银行面试题及答案
- 触电伤害事故课件
- 解构主义全屋定制课件
- 5G基带芯片算法验证平台:从设计到实现的关键技术与实践
- 税务会计与税收筹划课件
- 2025年高考生物辽宁卷真题解读及复习备考指导(黑龙江吉林内蒙古适用)
- 新媒体视听节目制作
- 数字化教学环境下小学语文板书设计优化策略
- JG/T 237-2008混凝土试模
- JG/T 232-2008卫浴型散热器
- 灭火员初级习题库
- T/CAQP 001-2017汽车零部件质量追溯体系规范
- 燃气入户可行性报告
- 技术赋能医疗创新-深入解析数字化口腔诊所建设指南
评论
0/150
提交评论