新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > LCD1602液晶屏+DS1302时钟芯片的电子时钟

LCD1602液晶屏+DS1302时钟芯片的电子时钟

作者:时间:2012-08-04来源:网络收藏

点击浏览下一页
程序源代码下载地址:http://www.51hei.com/f/1320dsf.rar

#includereg52.h>#define uchar unsigned char#define uint unsigned intuchar code tab1[]="";uchar code tab2[]="Week-";uchar code tab3[]="0123456789";uchar xdw[13];sbit SCK=P2^0;sbit AB=P2^1;sbit RS=P2^2;sbit RW=P2^3;sbit EN=P2^4;sbit RST=P2^5;sbit SCLK=P2^6;sbit DS=P2^7;void _xie_hs(uchar dat);void _xie_1byte(uchar add,uchar tdat);uchar DS1302_du_hs(void);uchar DS1302_du_1byte(uchar add);void LCM1602_xie_cmd_hs(uchar cmd);void LCM1602_xie_dat_hs(uchar dat);void display();void dushuju();void inti();void delay(uint z);void DS1302_xie_hs(uchar dat){uint i,num;num=dat;for(i=0;i8;i++){DS=(bit)(num0x01);SCLK=1;SCLK=0;num>>=1;}}void DS1302_xie_1byte(uchar add,uchar tdat){RST=0;SCLK=0;RST=1;DS1302_xie_hs(add);DS1302_xie_hs(tdat);SCLK=1;RST=0;}uchar DS1302_du_hs(void){uchar i,num;for(i=0;i8;i++){num>>=1;if(DS)num|=0x80;SCLK=1;SCLK=0;}return(num);}uchar DS1302_du_1byte(uchar add){uchar tmp;RST=0;SCLK=0;RST=1;DS1302_xie_hs(add);tmp=DS1302_du_hs();SCLK=1;RST=0;return(tmp);}void LCM1602_xie_cmd_hs(uchar cmd){uchar i,num;RS=0;RW=0;EN=0;RS=0;RW=0;EN=1;num=cmd;for(i=0;i8;i++){AB=(bit)(num0x01);SCK=0;SCK=1;num>>=1;}EN=0;}void LCM1602_xie_dat_hs(uchar dat){uchar i,num;RS=0;RW=0;EN=0;RS=1;RW=0;EN=1;num=dat;for(i=0;i8;i++){AB=(bit)(num0x01);SCK=0;SCK=1;num>>=1;}EN=0;}void display(){uchar i,j,tmp;LCM1602_xie_cmd_hs(0x80+0x08);for(i=0;i3;i++){for(j=0;j2;j++){LCM1602_xie_dat_hs(tab3[xdw[i*2+j]]);delay(2);}}}void delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void inti(){RS=0;RW=0;EN=0;SCLK=0;LCM1602_xie_cmd_hs(0x38);LCM1602_xie_cmd_hs(0x0c);LCM1602_xie_cmd_hs(0x06);DS1302_xie_1byte(0x8e,0x00);DS1302_xie_1byte(0x80,0x00);DS1302_xie_1byte(0x82,0x29);DS1302_xie_1byte(0x84,0x22);DS1302_xie_1byte(0x86,0x24);DS1302_xie_1byte(0x88,0x01);DS1302_xie_1byte(0x8a,0x02);DS1302_xie_1byte(0x8c,0x12);DS1302_xie_1byte(0x8e,0x80);}void dushuju(){uchar seg;seg=DS1302_du_1byte(0x8d);xdw[0]=seg>>4;xdw[1]=seg0x0f;seg=DS1302_du_1byte(0x89);xdw[2]=seg>>4;xdw[3]=seg0x0f;seg=DS1302_du_1byte(0x87);xdw[4]=seg>>4;xdw[5]=seg0x0f;seg=DS1302_du_1byte(0x85);xdw[6]=seg>>4;xdw[7]=seg0x0f;seg=DS1302_du_1byte(0x83);xdw[8]=seg>>4;xdw[9]=seg0x0f;seg=DS1302_du_1byte(0x81);xdw[10]=seg>>4;xdw[11]=seg0x0f;seg=DS1302_du_1byte(0x8b);xdw[12]=seg0x0f;}void main(){inti();while(1){dushuju();display();}}


评论


相关推荐

技术专区

关闭