上传者: guoruibin123
|
上传时间: 2022-01-28 14:04:12
|
文件大小: 7.46MB
|
文件类型: ZIP
STM32单片机读写24位ADC_AD7190称重模块带液晶显示例程DEMO源码文件,可做为你的学习设计参考。
int main(void)
{
uint32_t lcdid;
float data_temp;
int32_t weight_count;
uint8_t cali_flag=0;
char str[50];
/* 复位所有外设,初始化Flash接口和系统滴答定时器 */
HAL_Init();
/* 配置系统时钟 */
SystemClock_Config();
/* 初始化串口并配置串口中断优先级 */
MX_DEBUG_USART_Init();
KEY_GPIO_Init();
/* 初始化3.5寸TFT液晶模组,一般优先于调试串口初始化 */
lcdid=BSP_LCD_Init();
/* 调用格式化输出函数打印输出数据 */
printf("LCD ID=0x%08X\n",lcdid);
LCD_Clear(0,0,LCD_DEFAULT_WIDTH,LCD_DEFAULT_HEIGTH,BLACK);
HAL_Delay(1000);
/* 开背光 */
LCD_BK_ON();
if(AD7190_Init()==0)
{
printf("获取不到 AD7190 !\n");
while(1)
{
HAL_Delay(1000);
if(AD7190_Init())
break;
}
}
printf("检测到 AD7190 !\n");
weight_ad7190_conf();
HAL_Delay(500);
weight_Zero_Data = weight_ad7190_ReadAvg(6);
printf("zero:%d\n",weight_Zero_Data);
/* 无限循环 */
while (1)
{
weight_count=weight_ad7190_ReadAvg(6);
data_temp=weight_count-weight_Zero_Data;
weight=data_temp*1000/weight_proportion;
printf("重量:0x%5X->%f\n",weight_count,weight);
sprintf(str,"0x%5X",weight_count);
LCD_DispString_EN(190,80,str,BLACK,RED,USE_FONT_24);
sprintf(str,"%0.2fg",weight);
LCD_Clear(140,100,300,64,BLACK);
LCD_DispString_EN(140,100,str,BLACK,YELLOW,USE_FONT_64);
HAL_Delay(100);
if(KEY1_StateRead()==KEY_DOWN) // 清零
{
weight_Zero_Data = weight_ad7190_ReadAvg(6);
printf("zero:%d\n",weight_Zero_Data);
cali_flag=1;
}
if(KEY2_StateRead()==KEY_DOWN) // 校准:必须先按“清零”键,然后把20g砝码放在称上,按下校准键
{
if(cali_flag)
{
weight_count = weight_ad7190_ReadAvg(6);
weight_proportion=(weight_count-weight_Zero_Data)*1000/100;
printf("weight_proportion:%d\n",weight_proportion);
}
cali_flag=0;
}
}