我在使用hx711模块配置成功后,每次读取完重量拿走后都会显示上一次测量结果的后几个数字,怎么让它实时刷新数据并且让后面的数字消失掉啊
求解!!!
读取东西时
拿走东西后
/************************************************************************************
主程序
*************************************************************************************/
#include "stm32f10x.h"
#include "delay.h"
#include "HX711.h"
#include "sys.h"
#include "iic.h"
#include "oled.h"
#include "word.h"
#include "usart.h"
#include "hx711.h"
u8 outstr[32];
int main(void)
{
Init_HX711pin();
delay_init();
NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
// uart_init(9600); //串口初始化为9600
Get_Maopi(); //称毛皮重量
delay_ms(1000);
Get_Maopi(); //重新获取毛皮重量
OLED_Init(); //OLED显示屏初始化
while(1)
{
Get_Weight();
sprintf((char*)outstr,"重量:%dg",Weight_Shiwu);//重量显示模块
OLED_DisplayString(0,0,16,16,outstr);
delay_ms(1000);
// OLED_Refresh_Screen();
}
}
/************************************************************************************
HX711模块程序
*************************************************************************************/
#include "HX711.h"
#include "delay.h"
u32 HX711_Buffer;
u32 Weight_Maopi;
s32 Weight_Shiwu;
u8 Flag_Error = 0;
//校准参数
//因为不同的传感器特性曲线不是很一致,因此,每一个传感器需要矫正这里这个参数才能使测量值很准确。
//当发现测试出来的重量偏大时,增加该数值。
//如果测试出来的重量偏小时,减小改数值。
//该值可以为小数
#define GapValue 586
void Init_HX711pin(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); //使能PF端口时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB , ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);
//HX711_SCK PB3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // 端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //根据设定参数初始化GPIOB
//HX711_DOUT PA4
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//输入上拉
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOB,GPIO_Pin_3); //初始化设置为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;//第25个脉冲下降沿来时,转换数据
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; //获取实物的AD采样数值。
Weight_Shiwu = (s32)((float)Weight_Shiwu/GapValue); //计算实物的实际重量
//因为不同的传感器特性曲线不一样,因此,每一个传感器需要矫正这里的GapValue这个除数。
//当发现测试出来的重量偏大时,增加该数值。
//如果测试出来的重量偏小时,减小改数值。
}
}
|