Home > other >  Ds1302 Stc15 + + 1602 calendar time
Ds1302 Stc15 + + 1602 calendar time

Time:10-11

Seek advice
# include "15 w4kxxs4. H"
#include
# define uint unsigned int
# define uchar unsigned char
Sbit IO=P1 ^ 6;
Sbit SCK=P1 ^ 5;
Sbit RST=P2 ^ 5;
Sbit rs=P2 ^ 4;
Sbit rw=P2 ^ 3;
Sbit en=P2 ^ 1;
Uchar writetime []={19,1,5, 15, 9, 15, 0};
Uchar writeadd [7]={x88 x8c 0, 0 x8a, 0, 0 x86, 0 x84, 0 x82, 0 x80};
Uchar readadd [7]={x89 x8d 0, 0 x8b, 0, 0 x87, 0 x85, 0 x83, 0 x81};


//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
Void delay (uchar ms)
{
Uchar x, y;
For (x=ms; x> 0; X -)
For (y=110; Y> 0; Y -);
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//


Void ds1302_write_byte (uchar date)//
{
uchar i;
for(i=0; i<8; I++)
{
SCK=0;
IO=date& 0 x01;//
The date=date> 1;
SCK=1; }
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
Void ds1302_write (uchar add, uchar date)/
{
RST=0; _nop_();//?????? 3 ¨
SCK=0; _nop_();
RST=1; _nop_();
Ds1302_write_byte (add);
Ds1302_write_byte (date);
RST=0; _nop_();
SCK=0; _nop_();
IO=1; SCK=1;
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
Uchar ds1302_read uchar (add)
{
Uchar I, date;
RST=0; _nop_();
SCK=0; _nop_();
RST=1; _nop_();
Ds1302_write_byte (add);
for(i=0; i<8; I++)
{
The date=date> 1;
SCK=0;
If (IO)
The date=date | 0 x80;
SCK=1; }
RST=0; _nop_();
SCK=0; _nop_();
IO=1; SCK=1;
The return date.
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
Void write_time ()//
{
Uchar I, j, k;
for(i=0; i<7. I++) {
J=writetime [I]/10;
K=writetime [I] % 10;
Writetime [I]=j * 16 + k;
}
Ds1302_write (0 x8e, 0 x00);
for(i=0; i<7. I++)
{
Writetime ds1302_write (writeadd [I], [I]);
}
Ds1302_write (0 x8e, 0 x80);
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
Void readtime ()/
{
uchar i;
for(i=0; i<7. I++)
{writetime [I]=ds1302_read (readadd [I]);//* * *
}
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
Void yj1602_write_com uchar (com)//
{

En=0; Delay (1);
En=1; Delay (1);
Rs=0; Delay (1);
Rw=0; Delay (1);
P0=com;
En=0; Delay (1); }


Void yj1602_write_date (uchar date)/
En=0; Delay (1);
En=1; Delay (1);
Rs=1; Delay (1);
Rw=0; Delay (1);
P0=date;
En=0; Delay (1);
}


Void yj1602_init ()//1
{
X38 yj1602_write_com (0);//
X0c yj1602_write_com (0);//
Yj1602_write_com x06 (0);//
Yj1602_write_com (0 x01);//
}
Void write_1602 (uchar add, uchar date)//
{
Uchar shi ge;
Shi=date/16;
Ge=16 date %;
Yj1602_write_com (0 x80 + add);//
Yj1602_write_date (0 x30 + shi);
Yj1602_write_date (0 x30 + ge);
}
Void deal_with ()//
{
Yj1602_write_com (0 x80 + 0);
Yj1602_write_date (' d ');
Delay (5);
Yj1602_write_com (0 x80 + 1);
Yj1602_write_date (' a ');
Delay (5);
Yj1602_write_com (0 x80 + 2);
Yj1602_write_date (' t ');
Delay (5);
Yj1602_write_com (0 x80 + 3);
Yj1602_write_date (' a ');
Delay (5);
Yj1602_write_com (0 x80 + 4);
Yj1602_write_date (', ');
Delay (5);
Write_1602 (5, writetime [0]);
Delay (5);
Yj1602_write_com (0 x80 + 7);
Yj1602_write_date (' - ');
Delay (5);
Write_1602 (8, writetime [2]);
Delay (5);
Yj1602_write_com (0 x80 + 10);
Yj1602_write_date (' - ');
Delay (5);
Write_1602 (11, writetime [3]);
Delay (5);
Yj1602_write_com (0 x80 + 0 x40);
Yj1602_write_date (' t ');
Delay (5);
Yj1602_write_com (0 x80 + 0 x40 + 1);
Yj1602_write_date (' I ');
Delay (5);
Yj1602_write_com (0 x80 + 0 x40 + 2);
Yj1602_write_date (" m ");
Delay (5);
Yj1602_write_com (0 x80 + 0 x40 + 3);
Yj1602_write_date (' e ');
Delay (5);
Yj1602_write_com (0 x80 + 0 x40 + 4);
Yj1602_write_date (', ');
Delay (5);
Write_1602 (0 x40 + 5, writetime [4]);
Delay (5);
Yj1602_write_com (0 x80 + 0 x40 + 7);
Yj1602_write_date (', ');
Delay (5);
Write_1602 (0 x40 + 8, writetime [5]);
Delay (5);
Yj1602_write_com (0 x80 + 0 x40 + 10);
Yj1602_write_date (', ');
Delay (5);
Write_1602 (0 x40 + 11, writetime [6]);
Yj1602_write_com (0 x80 + 0 x40 + 11);
Delay (5);
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
Void main () {
P2M1=0; P2M0=0;
P0M1=0; P0M0=0;
P1M1=0; P1M0=0;
P5M1=0 x00; P5M0=0 x18;


Yj1602_init ();
Write_time ();
While (1) {
Readtime ();
Deal_with ();
}
}

CodePudding user response:

Check whether the DS1302 crystals have start up, 32768 crystals seems to be difficult to start up

CodePudding user response:

Check the crystals, there is no clock time natural won't go away
  • Related