STM32F103称重模块HX711调试
#include "sys_init.h"
unsigned long HX711_Buffer = 0;
unsigned long Weight_Maopi = 0,Weight_Shiwu = 0;
void Get_Maopi()
{
HX711_Buffer = HX711_Read();
Weight_Maopi = HX711_Buffer/100;
}
void Get_Weight()
{
HX711_Buffer = HX711_Read();
HX711_Buffer = HX711_Buffer/100;
if(HX711_Buffer > Weight_Maopi)
{
Weight_Shiwu = HX711_Buffer;
Weight_Shiwu = Weight_Shiwu - Weight_Maopi; //获取实物的AD采样数值。
//1标准大气压=0.1MPa[兆帕] 1工程大气压≈1Kgf/cm^2[千克力/平方厘米]
//压力测试最小气压为0.2MPa。
if(Weight_Shiwu>400)//修改测量实物的最小触发重量值。
{
printf("得到的重量%dg\r\n",Weight_Shiwu);
}
}
}
void sys_init(void)
{
delay_init(); //延时函数初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// 设置中断优先级分组2
uart_init(9600); //串口初始化为9600
ADInit() ;//初始化
Get_Maopi();//获取毛皮的重量
}
1