#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]=" 2007-01-01 MON";
uchar code table1[]=" 00:00:00";
sbit select=P1^0;
sbit add=P1^1;
sbit minus=P1^2;
sbit kk=P1^4;
sbit RS=P2^5;
sbit RW=P2^6;
sbit E=P2^7;
sbit sclk=P1^6;
sbit io=P3^5;
sbit res=P1^7;
sbit ACC0=ACC^0;
char shi,fen,miao;
uchar count,m;
void delay(uint z)
{
uint x,y;
for(x=110;x>0;x--)
for(y=z;y>0;y--);
}
void wcom(uchar com)
{
RS=0;
P0=com;
delay(1);
E=1;
delay(1);
E=0;
}
void wdata(uchar date)
{
RS=1;
P0=date;
delay(1);
E=1;
delay(1);
E=0;
}
void inint()
{
uchar a,b;
kk=0;
RW=0;
E=0;
wcom(0x38);
wcom(0x0c);
wcom(0x06);
wcom(1);
wcom(0x80+0x01);
for(a=0;a<15;a++)
{
wdata(table[a]);
delay(1);
}
wcom(0x80+0x40+0x03);
for(b=0;b<10;b++)
{
wdata(table1[b]);
delay(1);
}
}
void
timetrends(uchar address,uchar dong)
{
uchar ge,sh;
sh=dong/10;
ge=dong%10;
wcom(0x80+0x40+address);
wdata(0x30+sh);
wdata(0x30+ge);
}
void wds1302(uchar date)
{
uchar i,j;
res=0;
sclk=0;
res=1;
io=1;
j=date;
for(i=8;i>0;i--)
{
sclk=0;
io=(j&0x01);
delay(1);
sclk=1;
j=j>>1;
}
}
void rds1302()
{
uchar k,qq;
m=0;
for(k=8;k>0;k--)
{
sclk=1;
delay(1);
sclk=0;
qq=io;
if(qq==1)
m=m|0x01;
else m=m&0xfe;
m=m<<1;
}
miao=m;
}
void main()
{
inint();
while(1)
{
wds1302(0x89);
rds1302();
timetrends(11,miao);
}
}
在这只调试下读取 但是读不出来 不知道哪错了
帮忙看下 LCD显示没什么问题 就是DS1302的写入和读取的问题
一周热门 更多>