sed1520显示时间

上传人:206****923 文档编号:91265771 上传时间:2019-06-27 格式:DOC 页数:6 大小:41.02KB
返回 下载 相关 举报
sed1520显示时间_第1页
第1页 / 共6页
sed1520显示时间_第2页
第2页 / 共6页
sed1520显示时间_第3页
第3页 / 共6页
sed1520显示时间_第4页
第4页 / 共6页
sed1520显示时间_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《sed1520显示时间》由会员分享,可在线阅读,更多相关《sed1520显示时间(6页珍藏版)》请在金锄头文库上搜索。

1、 /*将时间显示在LCD上,LCD的控制器是sed1520,可以调整,调整规律为s1键 为时分秒调整端,按一下为秒调整,按2下位分调整,按三次为时调整,按四次调整结束, 计时开始。s2,s3键为时分秒加减端,该程序通过调试,但是不是时钟芯片来控制时间。 只能是51学习之用,工业上,时钟更多是用时钟芯片,比如DS1302,PCF8563,等, 请读者注意*/#include #include #define xiezhi1 XBYTE0x8000 /*left lcd command address*/#define xieshuju1 XBYTE0x8001 /*left lcd data w

2、rite addresss*/#define duzhi1 XBYTE0x8002 /*left lcd read status address*/#define xiezhi2 XBYTE0x8004 /*right lcd write command address*/#define xieshuju2 XBYTE0x8005 /*right lcd data write addresss*/#define duzhi2 XBYTE0x8006 /*right lcd read status address*/sbit s1=P11; /*时分秒选择端*/sbit s2=P12; /*加端

3、*/sbit s3=P13 ; /*减端*/sbit beep=P10;unsigned char code tab18= 0x00,0x00,0x00,0x7E,0x81,0x81,0x81, 0x7e,0x00,0x00,0x00,0x00,0x00,0x82,0xff,0x80, /*1*/0x00,0x00,0x00,0xc6,0xa1,0x91,0x89,0xc6, /*2*/0x00,0x00,0x00,0x42,0x81,0x81,0x99,0x66,0x00,0x00,0x00,0x1f,0x10,0xff,0x10,0x10,0x00,0x00,0x00,0x4F,0x89,

4、0x89,0x89,0x79,0x00,0x00,0x00,0x7E,0x89,0x89,0x89,0x72,0x00,0x00,0x00,0x01,0x01,0xF9,0x05,0x03,0x00,0x00,0x00,0x76,0x89,0x89,0x89,0x76,0x00,0x00,0x00,0x4E,0x91,0x91,0x91,0x7E /*9*/;unsigned char code tab2=0x00,0x00,0x00, 0xcc, 0x00,0x00 ;/*LCD上冒号的编码*/unsigned char shi,fen,miao; /*定义时分秒*/unsigned cha

5、r num;unsigned int tt;unsigned char ledbuf6;void writezhi1(unsigned char command)while(duzhi1&0x80); /*先判断读状态高位是不是忙信号*/xiezhi1=command; /*左边写指令子程序*/ void writeshuju1(unsigned char shuju)while(duzhi1&0x80); /*先判断读状态高位是不是忙信号*/xieshuju1=shuju; /*左边写数据子程序*/ void writezhi2(unsigned char command) while(du

6、zhi2&0x80); /*先判断读状态高位是不是忙信号*/xiezhi2=command; /*右边写指令子程序*/ void writeshuju2(unsigned char shuju)while(duzhi2&0x80); /*先判断读状态高位是不是忙信号*/xieshuju2=shuju; /*右边写数据子程序*/ void init() writezhi1(0xe2); writezhi2(0xe2); /*复位*/ writezhi1(0xa4); writezhi2(0xa4); /*静态驱动*/ writezhi1(0xa9); writezhi2(0xa9); /*刷新率

7、为1/32*/ writezhi1(0xa0); writezhi2(0xa0); /*ADC choice*/ writezhi1(0xc0); writezhi2(0xc0); /*起始行设置*/ writezhi1(0xaf); writezhi2(0xaf); /*开显示*/ void clear() unsigned char i,j; i=0; do writezhi1(i+0xb8); writezhi2(i+0xb8); /*对左右两边LCD4页80列清零*/ writezhi1(0x00); writezhi2(0x00); j=0x50; do writeshuju1(0x

8、00); writeshuju2(0x00); while(-j!=0); while(+i!=4); void delay(unsigned char z) unsigned char x; while(-z!=0) /*按键子程序要用到的延时程序*/ for(x=100;x!=0;x-); void d1() beep=0; /*按一下调整键响一下*/ delay(20); beep=1; void key() if(s1=0) delay(5); if(s1=0) /*第一个按键判断*/ num+; while(!s1); /*等键松开*/ d1(); /*响一下*/ if(num=4)

9、 num=0; /*如果第一个按键次数到了四次,则num=0;*/ TR0=1; if(num!=0) TR0=0; /*第一个按键在四次之内,则停止计时,等待时分秒调整*/ if(s2=0) /*第二个按键为时分秒加键*/ delay(5); if(s2=0) while(!s2); /*第一个按键按下后,判断2,3键按下*/ d1(); if(num=1) /*在第一个按键按一次的情况下,按第二个键为秒加*/ miao+; if(miao=60) miao=0; if(num=2) /*在第一个按键按2次的情况下,按第二个键为分加键 */ fen+; if(fen=60) fen=0; i

10、f(num=3) /*在第一个按键按3次的情况下,按第二个键为时加键 */ shi+; if(shi=24) shi=0; if(s3=0) /*第三个按键为时分秒减键*/ delay(5); if(s3=0) while(!s3); d1(); if(num=1) /*在第一个按键按一次的情况下,按第三个键为秒减*/ miao-; if(miao=-1) miao=59; if(num=2) /*在第一个按键按2次的情况下,按第三个键为分减*/ fen-; if(fen=-1) fen=59; if(num=3) /*在第一个按键按3次的情况下,按第三个键为时减*/ shi-; if(shi

11、=-1) shi=23; void timer0() interrupt 1 tt-; if(tt=0) /*中断10000次就是一秒*/ tt=10000; miao+; /*秒加一*/ if(miao=60) miao=0; /*if second equal to 60,minute plus one,*/ fen+; if(fen=60) /*if minutes equal to 60,hour plus one*/ fen=0; shi+; if(shi=24) shi=0; /*if hour equal to 24,clear hour buffer*/ void displaylcd(unsigned char page,unsigned char column,unsigned char code_) /*在左边lcd里显示数子子程序*/ unsigned char i; writezhi1(page+0xb8); /*选择页码*/ for(i=0;i8;i+) /*一个数字有8个列显示,等于

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 其它中学文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号