可去皮,重量微调,语音播报重量。
单片机源程序如下:
- #include "main.h"
- #include "LCD1602.h"
- #include "HX711.h"
- //#include"eeprom.h"
- unsigned long HX711_Buffer = 0;
- unsigned int Weight_Maopi = 0,Weight_Shiwu = 0;
- char Price_Count = 0;
- unsigned char KEY_NUM = 0;
- unsigned char Price_Buffer[3] = {0x00,0x00,0x00};
- unsigned long Money = 0;
- bit Flag_OK = 0;
- unsigned int Weight=10,s1num=0; //报警值初始化 按键计数标志
- float m__1=2.90;
- //语音播报程序
- sbit MUSIC_REST =P2^2;//语音芯片复位脚
- sbit MUSIC_DATA =P2^1;//语音芯片脉冲识别
- sbit bus =P2^0;//语音芯片工作状态识别信号
- unsigned char bbh,xm1,xm2,xm0,xm3;
- void delay_us(unsigned int us)
- {
- while(us--)
- {
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- }
- }
- void Music(unsigned char music_count)
- {
- MUSIC_REST=1;
- delay_us(200);
- MUSIC_REST=0;
- delay_us(200);
- while(music_count>0)
- {
- MUSIC_DATA=1;
- delay_us(100);
- MUSIC_DATA=0;
- delay_us(100);
- music_count--;
- }
- }
- void Msc()
- {
- if((xm0+xm1+xm2+xm3)!=0) //当超出测量范围时不进行播报
- {
- Music(16); //播报:“ 重量 ”
- while(!bus);
- if(xm0==0)
- {
- Music(2); //播报:“千位数具体值” 0
- while(!bus);
- }
- else Music(xm0+2); //播报:“千位数具体值”
- while(!bus);
- // Music(14); //播报:“点”
- // while(!bus);
- if(xm1==0)
- {
- Music(2); //播报:“百位数具体值” 0
- while(!bus);
- }
- else Music(xm1+2); //播报:“千位数具体值”
- while(!bus);
- if((xm2+xm3)!=0)
- {
-
- Music(xm2+2); //播报:“十分位的具体值”
- while(!bus);
- Music(xm3+2); //播报:“百分位的具体值”
- while(!bus);
- Music(15); //播报:“单位”
- while(!bus);
- }
- else
- {
- Music(15); //播报:“单位”
- while(!bus);
- }
- }
- }
- //****************************************************
- //主函数
- //****************************************************
- void main()
- {
- Init_LCD1602(); //初始化LCD1602
- LCD1602_write_com(0x80); //指针设置
- LCD1602_write_word("Welcome to use! "); //开机画面第一行
- Delay_ms(2000); //延时2s
- Price_Buffer[0] = 0;
- Price_Buffer[1] = 0;
- Price_Buffer[2] = 0;
- Flag_OK = 0;
- LCD1602_write_com(0x80); //指针设置
- LCD1602_write_word(" Test weight ");//重量检测仪
- LCD1602_write_com(0x80+0x40); //指针设置
- LCD1602_write_word("weight: g ");
-
-
- Get_Maopi(); //称毛皮重量
- while(1)
- {
-
- Get_Weight(); //称重
- KEY_Scan();
- }
- }
- //****************************************************
- //称重
- //****************************************************
- 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采样数值。
-
- Weight_Shiwu = (unsigned int)((float)Weight_Shiwu/m__1+0.05); //计算实物的实际重量
- //因为不同的传感器特性曲线不一样,因此,每一个传感器需要矫正这里的4.30这个除数。
- //当发现测试出来的重量偏大时,增加该数值。
- //如果测试出来的重量偏小时,减小改数值。
- //该数值一般在4.0-5.0之间。因传感器不同而定。
- //+0.05是为了四舍五入百分位
-
- if(Weight_Shiwu >500 )Weight_Shiwu=500;
- if(Weight_Shiwu < 5)Weight_Shiwu=0;
- xm0=Weight_Shiwu/1000 ;
- xm1=Weight_Shiwu%1000/100;
- xm2=Weight_Shiwu%100/10;
- xm3=Weight_Shiwu%10;
- LCD1602_write_com(0x80+0x40+7);
- LCD1602_write_data(xm0+ 0x30);
- LCD1602_write_data(xm1 + 0x30);
- LCD1602_write_data(xm2 + 0x30);
- LCD1602_write_data(xm3 + 0x30);
-
- }
-
-
- }
- void delay(unsigned int x) //毫秒级延时函数
- {
- unsigned int i,j;
- for(i=x;i>0;i--)
- for(j=110;j>0;j--);
- }
- void KEY_Scan()
- {
- while(!k4)
- {
- bbh=1;
- }
- if(bbh==1) //bb=1调用一次播报程序
- {
- bbh=0;
- Msc();
- }
- if(key1==0) //
- {
- delay(10);
- if(key1==0)
- {
- while(!key1); //
- Get_Maopi(); //去皮
- }
- }
- if(key2==0) //
- {
-
- delay(10);
- if(key2==0)
- {
- while(!key2); // 微调重量-
- m__1=m__1+0.10;
- if(m__1>=5.10)m__1=5.00;
-
- }
-
- }
- if(key3==0) //
- {
-
- delay(10);
- if(key3==0)
- {
- while(!key3); // 微调重量+
- m__1=m__1-0.10;
- if(m__1<=1.10)m__1=2.50;
-
- }
-
- }
- }
- //****************************************************
- //获取毛皮重量
- //****************************************************
- void Get_Maopi()
- {
- HX711_Buffer = HX711_Read();
- Weight_Maopi = HX711_Buffer/100;
- }
- //****************************************************
- //MS延时函数(12M晶振下测试)
- //****************************************************
- void Delay_ms(unsigned int n)
- {
- unsigned int i,j;
- for(i=0;i<n;i++)
- for(j=0;j<123;j++);
- }
复制代码
所有资料51hei提供下载:
电子称设计.zip
(174.55 KB, 下载次数: 60)
|