#include<reg51.h>
#include<absacc.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit T_CLK=P1^3;
sbit T_IO=P1^4;
sbit T_RST=P1^2;
sbit RS=P1^7;
sbit RW=P1^6;
sbit EN=P1^5;
sbit ACC7=ACC^7;
sbit ACC0=ACC^0;
uchar datechar[]={"DATA:"};
uchar timechar[]={"TIME:"};
uchar datebuffer[10]={0x32,0x30,0,0,0x2d,0,0,0x2d,0,0};
uchar timebuffer[8]={0,0,0x3a,0,0,0x3a,0,0};
uchar weekbuffer={0x3a};
void writeb(uchar ucda)
{
uchar i;
ACC=ucda;
for(i=8;i>0;i--)
{
T_IO=ACC0;
T_CLK=1;
T_CLK=0;
ACC>>1;
}
}
uchar readb()
{
uchar i;
for(i=8;i>0;i--)
{
ACC=ACC>>1;
ACC7=T_IO;T_CLK=1;T_CLK=0;
}
return(ACC);
}
void v_w1302(uchar ucaddr,uchar ucda)
{
T_RST=0;
T_CLK=0;
_nop_();
_nop_();
T_RST=1;
_nop_();
_nop_();
writeb(ucaddr);
writeb(ucda);
T_CLK=1;
T_RST=0;
}
uchar uc_r1302(uchar ucaddr)
{
uchar ucda=0;
T_RST=0;T_CLK=0;
T_RST=1;
writeb(ucaddr);
ucda=readb();
T_CLK=1;T_RST=0;
return(ucda);
}
void fbuzy()
{
P2=0xff;
RS=0;
RW=1;
EN=1;
EN=0;
while((P2&0x80))
{
EN=0;
EN=1;
}
}
void wc51r(uchar j)
{
fbuzy();
EN=0;
RS=0;
RW=0;
EN=1;
P2=j;
EN=0;}
void wc51ddr(uchar j)
{
fbuzy();
EN=0;
RS=1;
RW=0;
EN=1;
P2=j;
EN=0;
}
void init()
{
wc51r(0x01);
wc51r(0x38);
wc51r(0x0c);
wc51r(0x06);
}
void delay(uint i)
{
uint y,j;
for(j=0;j<i;j++){
for(y=0;y<0xff;y++){;}
}
}
void main()
{
uchar i;
uchar data temp;
SP=0x50;
delay(10);
init();
wc51r(0x80);
for(i=0;i<5;i++)
wc51ddr(datechar[i]);
wc51r(0xc0);
for(i=0;i<5;i++)
wc51ddr(timechar[i]);
wc51r(0xc0);
v_w1302(0x8e,0);
v_w1302(0x8c,0x19);
v_w1302(0x8a,0x06);
v_w1302(0x88,0x05);
v_w1302(0x86,0x21);
v_w1302(0x84,0x21);
v_w1302(0x82,0x00);
v_w1302(0x80,0x00);
v_w1302(0x8e,0x00);
while(1)
{
temp=uc_r1302(0x8d);
datebuffer[2]=0x30+temp/16;
datebuffer[3]=0x30+temp%16;
temp=uc_r1302(0x89);
datebuffer[5]=0x30+temp/16;
datebuffer[6]=0x30+temp%16;
temp=uc_r1302(0x87);
datebuffer[8]=0x30+temp/16;
datebuffer[9]=0x30+temp%16;
temp=uc_r1302(0x85);
temp=temp&0x7f;
timebuffer[0]=0x30+temp/16;
timebuffer[1]=0x30+temp%16;
temp=uc_r1302(0x83);
timebuffer[3]=0x30+temp/16;
timebuffer[4]=0x30+temp%16;
temp=uc_r1302(0x81);
temp=temp&0x7f;
timebuffer[6]=0x30+temp/16;
timebuffer[7]=0x30+temp%16;
wc51r(0x86);
for(i=0;i<10;i++)
wc51ddr(datebuffer[i]);
wc51r(0xc6);
for(i=0;i<8;i++)
wc51ddr(timebuffer[i]);
wc51r(0x20); }
哪里出错了??
|