打印
[ZLG-ARM]

用LPC2214操作时钟芯片PCF8563碰到的问题,高手进来看下

[复制链接]
2005|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
晕中漫步|  楼主 | 2007-5-25 15:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
uint16 read_8563_realtime(void)  //ctrl_addres 是控制字段 //addres是地址                                                        
{        
   uint16  temp;
   uint16  *pt;
   pt=&temp; 
   
   if(I2C_ReadNByte (0x00, pt, 0x01))
    {
      if((*pt&0xa8)!=0)
      {
         *pt=0;
         I2C_WriteNByte(0x0C, pt, 0x01);        
         I2C_WriteNByte(0x0D, pt, 0x01);
            
         I2C_WriteNByte(0x0F, pt, 0x01);
           I2C_WriteNByte(0x00, pt, 0x01);
         I2C_WriteNByte(0x01, pt, 0x01);
         __asm{
                NOP
                NOP
                NOP
                NOP
         }
         *pt=0x81;
         I2C_WriteNByte(0x0E, pt, 0x01); 
       }
    }
    
    pt=(uint16 *)&rt_time_buf.second;
    if(I2C_ReadNByte (0x02, pt, 0x07)==0)
    {
      if(I2C_ReadNByte (0x02, pt, 0x07)==0)
      return 0;   
    }
    temp=rt_time_buf.second;
    temp=temp & 0x7f   ;        //59
    if(temp<=0x59)
    rt_time.second=temp;
    else 
    return 0;  
    
    temp=rt_time_buf.minute;
    temp=temp & 0x7f ;         //59
    if(temp<=0x59)
    rt_time.minute=temp;
    else 
    return 0;  

    temp=rt_time_buf.hour;//23
    temp=temp & 0x3f;
    if(temp<=0x23)
    rt_time.hour=temp;
     else 
    return 0;

    temp=rt_time_buf.day;//31
    temp=temp & 0x3f;
    if(temp<=0x31)
    rt_time.day=temp;
     else 
    return 0;

    temp=rt_time_buf.month;//12
    temp=temp & 0x1f;
    if(temp<=0x12)
    rt_time.month=temp& 0x1f;
     else 
    return 0;

    temp=rt_time_buf.year;   
    if(temp<=0x99)
    {  
      rt_time.year=temp;
      return 1;
    }
    else 
    return 0; 
}   

在读操作的时候I2C_ReadNByte (0x00, pt, 0x01),地址0x00读出来的数据一直是0x80,而不是设置的0x00,时间也就一直是设置进去的值,时钟芯片没有计时工作

相关帖子

沙发
晕中漫步|  楼主 | 2007-5-25 15:52 | 只看该作者

这是写操作的函数我也贴出来,高手们帮忙看看有没问题

uint16 I2C_WriteNByte(uint16 suba, uint16 *s, uint16 num)
{
    uint8 stat;
    uint16  yzh;
    uint32 timerl;
    if (num > 0)/* 如果读取的个数为0,则返回错误 */
    {    /* 设置参数 */    
        /* 子地址为单字节 */

        I2CONCLR=0x40;
        timerl=0x100;
        while(timerl)
        {
            if(timerl==1)
            break;             
            timerl--;        
        }
        /* 清除STA,SI,AA标志位 */
        I2CONCLR =     (1 << 2)|    /* AA         */
                    (1 << 3)|    /* SI         */
                    (1 << 5);    /* STA         */
        
        /* 置位STA,启动I2C总线 */
        I2CONSET =     (1 << 5)|    /* STA         */
                    (1 << 6);    /* I2CEN     */
        
        stat=00; 
        timerl=0x8000;
        while(timerl)
        {
            if(timerl==1)
            break;
            stat=I2CONSET;
            if((stat & 0x08)==0x08)
            {timerl=0;break;}
            else
            timerl--;        
        }
        if(timerl==1)
        return 0;
        stat=I2STAT;
        if(stat!=0x08)
        return 0;
        
        
        I2DAT = 0xa2;
        I2CONCLR =0x28;    
        timerl=0x80000;
        while(timerl)
        {
            if(timerl==1)
            break;
            stat=I2CONSET;            
            if((stat & 0x08)==0x08)
            {timerl=0;break;}
            else 
            timerl--;        
        }
        if(timerl==1)
        return 0;
        stat=I2STAT;
        if((stat & 0xf8)!=0x18)
        return 0;
        
            
        I2DAT = suba;    
        I2CONCLR =0x28;
        timerl=0x800000;
        while(timerl)
        {
            if(timerl==1)
            break;
            stat=I2CONSET;            
            if((stat & 0x08)==0x08)
            {timerl=0;break;}
            else 
            timerl--;        
        }
        if(timerl==1)
        return 0;        
        stat=I2STAT;
        if((stat & 0xf8)!=0x28)
        return 0;
                       
        
        I2CONCLR =0x28;        
        
        while(num>0)
        {
           stat=I2CONSET;            
           if((stat & 0x08)==0x08) 
            {
                 if(num>1)
                 {  
                      yzh=*s++;
                      I2DAT =yzh;
                      I2CONCLR = 0x28; 
                      num--;
                 }
                 else if(num==1)
                 {
                      I2CONCLR = 0x28;
                      I2CONSET = 0x50;  // 无数据发送,结束总线                          
                                        // 设置总线操作结束标志
                      num--;                      
                 }
              
             }
        }
                    
    }

    return (1);
}

使用特权

评论回复
板凳
晕中漫步|  楼主 | 2007-5-25 15:57 | 只看该作者

在线等解决

使用特权

评论回复
地板
signal7902| | 2007-5-25 16:29 | 只看该作者

可以先用gpio试验一下。

使用特权

评论回复
5
五月天| | 2007-5-27 20:26 | 只看该作者

用zlg的I2C软件包测试过可以

使用zlg的I2C软件包对8563操作,完全可以,不过那软件包能不能用在产品,需要自己判断

使用特权

评论回复
6
晕中漫步|  楼主 | 2007-5-29 14:29 | 只看该作者

问题解决

最后没办法,还是换成I2C软件包的程序,还好,用上来没问题,谢谢各位好心朋友

使用特权

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

本版积分规则

3

主题

13

帖子

1

粉丝