- #include "HX711.h"
- #include "SysTick.h"
- u32 HX711_Buffer;
- u32 weightfirst;
- s32 weightend;
- u8 Flag_Error = 0;
- #define GapValue 106.5
- void Init_HX711pin(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
- //HX711_SCK
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
-
- //HX711_DOUT
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
-
- GPIO_SetBits(GPIOC,GPIO_Pin_0);
- }
- //****************************************************
- //HX711
- //****************************************************
- u32 HX711_Read(void) //128
- {
- 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)
- {
- weightfirst = HX711_Read();
- }
- //****************************************************
- //3???
- //****************************************************
- void Get_Weight(void)
- {
- HX711_Buffer = HX711_Read();
- if(HX711_Buffer > weightfirst)
- {
- weightend = HX711_Buffer;
- weightend = weightend - weightfirst; //
-
- weightend = (s32)((float)weightend/GapValue); //最终质量
-
- }
-
- }
复制代码
代码下载:
Desktop.7z
(323.51 KB, 下载次数: 80)
|