ds12c887 时间不更新
时间:10-02
整理:3721RD
点击:
- #include<reg52.h>
- sbit lcden=P3^4;
- sbit lcdrs=P3^5;
- sbit dscs=P1^4;
- sbit dsas=P1^5;
- sbit dsrw=P1^6;
- sbit dsds=P1^7;
- char filine[14]="2015-10-18 MON";
- char seline[10]=" 00:00:00 ";
- char sec,min,hor;
- int m,n;
- int num;
- void delay(int m)
- {
- int n;
- for(;m>=0;m--)
- for(n=110;n>=0;n--);
- }
- void write_command(char com)
- {//液晶命令
- lcdrs=0;
- lcden=0;
- P0=com;
- delay(5);
- lcden=1;
- delay(5);
- lcden=0;
- }
- void write_date(char date)
- {//液晶数据
- lcdrs=1;
- lcden=0;
- P0=date;
- delay(5);
- lcden=1;
- delay(5);
- lcden=0;
- }
- /*void write_ds(char address,char date)
- {
- dscs=0;
- dsas=1;
- dsds=1;
- dsrw=0;
- P0=address;
- dsas=0;
- dsrw=0;
- P0=date;
- dsrw=1;
- dsas=1;
- dscs=1;
-
- }*/
- char read_ds(char address)
- {
- char ds_date;
- dsas=1;
- dsds=1;
- dsrw=1;
- dscs=0;
- P0=address;
- dsas=0;
- dsds=0;
- P0=0xff;
- ds_date=P0;
- dsds=1;
- dsas=1;
- dscs=1;
- return ds_date;
- }
- void init()
- {
- write_command(0x38);
- write_command(0x0c);
- write_command(0x06);
- write_command(0x01);
- write_command(0x80);
- for(m=0;m<14;m++)
- write_date(filine[m]);
- write_command(0x80+0x40);
- for(m=0;m<10;m++)
- write_date(seline[m]);
- }
- void display_number(char address,char number)
- {
- char ge,shi;
- shi=number/10;
- ge=number%10;
- write_command(0x80+0x40+address);
- write_date(0x30+shi);
- write_date(0x30+ge);
- }
- void main()
- {
- num=0;
- init();
- delay(50);
- while(1)
- {
- sec=read_ds(0);
- display_number(7,sec);
-
-
- }
- }
你调试下看看你读取回来的sec是个什么数,先确定错误出在哪里