解决库仑计初始化卡死问题
作者:互联网
解决库仑计初始化卡死问题
void write_ds2781_cmd(unsigned char cmd, unsigned char address)
{
unsigned char pres;
restart:
pres = reset();
if(pres) //return fause; // Èç¹ûûÓÐÆ÷¼þ£¬·µ»Ø0
{
delay_us(100);
goto restart;
}
write_byte(0xCC); //Ö÷»ú·¢³öSkip Net AddressÃüÁî
write_byte(cmd); // Ö÷»ú·¢³öxxÃüÁî
write_byte(address); // Ö÷»ú·¢³öµØÖ·ÃüÁî
//return ture;
}
改成
void write_ds2781_cmd(unsigned char cmd, unsigned char address)
{
unsigned char pres;
unsigned char i;
for(i=0;i<50;i++)
{
pres = reset();
if(pres) //pres=1ʱ£¬Î´¼ì²âµ½Æ÷¼þ¡£
{
delay_us(100);
}
else break; //pres=0ʱ£¬¼ì²âµ½Æ÷¼þ¡£
}
write_byte(0xCC); //Ö÷»ú·¢³öSkip Net AddressÃüÁî
write_byte(cmd); // Ö÷»ú·¢³öxxÃüÁî
write_byte(address); // Ö÷»ú·¢³öµØÖ·ÃüÁî
//return ture;
}
防止通信失败后程序卡死
标签:初始化,char,byte,cmd,unsigned,write,库仑计,卡死,pres 来源: https://blog.csdn.net/cht1999/article/details/115110337