谢谢,根据作者提供的思路,我简单修改了官方的驱动增加了DOUT的判断,确保每次都为DOUT刚就绪时读取,使用在51单片机上,稳定。具体如下:
#include "hx711.h"
//ADSK_CH1 为SCK
//ADDO_CH1为DOUT
unsigned long ReadCount(void)
{
unsigned long Count;
unsigned char i;
ADSK_CH1=0;
Count=0;
//------------确保每次都为刚准备好的数据---------------//
if(ADDO_CH1)
{
while(ADDO_CH1);
}
else
{
while(!ADDO_CH1);
while(ADDO_CH1);
}
//-----------------------------------------------------//
for (i=0;i<24;i++)
{
ADSK_CH1=1;
Count=Count<<1;
ADSK_CH1=0;
if(ADDO_CH1) Count++;
}
ADSK_CH1=1;
Count=Count^0x800000;
ADSK_CH1=0;
return(Count);
}