RT,本人按照那个RTC的时序来写的程序,死活读不了时钟的数据,网上基本上全是51驱动的这个芯片,不知道哪位用stm32驱动过这个片子,求解答!!!以下是本人写的读写函数
//写DS12C887函数
void write_ds(unsigned char add,unsigned char date)
{
dscs = 0;
dsas = 0;
dsds = 1;
dsrw = 1;
wad0 = (add & 0x01); //先写地址
wad1 = ((add & 0x02) >>1);
wad2 = ((add & 0x04) >>2);
wad3 = ((add & 0x08) >>3);
wad4 = ((add & 0x10) >>4);
wad5 = ((add & 0x20) >>5);
wad6 = ((add & 0x40) >>6);
wad7 = ((add & 0x80) >>7);
dsas = 1;
dsrw = 0;
wad0 = (date & 0x01); //再写数据
wad1 = ((date & 0x02) >>1);
wad2 = ((date & 0x04) >>2);
wad3 = ((date & 0x08) >>3);
wad4 = ((date & 0x10) >>4);
wad5 = ((date & 0x20) >>5);
wad6 = ((date & 0x40) >>6);
wad7 = ((date & 0x80) >>7);
dsrw = 1;
dsas = 0;
dscs = 1;
}
//读DS12C887函数
unsigned char read_ds(unsigned char add)
{
unsigned char ds_date;
unsigned char d1;
unsigned char d2;
unsigned char d3;
unsigned char d4;
unsigned char d5;
unsigned char d6;
unsigned char d7;
unsigned char d8;
dscs = 0;
dsas = 0;
dsds = 1;
dsrw = 1;
wad0 = (add & 0x01); //先写地址
wad1 = ((add & 0x02) >>1);
wad2 = ((add & 0x04) >>2);
wad3 = ((add & 0x08) >>3);
wad4 = ((add & 0x10) >>4);
wad5 = ((add & 0x20) >>5);
wad6 = ((add & 0x40) >>6);
wad7 = ((add & 0x80) >>7);
dsas = 1;
dsds = 0;
d1 = (rad7 << 7);
d2 = (rad6 << 6);
d3 = (rad5 << 5);
d4 = (rad4 << 4);
d5 = (rad3 << 3);
d6 = (rad2 << 2);
d7 = (rad1 << 1);
d8 = rad0 ;
ds_date = (d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8);//再读数据
dsds = 1;
dsas = 0;
dscs = 1;
return ds_date;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
他是用的51,我用的stm32,我就是按照他那个移植的,就是不管用…
---------------------------------
没用过
请问lz硬件上stm32驱动ds12c887,选用的IO口还是外部总线,能否推荐下硬件如何设计,谢谢
一周热门 更多>