找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 7528|回复: 5
收起左侧

卖瓜啦,HX711电子秤全部设计资料,拿走不谢

  [复制链接]
ID:232657 发表于 2018-3-14 18:47 | 显示全部楼层 |阅读模式
毕设课设必备,懂速来
0.png

功能:
     按键K1为去皮功能,K2和K3是修改报警参数值。K2加,K3减。当所测重量大于设置的报警值时,P3.0驱动继电器工作,继电器可以接报警装置等。
     校正方法:如果所测重量偏小。则按住K3键不放,再按下K1键。 直到显示重量为正确重量时再放开K1和K3按键。
                如果所测重量偏大。则按住K2键不放,再按下K1键。 直到显示重量为正确重量时再放开K1和K2按键。。 校正系数具有断电保存功能。
时间:2016.7.25
版本:V1
安装方法2.png 压力传感器输出参数特性.jpg 压力传感器和HX711模块接法.jpg 安装方法1.png
20kg电子秤程序+上线报警设置(加继电器)单片机源程序如下:
  1. #include "main.h"
  2. #include "LCD1602.h"
  3. #include "HX711.h"
  4. #define uchar unsigned char  //无符号字符型 宏定义        变量范围0~255
  5. #define uint  unsigned int         //无符号整型 宏定义        变量范围0~65535


  6. #include "eeprom52.h"
  7. //定义变量
  8. unsigned char KEY_NUM = 0;   //用来存放按键按下的键值
  9. unsigned long HX711_Buffer = 0;  //用来存放HX711读取出来的数据
  10. unsigned long Weight_Maopi = 0; //用来存放毛皮数据
  11. long Weight_Shiwu = 0;          //用来存放实物重量
  12. unsigned char Max_Value;             //用来存放设置最大值

  13. unsigned char state = 0;    //用来存放设置状态
  14. unsigned char Blink_Speed = 0;
  15. #define Blink_Speed_Max 6          //该值可以改变设置指针闪烁频率


  16. uint GapValue= 104;           //传感器曲率

  17. unsigned char num1,num2,times; //num1 和 num2  是存储在单片机eeprom内部的。

  18. sbit JDQ=P3^0;

  19. //报警值,单位是g
  20. #define AlarmValue 20000                        



  21. /******************把数据保存到单片机内部eeprom中******************/
  22. void write_eeprom()
  23. {  
  24.     num1=GapValue/256;
  25.         num2=GapValue%256;

  26.     SectorErase(0x2000);
  27.         byte_write(0x2001,Max_Value);
  28.         byte_write(0x2002,  num1);
  29.         byte_write(0x2003,  num2);

  30.     byte_write(0x2060, a_a);        
  31. }

  32. /******************把数据从单片机内部eeprom中读出来*****************/
  33. void read_eeprom()
  34. {
  35.         Max_Value = byte_read(0x2001);
  36.         num1   = byte_read(0x2002);
  37.         num2   = byte_read(0x2003);
  38.         
  39.     a_a      = byte_read(0x2060);
  40.         GapValue= num1*256+num2;
  41. }

  42. /**************开机自检eeprom初始化*****************/
  43. void init_eeprom()
  44. {
  45.         read_eeprom();                //先读
  46.         if(a_a != 3)                //新的单片机初始单片机内问eeprom
  47.         {
  48.            a_a =3;
  49.            Max_Value = 10;
  50.            GapValue= 106;
  51.        write_eeprom();
  52.         }        
  53.         
  54.         
  55.         
  56. }


  57. //扫描按键
  58. void Scan_Key()
  59. {
  60.         if(KEY1 == 0 && KEY2 ==1 && KEY3 ==1 )
  61.         {
  62.                 Delay_ms(5);
  63.                 if(KEY1 == 0 && KEY2 ==1 && KEY3 ==1 )
  64.                 {
  65.                         while(KEY1 == 0 && KEY2 ==1 && KEY3 ==1 );
  66.                     Get_Maopi();
  67.                         Buzzer_Di();
  68.                 }        
  69.         }

  70.         if(KEY2 == 0 && KEY1 ==1 && KEY3 ==1 )
  71.         {
  72.                 Delay_ms(5);
  73.                 if(KEY2 == 0 && KEY1 ==1 && KEY3 ==1 )
  74.                 {
  75.                         while(KEY2 == 0 && KEY1 ==1 && KEY3 ==1 );
  76.                     if(Max_Value<20)         { Max_Value++;}
  77.                     write_eeprom();       //保存数据
  78.                         Buzzer_Di();
  79.                         LCD1602_write_com(0x80+0x40);
  80.             LCD1602_write_word("JDQ=");
  81.             LCD1602_write_data(Max_Value/100 + 0x30);
  82.             LCD1602_write_data(Max_Value%100/10 + 0x30);
  83.             LCD1602_write_data(Max_Value%10 + 0x30);
  84.                 }        
  85.         }

  86.         if(KEY3 == 0 && KEY1 ==1 && KEY2 ==1 )
  87.         {
  88.                 Delay_ms(5);
  89.                 if(KEY3 == 0 && KEY1 ==1 && KEY2 ==1)
  90.                 {
  91.                         while(KEY3 == 0 && KEY1 ==1 && KEY2 ==1);
  92.                     if(Max_Value>1)         { Max_Value--; }
  93.                          write_eeprom();       //保存数据
  94.                          Buzzer_Di();
  95.                          LCD1602_write_com(0x80+0x40);
  96.             LCD1602_write_word("JDQ=");
  97.             LCD1602_write_data(Max_Value/100 + 0x30);
  98.             LCD1602_write_data(Max_Value%100/10 + 0x30);
  99.             LCD1602_write_data(Max_Value%10 + 0x30);
  100.                 }        
  101.         }


  102.    //=======================对实物进行重量校正================================
  103.         if( KEY1 == 0 && KEY2 ==0)
  104.         {
  105.                 Delay_ms(25);
  106.                 if( KEY1 == 0 && KEY2 ==0)
  107.                 {
  108.                     times=0;
  109.                         Buzzer =0;
  110.                         Delay_ms(25);
  111.                         Buzzer =1;
  112.                     if(GapValue<999)  { GapValue++; }
  113.                         write_eeprom();       //保存数据
  114.                         LCD1602_write_com(0x80+0x40+11);
  115.             LCD1602_write_word("K=");
  116.                 LCD1602_write_data(GapValue/100 + 0x30);
  117.             LCD1602_write_data(GapValue%100/10 + 0x30);
  118.             LCD1602_write_data(GapValue%10 + 0x30);

  119.                 }        
  120.         }

  121.         if(KEY1 == 0 && KEY3 ==0)
  122.         {
  123.                 Delay_ms(25);
  124.                 if(KEY1 == 0 && KEY3 ==0)
  125.                 {        
  126.                     times=0;
  127.                         Buzzer =0;
  128.                         Delay_ms(25);
  129.                         Buzzer =1;
  130.                     if(GapValue>1)  {         GapValue--; }
  131.                          write_eeprom();       //保存数据
  132.                         LCD1602_write_com(0x80+0x40+11);
  133.             LCD1602_write_word("K=");
  134.                 LCD1602_write_data(GapValue/100 + 0x30);
  135.             LCD1602_write_data(GapValue%100/10 + 0x30);
  136.             LCD1602_write_data(GapValue%10 + 0x30);

  137.                 }        
  138.         }

  139. }



  140. //****************************************************
  141. //主函数
  142. //****************************************************
  143. void main()
  144. {
  145.         Init_LCD1602();                                                //初始化LCD1602
  146.         init_eeprom();                              //读eeprom数据
  147.         LCD1602_write_com(0x80);                        //设置LCD1602指针
  148.         LCD1602_write_word("Welcome to use!");
  149.         
  150.         Get_Maopi();
  151.         Get_Maopi();
  152.         Delay_ms(2000);                 //延时2s
  153.         Get_Maopi();
  154.         Get_Maopi();                                //称毛皮重量        //多次测量有利于HX711稳定
  155.     LCD1602_write_com(0x01);    //清屏
  156.    
  157.         LCD1602_write_com(0x80+0x40);
  158.     LCD1602_write_word("JDQ=");
  159.         LCD1602_write_data(Max_Value/100 + 0x30);
  160.     LCD1602_write_data(Max_Value%100/10 + 0x30);
  161.     LCD1602_write_data(Max_Value%10 + 0x30);
  162.     LCD1602_write_word("Kg");
  163.                    Buzzer =0;
  164.                         Delay_ms(25);
  165.                         Buzzer =1;

  166.         while(1)
  167.         {
  168.            
  169.             Scan_Key();
  170.         Get_Weight();               
  171.         
  172.                 //显示当前重量
  173.                 LCD1602_write_com(0x80);
  174.         LCD1602_write_word("Weight=");
  175.         LCD1602_write_data(Weight_Shiwu/10000 + 0x30);
  176.                 LCD1602_write_data(Weight_Shiwu%10000/1000 + 0x30);
  177.                 LCD1602_write_data('.');
  178.                 LCD1602_write_data(Weight_Shiwu%1000/100 + 0x30);
  179.                  LCD1602_write_data(Weight_Shiwu%100/10 + 0x30);
  180.                 LCD1602_write_data(Weight_Shiwu%10 + 0x30);        
  181.         
  182.                 LCD1602_write_word("Kg");

  183.         
  184.         
  185.         //超限报警
  186.         if(Weight_Shiwu/1000 >= Max_Value || Weight_Shiwu >= AlarmValue)                //超过设置最大值或者传感器本身量程最大值报警        
  187.                 {
  188.                         JDQ = 0; Buzzer=0;        
  189.                 }
  190.                 else
  191.                 {
  192.                         JDQ = 1; Buzzer=1;
  193.                 }

  194.             times++;
  195.                 if(times>=50)
  196.                 {
  197.                     times=0;
  198.                     LCD1602_write_com(0x80+0x40+11);
  199.             LCD1602_write_word("     ");
  200.                
  201.                 }
  202.         }
  203. }




  204. //****************************************************
  205. //称重
  206. //****************************************************
  207. void Get_Weight()
  208. {
  209.         Weight_Shiwu = HX711_Read();
  210.         Weight_Shiwu = Weight_Shiwu - Weight_Maopi;                //获取净重
  211.         if(Weight_Shiwu >= 0)                        
  212.         {        
  213.                 Weight_Shiwu = (unsigned long)((float)Weight_Shiwu/GapValue);         //计算实物的实际重量
  214.         }
  215.         else
  216.         {
  217.                 Weight_Shiwu = 0;
  218.         }
  219.         
  220. }
  221. ……………………

  222. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
压力传感器-给客户的资料包.rar (2 MB, 下载次数: 343)

评分

参与人数 2黑币 +53 收起 理由
悦风43 + 3 赞一个!
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:241242 发表于 2018-9-16 12:43 | 显示全部楼层
太棒了,学习,感谢!
回复

使用道具 举报

ID:126651 发表于 2019-7-18 21:26 | 显示全部楼层
请教个问题,传感器的曲率怎么算        GapValue这个变量的值
回复

使用道具 举报

ID:496297 发表于 2019-7-19 09:44 | 显示全部楼层
芯片右边那四个针叫啥。
回复

使用道具 举报

ID:588581 发表于 2020-4-15 10:08 | 显示全部楼层
您好,您知道HX711 B通道怎么使用吗
回复

使用道具 举报

ID:941278 发表于 2021-6-23 10:13 来自手机 | 显示全部楼层
里面有仿真吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表