123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include "hx711.h"
- #include "public.h"
- #define GapValue 710
- #define AlarmValue 10000
- unsigned long HX711_Buffer = 0;
- unsigned long Weight_Maopi = 0;
- long Weight_Shiwu = 0;
- void Get_Maopi(void);
- long Get_Weight(void);
- void Hx711Init(void);
- void Hx711Init(void)
- {
- HX711_DOUT_PIN_OUT();
- HX711_SCK_PIN_OUT();
- }
- unsigned long HX711_Read(void)
- {
- unsigned long count;
- unsigned int timeout=0;
- unsigned char i;
- HX711_DOUT_PIN_OUT();
- HX711_DOUT_PIN=1;
- system_delay_us(1);
- HX711_SCK_PIN=0;
- count=0;
- HX711_DOUT_PIN_IN();
- while((HX711_DOUT_PIN)&&(++timeout<3000));
- for(i=0;i<24;i++)
- {
- HX711_SCK_PIN=1;
- count=count<<1;
- HX711_SCK_PIN=0;
- HX711_DOUT_PIN_IN();
- if(HX711_DOUT_PIN)
- count++;
- }
- HX711_SCK_PIN=1;
- count=count^0x800000;
- system_delay_us(1);
- HX711_SCK_PIN=0;
- return(count);
- }
- void Get_Maopi(void)
- {
- Weight_Maopi = HX711_Read();
- }
- long Get_Weight(void)
- {
- Weight_Shiwu = HX711_Read();
- Weight_Shiwu = Weight_Shiwu - Weight_Maopi;
- if(Weight_Shiwu >= 0)
- {
- Weight_Shiwu = (unsigned long)((float)Weight_Shiwu/GapValue);
- }
- else
- {
- Weight_Shiwu = 0;
- }
- return Weight_Shiwu;
- }
|