extern unsigned long HX711_Buffer=0;
extern unsigned long Weight_Maopi=0,Weight_Shiwu=0;
void PORT_Init(void)
{
P3SEL &=~ (BIT4+BIT5);
P3DIR &=~ BIT4;//SDA
P3DIR |= BIT5;//SCK
}
void Delay_hx711_us(uint t)
{
_NOP();
_NOP();
while(t--);
}
unsigned long HX711_Read(void)
{
unsigned long count;
unsigned char i;
P3OUT |= BIT4;
Delay_hx711_us(4);
P3OUT &=~ BIT5;/
count=0;
while( P3IN&BIT4 );
for(i=0;i<24;i++)
{
P3OUT |= BIT5;
count=count<<1;
P3OUT &=~ BIT5;
if(P3IN&BIT4)
count++;
}
P3OUT |= BIT5;
Delay_hx711_us(4);
count=count^0x800000;
P3OUT &=~ BIT5;
return(count);
}
unsigned long Get_Maopi()
{
HX711_Buffer=HX711_Read();//HX711_Read()中的数不变化???
Weight_Maopi=HX711_Buffer/100;
return Weight_Maopi;
}
unsigned long Get_Weight()
{
HX711_Buffer=HX711_Read();
HX711_Buffer=HX711_Buffer/100;
//这个放在主程序之中,没有放进while中!!!
if(HX711_Buffer>=Get_Maopi())
{
Weight_Shiwu=HX711_Buffer;
Weight_Shiwu=Weight_Shiwu-Get_Maopi();
Weight_Shiwu=(unsigned long)((float)Weight_Shiwu/4.3+0.05);
return Weight_Shiwu;
}
else
return 1;
}
求各位看看哪有错误,小弟感激不尽。
为什么显示出来的是静态值????用的是msp430f149的单片机
|