导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→为何PCF8583不计时?[loverss]

 *第11117篇: 为何PCF8583不计时?

  
楼 主:loverss 2003年4月28日08:18
 为何PCF8583不计时?
小弟想用AT89C51去控制PCF8583,读写PCF8583都可以且正确,但不管隔多久时间,读出来的值总是我写进去的值,换句话说,PCF8583没有计时(我在PCF8583的00H单元写的是00H),请问各位大虾,是否我用错了晶振?正确的晶振应该是32.768KHZ,但我的晶振上只写了32768,请指教!
  
2楼:荒原野草 2003年4月28日09:15
 晶振没错
再检查一下你的程序,有以下可能:
1:晶振没有启振.(可能性不是很大)
2:程序有错误,从你的现象看,很有可能是操作地址出错了,你读写了ram区.
  
3楼:loverss 2003年4月28日09:43
 我读写的是00H到07H 单元,没错啊
我读写的是00H到07H 单元,没错啊
  
4楼:荒原野草 2003年4月28日09:57
 给你段例程,仅供参考
sbit scl=0x96;
sbit sda=0x97;
sbit a0=0xe0;  //定义ACC
sbit a1=0xe1;
sbit a2=0xe2;
sbit a3=0xe3;
sbit a4=0xe4;
sbit a5=0xe5;
sbit a6=0xe6;
sbit a7=0xe7;

sbit b0=0xf0;  //定义B
sbit b1=0xf1;
sbit b2=0xf2;
sbit b3=0xf3;
sbit b4=0xf4;
sbit b5=0xf5;
sbit b6=0xf6;
sbit b7=0xf7;
struct time
{
 unsigned char year,month,week,day,hour,min,sec;
} today;

void s24(void)
{
 sda=1;_nop_();
 scl=1;_nop_();
 sda=0;_nop_();
 scl=0;

void p24(void)
{
 sda=0;_nop_();
 scl=1;_nop_();
 sda=1;_nop_();
}

void ask24(void)
{
 sda=0;_nop_();
 scl=1;_nop_();
 scl=0;_nop_();
}

unsigned char rd24(void)
{
 sda=1;scl=0;
 scl=1;a7=sda;scl=0;
 scl=1;a6=sda;scl=0;
 scl=1;a5=sda;scl=0;
 scl=1;a4=sda;scl=0;
 scl=1;a3=sda;scl=0;
 scl=1;a2=sda;scl=0;
 scl=1;a1=sda;scl=0;
 scl=1;a0=sda;scl=0;
 return(ACC);
}
void wd24(unsigned char dd)
{
 B=dd;
 sda=b7;scl=1;scl=0;
 sda=b6;scl=1;scl=0;
 sda=b5;scl=1;scl=0;
 sda=b4;scl=1;scl=0;
 sda=b3;scl=1;scl=0;
 sda=b2;scl=1;scl=0;
 sda=b1;scl=1;scl=0;
 sda=b0;scl=1;scl=0;
 sda=1; scl=1;
 
  while(sda);
  scl=0;
}

unsigned char rdone(unsigned char add) //从add读1个数据
{
 unsigned char dat;
 s24();
 wd24(0xa0); //从机地址
 wd24(add);
 s24();
 wd24(0xa1);
 dat=rd24();
 p24();
 return(dat);
}

void wrone(unsigned char add,unsigned char dat)
{
 s24();
 wd24(0xa0);
 wd24(add);
 wd24(dat);
 p24();
 soft_20ms();
}

void ReadClock(void)
{
  unsigned char temp[5];
  unsigned char i;
  s24();
  wd24(0xa0);
  wd24(0x02);
  s24();
  wd24(0xa1);
  for(i=0;i  <4;i++)
  {
    temp[i]=rd24();
    ask24();
  }
  temp[4]=rd24();
  p24();
  today.sec=((temp[0]&0xf0)>  >  4)*10+(temp[0]&0x0f);
  today.min=((temp[1]&0xf0)>  >  4)*10+(temp[1]&0x0f);
  today.hour=((temp[2]&0x30)>  >  4)*10+(temp[2]&0x0f);
  today.day=((temp[3]&0x30)>  >  4)*10+(temp[3]&0x0f);
  today.week=(temp[4]&0xe0)>  >  5;
  today.month=((temp[4]&0x10)>  >  4)*10+(temp[4]&0x0f);
//  today.year=(temp[3]&0xc0)>  >  6;
  today.year=rdone(0x0f);
}

void SetClock(void)
{
 char temp[5];

 temp[0]=(today.sec/10  <  <4)+today.sec%10;
 temp[1]=(today.min/10  <  <4)+today.min%10;
 temp[2]=(today.hour/10  <  <4)+today.hour%10;
 temp[3]=(today.day/10  <  <4)+today.day%10+((today.year%3)  <  <6);
 temp[4]=(today.month/10  <  <4)+today.month%10+(today.week  <  <5);
 wrone(0x0f,today.year);
 s24();
 wd24(0xa0);
 wd24(02);
 wd24(temp[0]);
 wd24(temp[1]);
 wd24(temp[2]);
 wd24(temp[3]);
 wd24(temp[4]);
 p24();
 soft_20ms();
}

void main(void)
{
.........
  today.sec=0;
  today.min=0;
  today.hour=0;
  today.day=0;
  today.week=0;
  today.month=0;
  today.year=0;

  wrone(0x00,0x00);
  wrone(0x08,0x90);
............
}


>>>>>>对该主题发表你的看法

本主题贴数4,分页: [第1页]


[上一篇主题]:向大家推荐一个很好的 MCU BBS   即时在线

[下一篇主题]:pic烧录问题!!!