找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1849|回复: 4
收起左侧

基于stm32的HX711和LCD1602体重秤程序设计

[复制链接]
ID:999834 发表于 2022-1-4 21:22 | 显示全部楼层 |阅读模式
  1. #include "HX711.h"
  2. #include "SysTick.h"

  3. u32 HX711_Buffer;
  4. u32 weightfirst;
  5. s32 weightend;
  6. u8 Flag_Error = 0;


  7. #define GapValue 106.5


  8. void Init_HX711pin(void)
  9. {
  10.         GPIO_InitTypeDef GPIO_InitStructure;
  11.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

  12.         //HX711_SCK
  13.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  14.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  
  15.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  
  16.         GPIO_Init(GPIOC, &GPIO_InitStructure);  
  17.         
  18.         //HX711_DOUT
  19.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  20.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  21.     GPIO_Init(GPIOC, &GPIO_InitStructure);  
  22.         
  23.         GPIO_SetBits(GPIOC,GPIO_Pin_0);  
  24. }



  25. //****************************************************
  26. //HX711
  27. //****************************************************
  28. u32 HX711_Read(void)        //128
  29. {
  30.         unsigned long count;
  31.         unsigned char i;
  32.           HX711_DOUT=1;
  33.         delay_us(1);
  34.           HX711_SCK=0;
  35.           count=0;
  36.           while(HX711_DOUT);
  37.           for(i=0;i<24;i++)
  38.         {
  39.                   HX711_SCK=1;
  40.                   count=count<<1;
  41.                 delay_us(1);
  42.                 HX711_SCK=0;
  43.                   if(HX711_DOUT)
  44.                         count++;
  45.                 delay_us(1);
  46.         }
  47.          HX711_SCK=1;
  48.     count=count^0x800000;
  49.         delay_us(1);
  50.         HX711_SCK=0;  
  51.         return(count);
  52. }

  53. void Get_Maopi(void)
  54. {
  55.         weightfirst = HX711_Read();        
  56. }

  57. //****************************************************
  58. //3???
  59. //****************************************************
  60. void Get_Weight(void)
  61. {
  62.         HX711_Buffer = HX711_Read();
  63.         if(HX711_Buffer > weightfirst)                        
  64.         {
  65.                 weightend = HX711_Buffer;
  66.                 weightend = weightend - weightfirst;                                //
  67.         
  68.                 weightend = (s32)((float)weightend/GapValue);         //最终质量
  69.                                                                                                                                        
  70.         }

  71.         
  72. }
复制代码

代码下载: Desktop.7z (323.51 KB, 下载次数: 74)

评分

参与人数 1黑币 +20 收起 理由
admin + 20 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:924572 发表于 2022-2-18 20:59 | 显示全部楼层
请问1602 有3.3V供电 和5V供电 有什么办法分辨吗?
回复

使用道具 举报

ID:423971 发表于 2022-2-23 15:04 | 显示全部楼层
参考意义不大
回复

使用道具 举报

ID:931040 发表于 2022-2-24 12:18 | 显示全部楼层
用的是什么传感器
回复

使用道具 举报

ID:264021 发表于 2024-3-10 20:33 | 显示全部楼层
里面的模块程序可以用,但主函数没有把模块程序组合起来,不懂修改程序的勿下载,浪费黑币
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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