话不多说,上代码
#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)
{}
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();
}
最后想要源码的,我会上传到我的资源里,自取
|