| 用stc12C5A60S2做DS12C887+ 时钟,用途是给系统一个显示时间和计算时间间隔; 现在问题是读到的数据总是0xFF,越容易就越能忽略细节,哪里出问题?
 sbit CS=P4^6;
 sbit AS=P1^4;
 sbit RW=P4^5;
 sbit DS=P4^4;
 /***********地址数据用P2口**********/
 /*void Delay1us()                //@11.0592MHz
 {
 _nop_();
 _nop_();
 _nop_();
 }  */
 
 char read( char add)
 {
 /*char temp;
 as=0;
 ds=1;
 wr=1;
 cs=0;
 Delay1us();
 as=1;
 Delay1us();
 P2=add;
 Delay1us();
 as=0;
 Delay1us();
 ds=0;
 Delay1us();
 P2=0xff;
 temp=P2;
 Delay1us();
 ds=1;
 Delay1us();
 as=1;
 cs=1;
 return temp;  */
 
 char ds_dat;
 AS=1;
 DS=1;
 RW=1;
 P2=add;
 AS=0;
 DS=0;
 P2=0XFF;
 ds_dat=P2;
 DS=1;
 AS=1;
 RW=1;
 return(ds_dat);
 }
 
 void write( char add,char dat)
 {
 /*as=0;
 ds=1;
 wr=1;
 cs=0;
 Delay1us();
 as=1;
 Delay1us();
 P2=add;
 Delay1us();
 as=0;
 Delay1us();
 wr=0;
 Delay1us();
 P2=dat;
 Delay1us();
 wr=1;
 Delay1us();
 as=1;
 cs=1;*/
 
 AS=1;
 DS=1;
 RW=1;
 P2=add;
 AS=0;
 RW=0;
 P2=dat;
 AS=1;
 DS=1;
 RW=1;
 }
 
 void main()
 {
 int i;
 intUart2();
 intUart1();
 CS=0;
 write(0x0A,0x20);          //打开振荡器
 write(0x0B,0x26);           //设置24小时模式,数据二进制格式,开启闹钟中断
 write(0,0);                           //初始时间函数
 write(1,0);
 write(2,0);
 write(3,0);
 write(4,0);
 write(5,0);
 write(6,0);
 write(7,0);
 write(8,0);
 write(9,0);
 
 //read(0x0C);
 //read(0x0D);
 while(1)
 {
 Delay500ms();
 Delay500ms();
 i=read(0x00);
 SendData1(i);
 }
 }
 |