LCD1602液晶屏+DS1302时钟芯片的电子时钟
时间:08-04
来源:互联网
点击:
程序源代码下载地址:http://www.51hei.com/f/1320dsf.rar
#includereg52.h>#define uchar unsigned char#define uint unsigned intuchar code tab1[]="DS1302";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 DS1302_xie_hs(uchar dat);void DS1302_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();}}
- 单片机定时器实现实时时钟程序-lcd1602显示(12-02)
- 单片机写LCD1602液晶程序源码(12-02)
- 单片机I2C通信及LCD1602显示C程序(12-02)
- 单片机LCD1602底层驱动子程序(12-02)
- 51单片机加HC—SR04超声波测距仪用LCD1602显示(12-02)
- PIC单片机驱动LCD1602液晶显示字符串程序(12-02)