打印
[51单片机]

用STC12C5A60S2读写DS12C887+时钟芯片

[复制链接]
1050|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ltzcode|  楼主 | 2014-6-27 14:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
用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);
  }
}

相关帖子

沙发
ayb_ice| | 2014-6-27 16:02 | 只看该作者
CS长期拉低肯定不行的

对着时序图写

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

3

帖子

0

粉丝