12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #include "HX711.h"
- #include "delay.h"
- u32 HX711_Buffer;
- u32 Weight_Maopi;
- s32 Weight_Shiwu;
- u8 Flag_Error = 0;
- #define GapValue 490
- void Init_HX711pin(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- GPIO_SetBits(GPIOB,GPIO_Pin_12);
- }
- u32 HX711_Read(void)
- {
- unsigned long count;
- unsigned char i;
- HX711_DOUT=1;
- delay_us(1);
- HX711_SCK=0;
- count=0;
- while(HX711_DOUT);
- for(i=0;i<24;i++)
- {
- HX711_SCK=1;
- count=count<<1;
- delay_us(1);
- HX711_SCK=0;
- if(HX711_DOUT)
- count++;
- delay_us(1);
- }
- HX711_SCK=1;
- count=count^0x800000;
- delay_us(1);
- HX711_SCK=0;
- return(count);
- }
- void Get_Maopi(void)
- {
- Weight_Maopi = HX711_Read();
- }
- void Get_Weight(void)
- {
- HX711_Buffer = HX711_Read();
- if(HX711_Buffer > Weight_Maopi)
- {
- Weight_Shiwu = HX711_Buffer;
- Weight_Shiwu = Weight_Shiwu - Weight_Maopi;
-
- Weight_Shiwu = (s32)((float)Weight_Shiwu/GapValue);
-
-
-
- }
-
- }
|