久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4510|回復: 1
收起左側

hx711數字式壓力表的設計,原理圖和單片機源程序代碼

[復制鏈接]
ID:303558 發表于 2018-4-8 11:20 | 顯示全部樓層 |閱讀模式
電路原理圖如下:
0.jpg

單片機源程序如下:
  1. #include <reg52.h>
  2. #include <intrins.h>
  3. #include <string.h>
  4. #include "LCD1602.h"
  5. #include "hx711.h"
  6. //#include "keyboard.h"

  7. #define uchar unsigned char
  8. #define uint  unsigned int
  9. //定義量程系數
  10. #define RATIO   1800/1000    //1574/1000  //2114/1623

  11. //超聲波程序
  12. #define WD  30
  13. void delay_ms(uint q);
  14. void delay_10us();
  15. void send_wave();
  16. void time_init();

  17. sbit c_send   = P2^0;                //超聲波發射
  18. sbit c_recive = P2^1;                //超聲波接收
  19. sbit alarm=P1^0;
  20. sbit S1=P1^4;
  21. sbit S2=P1^5;
  22. sbit S3=P1^6;
  23. sbit S4=P1^7;
  24. sbit deng=P1^1;

  25. bit Flag_ON=1;
  26. bit flag_300ms ;
  27. long distance;                //距離
  28. uint Set_Dis=50;                //設置距離
  29. uchar flag;
  30. uchar flag_csb_juli;    //超聲波超出量程
  31. uint  flag_time0;       //用來保存定時器0的時候的
  32. uint  count=0;
  33. uchar HG=5;
  34. uchar LG=1;
  35. float speed;


  36. //定義標識

  37. volatile bit FlagSetPrice = 0;  //價格設置狀態標志,設置好為1。





  38. //顯示用變量
  39. int Counter;
  40. int i, iTemp;
  41. //稱重用變量
  42. unsigned long idata FullScale; //滿量程AD值/1000
  43. unsigned long AdVal;     //AD采樣值
  44. unsigned long weight;    //重量值,單位g
  45. unsigned long idata price;     //單價,長整型值,單位為分
  46. unsigned long idata money;     //總價,長整型值,單位為分


  47. unsigned long idata pre_weight;    //重量值,單位g
  48. unsigned long idata pre_money;

  49. //鍵盤處理變量
  50. unsigned char keycode;
  51. unsigned char DotPos;                                   //小數點標志及位置


  52. void Data_Init();
  53. void INT1_Init();

  54. void To_Zero();

  55. void Display_Weight();



  56. /*延時*/
  57. void delay(int i)
  58. {
  59.     int j,k;
  60.     for(j=0; j<i; j++)
  61.         for(k=0; k<500; k++);
  62. }

  63. //重新找回零點,每次測量前調用
  64. void To_Zero()
  65. {
  66.     FullScale=ReadCount()/1000;

  67. }



  68. //顯示重量,單位kg,兩位整數,三位小數
  69. void Display_Weight()
  70. {
  71.     LCD1602_write_com(0x83);
  72.     LCD1602_write_data(weight/1000 + 0x30);
  73.     LCD1602_write_data('.');
  74.     LCD1602_write_data(weight%1000/100 + 0x30);
  75.     LCD1602_write_data(weight%100/10 + 0x30);
  76.     LCD1602_write_data(weight%10 + 0x30);
  77. }


  78. void Display_juli()
  79. {
  80.     LCD1602_write_com(0x82+0x40);
  81.     LCD1602_write_data(distance/100 + 0x30);
  82.     LCD1602_write_data('.');
  83.     LCD1602_write_data(distance%100/10 + 0x30);
  84.     LCD1602_write_data(distance%10 + 0x30);
  85.    




  86. }







  87. unsigned short weight_value_filter(unsigned short wvalue)
  88. {
  89.     /*----------------------------------------------------------------*/
  90.     /* Local Variables                                                */
  91.     /*----------------------------------------------------------------*/
  92.     unsigned char i,j;
  93.     static unsigned short idata lastest_5times_value[5] = {0};
  94.     static unsigned char idata filter_count = 0;
  95.     static unsigned short idata calibration_voltage = 0;
  96.     unsigned char max_equal_index = 0;
  97.     unsigned char value_equal_count[5] = {0};
  98.     /*----------------------------------------------------------------*/
  99.     /* Code Body                                                      */
  100.     /*----------------------------------------------------------------*/
  101.     if(filter_count < 5)
  102.     {
  103.         filter_count ++;
  104.         lastest_5times_value[filter_count -1] = wvalue;
  105.         return lastest_5times_value[filter_count -1];
  106.     }
  107.     else
  108.     {
  109.         i = 0;
  110.         while(i < 4)
  111.         {
  112.             lastest_5times_value[i] = lastest_5times_value[i + 1];
  113.             i ++;
  114.         }

  115.         lastest_5times_value[4] = wvalue;
  116.     }
  117.     /*Find Most Times Digit*/
  118.     for(i = 0; i < 5; i ++)
  119.     {
  120.         for(j = 0; j < 5; j ++)
  121.         {
  122.             if(lastest_5times_value[i] == lastest_5times_value[j])
  123.             {
  124.                 value_equal_count[i] ++;
  125.             }
  126.         }
  127.     }
  128.     for(i = 0; i < 4; i ++)
  129.     {
  130.         if(value_equal_count[max_equal_index] < value_equal_count[i + 1])
  131.         {
  132.             max_equal_index = i + 1;
  133.         }
  134.     }
  135.     /*If "calibration_voltage" exist in the "lastest_5times_value";Return the
  136.     "calibration_voltage"*/
  137.     for(i = 0; i < 5; i ++)
  138.     {
  139.         if(calibration_voltage == lastest_5times_value[i])
  140.         {
  141.             return calibration_voltage;
  142.         }
  143.     }

  144.     calibration_voltage = lastest_5times_value[max_equal_index];

  145.     return calibration_voltage;
  146. }

  147. //===============main program===================//
  148. void main(void)
  149. {
  150.     unsigned short idata test_interval;



  151.     Init_LCD1602();
  152.    
  153.    


  154.     To_Zero();
  155.     LCD1602_write_com(0x80);                                                //指針設置
  156.     LCD1602_write_word("WE: .   kg                 ");
  157.     LCD1602_write_com(0x80+0x40);                                //指針設置
  158.     LCD1602_write_word(" L:1Kg    H:5Kg    ");


  159.     while(1)
  160.     {            
  161.                           
  162.         //每0.5秒稱重一次
  163.         if (test_interval ++ > 50)
  164.         {
  165.             test_interval = 0;
  166.             //稱重,得到重量值weight,單位為g
  167.             AdVal=ReadCount();
  168.             weight=FullScale-AdVal/1000;
  169.             if (weight>0x8000) weight=0;
  170.             weight=10000*weight/FullScale;
  171.             weight=weight*RATIO;

  172.             weight = weight_value_filter(weight);
  173.                     
  174.                
  175.                 if (pre_weight != weight)
  176.                 {
  177.                     pre_weight = weight;
  178.                     Display_Weight();
  179.                                 if((pre_weight/1000)>=HG)
  180.                                  {alarm=0;
  181.                                   deng=0;
  182.                                  }
  183.                             else if((pre_weight/1000)<LG)
  184.                                  {alarm=0;
  185.                                   deng=0;
  186.                                  }
  187.                                  else
  188.                                  {alarm=1;
  189.                                  deng=1;
  190.                                  }
  191.                 }


  192.                                  if(S1==0)
  193.                {   delay(10);
  194.                      
  195.                    if(S1==0)
  196.                     {
  197.                               while(!S1);
  198.                                           LG++;
  199.                                    if(LG>9)
  200.                                            {LG=9;}
  201.                                      LCD1602_write_com(0x83+0x40);
  202.                    LCD1602_write_data(LG + 0x30);
  203.                         
  204.                     }
  205.               }
  206.                             if(S2==0)
  207.                {   delay(10);
  208.                      
  209.                    if(S2==0)
  210.                     {
  211.                               while(!S2);
  212.                                           LG--;
  213.                                    if(LG<1)
  214.                                            {LG=1;}
  215.                                      LCD1602_write_com(0x83+0x40);
  216.                    LCD1602_write_data(LG + 0x30);
  217.                         
  218.                     }
  219.               }
  220.                          if(S3==0)
  221.                {   delay(10);
  222.                      
  223.                    if(S3==0)
  224.                     {
  225.                               while(!S3);
  226.                                           HG++;
  227.                                    if(HG>9)
  228.                                            {HG=9;}
  229.                                      LCD1602_write_com(0x8C+0x40);
  230.                    LCD1602_write_data(HG + 0x30);
  231.                         
  232.                     }
  233.               }
  234.                             if(S4==0)
  235.                {   delay(10);
  236.                      
  237.                    if(S4==0)
  238.                     {
  239.                               while(!S4);
  240.                                           HG--;
  241.                                    if(HG<1)
  242.                                            {HG=1;}
  243.                                     LCD1602_write_com(0x8C+0x40);
  244.                    LCD1602_write_data(HG + 0x30);
  245.                         
  246.                     }
  247.               }
  248.                         









  249.                         
  250.                
  251.                
  252.         
  253.         delay(1);
  254.     }
  255. }

  256. }

  257. //超聲波測距程序

  258. /***********************1ms延時函數*****************************/
  259. void delay_ms(uint q)
  260. {
  261.         uint i,j;
  262.         for(i=0;i<q;i++)
  263.                 for(j=0;j<120;j++);
  264. }

  265. /******************小延時函數*****************/
  266. void delay_10us()
  267. {
  268.         _nop_();                            //執行一條_nop_()指令就是1us
  269.         _nop_();
  270.         _nop_();
  271.         _nop_();
  272.         _nop_();
  273.         _nop_();
  274.         _nop_();
  275.         _nop_();
  276.         _nop_();  
  277.         _nop_();
  278. }

  279. /*********************超聲波測距程序*****************************/
  280. void send_wave()
  281. {
  282.         c_send = 1;                           //10us的高電平觸發
  283.         delay_10us();
  284.         c_send = 0;         
  285.         while(!c_recive);                  //當c_recive為零時等待
  286.         TR0=1;
  287.         while(c_recive);                      //當c_recive為1計數并等待
  288.         TR0=0;        
  289.                                                                                           
  290.         flag_time0 = TH0 * 256 + TL0;

  291.         TH0 = 0;                                  //給定時器0清零
  292.         TL0 = 0;
  293.         if((flag_time0 > 40000))      //當超聲波超過測量范圍時,顯示3個888
  294.         {
  295.                 TR0 = 0;
  296.                 flag_csb_juli = 2;
  297.                 distance = 888;
  298.         }
  299.         else
  300. ……………………

  301. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
壓力設計.zip (204.58 KB, 下載次數: 41)
回復

使用道具 舉報

ID:605916 發表于 2019-8-31 21:03 | 顯示全部樓層
學習下,好資料
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 99久热| 久久国产一区二区三区 | 精品av| 亚洲国产成人久久综合一区,久久久国产99 | 国产一区欧美 | 日韩欧美国产一区二区三区 | 91 在线| 伊人超碰 | 91毛片在线观看 | 97国产精品视频人人做人人爱 | 精品美女久久久久久免费 | 亚洲欧洲一区 | 日本一区二区高清不卡 | 欧美一区二区三区在线免费观看 | 一区在线观看视频 | 午夜影视在线观看 | 在线免费观看黄色 | 日韩成人精品一区二区三区 | 国产精品美女久久久久久久网站 | 黄色免费在线观看网址 | 午夜av在线| 欧美精品电影一区 | 在线成人免费视频 | 一区二区三区高清在线观看 | 久久久蜜桃一区二区人 | 亚洲国产精久久久久久久 | 56pao在线 | 久久精品 | 日韩欧美国产不卡 | 亚洲va在线va天堂va狼色在线 | 91精品久久久久久久久久入口 | 国产不卡一区 | 日本不卡一区 | 欧美中文字幕一区二区三区 | 97视频在线观看免费 | 亚洲国产精久久久久久久 | 日韩视频在线一区 | 国产视频欧美 | 中文字幕视频在线看5 | 亚洲视频二区 | 狠狠躁夜夜躁人人爽天天高潮 |