#include "15W4KxxS4.H"
#include<intrins.h>
#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]={0x8c, 0x8a, 0x88,0x86, 0x84,0x82, 0x80};//ds1302D′μ?μ??·
uchar readadd[7]={0x8d,0x8b, 0x89, 0x87,0x85,0x83, 0x81};
//************************************************//
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&0x01;//
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++)
{
date=date>>1;
sck=0;
if(io)
date=date|0x80;
sck=1;}
rst=0;_nop_();
sck=0;_nop_();
io=1;sck=1;
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(0x8e, 0x00);/
for(i=0; i<7;i++)
{
ds1302_write(writeadd[i], writetime[i]);
}
ds1302_write(0x8e,0x80);/
}
//*************************************************//
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
{
yj1602_write_com(0x38);//
yj1602_write_com(0x0c);//
yj1602_write_com(0x06);//
yj1602_write_com(0x01);//
}
void write_1602(uchar add, uchar date)//
{
uchar shi,ge;
shi=date/16;
ge=date%16;
yj1602_write_com(0x80+add);//
yj1602_write_date(0x30+shi);
yj1602_write_date(0x30+ge);
}
void deal_with()//
{
yj1602_write_com(0x80+0);
yj1602_write_date('d');
delay(5);
yj1602_write_com(0x80+1);
yj1602_write_date('a');
delay(5);
yj1602_write_com(0x80+2);
yj1602_write_date('t');
delay(5);
yj1602_write_com(0x80+3);
yj1602_write_date('a');
delay(5);
yj1602_write_com(0x80+4);
yj1602_write_date(':');
delay(5);
write_1602(5,writetime[0]);
delay(5);
yj1602_write_com(0x80+7);
yj1602_write_date('-');
delay(5);
write_1602(8,writetime[2]);
delay(5);
yj1602_write_com(0x80+10);
yj1602_write_date('-');
delay(5);
write_1602(11,writetime[3]);
delay(5);
yj1602_write_com(0x80+0x40);
yj1602_write_date('t');
delay(5);
yj1602_write_com(0x80+0x40+1);
yj1602_write_date('i');
delay(5);
yj1602_write_com(0x80+0x40+2);
yj1602_write_date('m');
delay(5);
yj1602_write_com(0x80+0x40+3);
yj1602_write_date('e');
delay(5);
yj1602_write_com(0x80+0x40+4);
yj1602_write_date(':');
delay(5);
write_1602(0x40+5,writetime[4]);
delay(5);
yj1602_write_com(0x80+0x40+7);
yj1602_write_date(':');
delay(5);
write_1602(0x40+8,writetime[5]);
delay(5);
yj1602_write_com(0x80+0x40+10);
yj1602_write_date(':');
delay(5);
write_1602(0x40+11,writetime[6]);
yj1602_write_com(0x80+0x40+11);
delay(5);
}
//**************************************************//
void main(){
P2M1 = 0; P2M0 = 0;
P0M1 = 0; P0M0 = 0;
P1M1 = 0; P1M0 = 0;
P5M1 = 0x00; P5M0 = 0x18;
yj1602_init();
write_time();
while(1){
readtime();
deal_with();
}
}
|