话不多说,上代码
#include <ds1621.h>
void DelayMS(uint ms)
{
uchar i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
//写
void Master(uchar slave_addr)
{
if(!SCL || !SDA) //sda == 0或scl== 0;
{}
else
{
SDA = 0;
_nop_();
_nop_();
SCL = 0;
_nop_();
_nop_();
write_onebyte_iic(slave_addr);
}
}
void SetTemp(uchar HI,uchar LO)
{
Master(0x90);
write_onebyte_iic(0xa1);
write_onebyte_iic(HI);
SendStop();
DelayMS(10);
Master(0x90);
write_onebyte_iic(0xa2);
write_onebyte_iic(LO);
SendStop();
}
void StartConversion()
{
Master(0x90);
write_onebyte_iic(0xee);
SendStop();
DelayMS(750);
}
void StopConversion()
{
Master(0x90);
write_onebyte_iic(0x22);
SendStop();
DelayMS(750);
}
//读温度
uint ReadTemp()
{
uint d;
Master(0x90);
write_onebyte_iic(0xaa);
SendStop();
Master(0x91);
d = read_onebyte_iic(0);
point = read_onebyte_iic(1)>>7;
SendStop();
return d;
}
void WriteConfig(uchar c)
{
Master(0x90);
write_onebyte_iic(0xac);
write_onebyte_iic(c);
SendStop();
}
最后想要源码的,我会上传到我的资源里,自取
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/156068.html