首页 实时时钟DS12C887_C实例程序

实时时钟DS12C887_C实例程序

举报
开通vip

实时时钟DS12C887_C实例程序DS12C887实例程序#include#defineucharunsignedchar#defineuintunsignedintucharnian,yue,ri,day,shi,fen,miao,ashi,afen,sshi,sfen;uchars1num,flag,flag1,flag2,flag3,flag4,settime,setalarm;/********************************************************************引脚配置定义 GNDVCCV...

实时时钟DS12C887_C实例程序
DS12C887实例程序#include#defineucharunsignedchar#defineuintunsignedintucharnian,yue,ri,day,shi,fen,miao,ashi,afen,sshi,sfen;uchars1num,flag,flag1,flag2,flag3,flag4,settime,setalarm;/********************************************************************引脚配置定义 GNDVCCVLRSR/WED0D1D2D3D4D5D6D7BLABLK*********************************************************************/#define LCDIO P1sbitLCD1602_RS=P3^5;sbitLCD1602_RW=P3^4;sbitLCD1602_EN=P3^3;sbits1=P2^1;sbits2=P2^2;sbits3=P2^0;sbits4=P2^3;/********************************************************************/voidLCD_delay(void);voiddelay_ms(unsignedintn);ucharchange_bcd(uchara);voidLCD_en_command(unsignedcharcommand);voidLCD_en_dat(unsignedchartemp);voidLCD_set_xy(unsignedcharx,unsignedchary);voidLCD_write_string(unsignedcharX,unsignedcharY,unsignedchar*s);voidLCD_init(void);voidwrite_sfm(uchar,uchar);voidsetup_time();voidsetup_alarm();/********************LCDPART*************************************/voidLCD_delay(void){_nop_();_nop_();_nop_();}voiddelay_ms(uintz)   {uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}/******************************************************************/ucharchange_bcd(uchara)  //D0~D7转换程序{chartemp,i;for(i=0;i<8;i){temp<<=1;temp|=(a&0x01);a>>=1;}return(temp);}/******************************************************************/voidLCD_en_command(unsignedcharcommand){command=change_bcd(command);command=_crol_(command,4);LCD1602_RS=0; LCD1602_EN=0;LCDIO&=0X0f;LCDIO|=(command&0xf0);LCD1602_EN=1;LCD_delay();LCD1602_EN=0;LCDIO&=0X0f;LCDIO|=(command<<4)&0xf0;LCD1602_EN=1;LCD_delay();LCD1602_EN=0;delay_ms(1);}voidLCD_en_dat(unsignedchardat){dat=change_bcd(dat);dat=_crol_(dat,4);LCD1602_RS=1;LCD1602_EN=0;LCDIO&=0X0f;LCDIO|=(dat&0xf0);LCD1602_EN=1;LCD_delay();LCD1602_EN=0;LCDIO&=0X0f;LCDIO|=(dat<<4)&0xf0;LCD1602_EN=1;LCD_delay();LCD1602_EN=0;delay_ms(1);}/********************************************************************/voidLCD_set_xy(unsignedcharx,unsignedchary){unsignedcharaddress;if(y==0)address=0x80x;elseaddress=0xC0x;LCD_en_command(address);}/********************************************************************/voidLCD_write_string(unsignedcharX,unsignedcharY,unsignedchar*s)     {LCD_set_xy(X,Y);  //setaddresswhile(*s)   //writecharacter{LCD_en_dat(*s); s;}}/********************************************************************/voidLCD_init(void){LCD1602_RW=0;LCD_en_command(0x01);delay_ms(5);LCD_en_command(0x01);delay_ms(5);  LCD_en_command(0x28);delay_ms(5);LCD_en_command(0x28);delay_ms(5);LCD_en_command(0x28);delay_ms(5);  LCD_en_command(0x0C);delay_ms(5);  LCD_en_command(0x80);delay_ms(5);  LCD_en_command(0x01);delay_ms(5);}/********************************************************************/voidwrite_sfm(ucharadd,uchardate){ucharshi,ge;shi=date/10;ge=date;LCD_en_command(add);LCD_en_dat(shi'0');LCD_en_dat(ge'0');}/*****************************SETDAY&TIME***************************************/voidsetup_time(){if(s1==0)  {delay_ms(5);if(s1==0){  s1num;TR0=0;               //关定时器flag=1;flag1=1;flag3=1;flag4=1;           //停止扫描DS12C887_read_time,setup_alarmwhile(!s1);if(s1num==1){LCD_en_command(0x82);LCD_en_command(0x0f);}}if(s1num==2){LCD_en_command(0x85);}if(s1num==3){LCD_en_command(0x88);}if(s1num==4){LCD_en_command(0x8b);}if(s1num==5){LCD_en_command(0xc0);}if(s1num==6){LCD_en_command(0xc3);}if(s1num==7){LCD_en_command(0xc6);}if(s1num==8){s1num=0;TR0=1;              //开定时器flag1=0;flag3=0;flag4=0;    //执行扫描setup_alarmsettime=1;            //执行settimeLCD_en_command(0x0c);}  }if(s1num!=0){/********************************************************************/if(s2==0){delay_ms(2);if(s2==0){while(!s2);if(s1num==1){nian;if(nian==100)miao=0;write_sfm(0x82,nian);LCD_en_command(0x82);  }if(s1num==2){yue;if(yue==13)yue=0;write_sfm(0x85,yue);LCD_en_command(0x85);}if(s1num==3){ri;if(ri==32)ri=0;write_sfm(0x88,ri);LCD_en_command(0x88);}if(s1num==4){day;if(day==8)day=1;write_sfm(0x8b,day);LCD_en_command(0x8b);}if(s1num==5){shi;if(shi==24)shi=0;write_sfm(0xc0,shi);LCD_en_command(0xc0);}if(s1num==6){fen;if(fen==60)fen=0;write_sfm(0xc3,fen);LCD_en_command(0xc3);}if(s1num==7){miao;if(miao==60)miao=0;write_sfm(0xc6,miao);LCD_en_command(0xc6);  }}}/********************************************************************/if(s3==0){delay_ms(2);if(s3==0){while(!s3);if(s1num==1){nian--;if(nian==-1)nian=99;write_sfm(0x82,nian);LCD_en_command(0x82);  }if(s1num==2){yue--;if(yue==0)yue=12;write_sfm(0x85,yue);LCD_en_command(0x85);}if(s1num==3){ri--;if(ri==0)ri=31;write_sfm(0x88,ri);LCD_en_command(0x88);}if(s1num==4){day--;if(day==0)day=7;write_sfm(0x8b,day);LCD_en_command(0x8b);}if(s1num==5){shi--;if(shi==-1)shi=23;write_sfm(0xc0,shi);LCD_en_command(0xc0);}if(s1num==6){fen--;if(fen==-1)fen=59;write_sfm(0xc3,fen);LCD_en_command(0xc3);}if(s1num==7){miao--;if(miao==-1)miao=59;write_sfm(0xc6,miao);LCD_en_command(0xc6);}}}/********************************************************************/}}/********************************************************************//********************************************************************/voidsetup_alarm(){if(s4==0)  {delay_ms(5);if(s4==0){  s1num;TR0=0;                 //关定时器flag=1;flag2=1;flag3=1;flag4=1;     //停止扫描DS12C887_read_time,setup_timewhile(!s4);if(s1num==1){LCD_en_command(0x01);LCD_write_string(0,0,"Startalarmat");write_sfm(0xcb,ashi);write_sfm(0xce,afen);LCD_write_string(0x0d,1,":");LCD_en_command(0xcb);LCD_en_command(0x0f);}}if(s1num==2){LCD_en_command(0xce);  }if(s1num==3){LCD_en_command(0x01);LCD_write_string(0,0,"Stopalarmat");  write_sfm(0xcb,sshi);write_sfm(0xce,sfen);LCD_write_string(0x0d,1,":");LCD_en_command(0xcb);LCD_en_command(0x0f);    }if(s1num==4){LCD_en_command(0xce);  }if(s1num==5){s1num=0;TR0=1;              //开定时器flag2=0;flag3=0;flag4=0;    //执行扫描setup_timesetalarm=1;            //执行setalarmLCD_en_command(0x01);      //清LCD屏幕LCD_write_string(0,0,"20 - -");LCD_write_string(2,1,": :");LCD_en_command(0x0c);  }}if(s1num!=0){/********************************************************************/if(s2==0){delay_ms(5);if(s2==0){while(!s2);if(s1num==1){ashi;if(ashi==24)ashi=0;write_sfm(0xcb,ashi);LCD_en_command(0xcb);  }if(s1num==2){afen;if(afen==60)afen=0;write_sfm(0xce,afen);LCD_en_command(0xce);}if(s1num==3){sshi;if(sshi==24)sshi=0;write_sfm(0xcb,sshi);LCD_en_command(0xcb);  }if(s1num==4){sfen;if(sfen==60)sfen=0;write_sfm(0xce,sfen);LCD_en_command(0xce);}}}/********************************************************************/if(s3==0){delay_ms(5);if(s3==0){while(!s3);if(s1num==1){ashi--;if(ashi==-1)ashi=23;write_sfm(0xcb,ashi);LCD_en_command(0xcb);  }if(s1num==2){afen--;if(afen==-1)afen=59;write_sfm(0xce,afen);LCD_en_command(0xce);}if(s1num==3){sshi--;if(sshi==-1)sshi=23;write_sfm(0xcb,sshi);LCD_en_command(0xcb);  }if(s1num==4){sfen--;if(sfen==-1)sfen=59;write_sfm(0xce,sfen);LCD_en_command(0xce);}}}/********************************************************************/}}
本文档为【实时时钟DS12C887_C实例程序】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_477730
暂无简介~
格式:doc
大小:48KB
软件:Word
页数:33
分类:
上传时间:2022-08-09
浏览量:0