找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2398|回复: 1
收起左侧

hx711电子秤+lm35温度检测+lcd1602+tlc549程序

[复制链接]
ID:833013 发表于 2020-12-5 19:25 | 显示全部楼层 |阅读模式
44~FEI6O2TAEG%LA2V]E$`Y.png

单片机源程序如下:
#include <reg52.h>
#include <intrins.h>
#include <string.h>

bit bdata flag_key;
#include "main.h"
#include "LCD1602.h"
#include "HX711.h"
#include "keyboard.h"
#include "eeprom52.h"
#include "tlc549.h"
#define uchar unsigned char
#define uint  unsigned int

unsigned long HX711_Buffer = 0;
unsigned long Weight_Maopi = 0;
unsigned long Weight_Maopi_0 = 0;
unsigned int qupi=0;
long Weight_Shiwu = 0;
//键盘处理变量
unsigned char keycode;
unsigned char DotPos;                                   //小数点标志及位置

uint GapValue,GapValue1;

unsigned char idata price;     //单价,长整型值,单位为分   
unsigned char idata money;     //总价,长整型值,单位为分
unsigned char idata lm35;  
//定义标识
volatile bit FlagTest = 0;                //定时测试标志,每0.5秒置位,测完清0
volatile bit FlagKeyPress = 0;  //有键按下标志,处理完毕清0
//校准参数
//因为不同的传感器特性曲线不是很一致,因此,每一个传感器需要矫正这里这个参数才能使测量值很准确。
//当发现测试出来的重量偏大时,增加该数值。
//如果测试出来的重量偏小时,减小改数值。
//该值可以为小数
//#define GapValue 349
sbit LED=P3^2;

volatile bit ClearWeighFlag = 0; //传感器调零标志位,清除0漂

/******************把数据保存到单片机内部eeprom中******************/
void write_eeprom()
{
        SectorErase(0x1000);
        GapValue1=GapValue&0x00ff;
        byte_write(0x2000, GapValue1);
        GapValue1=(GapValue&0xff00)>>8;
        byte_write(0x2001, GapValue1);
        byte_write(0x2060, a_a);        
}

/******************把数据从单片机内部eeprom中读出来*****************/
void read_eeprom()
{
        GapValue   = byte_read(0x2001);
        GapValue   = (GapValue<<8)|byte_read(0x2000);
        a_a      = byte_read(0x2060);
}

/**************开机自检eeprom初始化*****************/
void init_eeprom()
{
        read_eeprom();                //先读
        if(a_a != 1)                //新的单片机初始单片机内问eeprom
        {
                GapValue  = 3500;
                a_a = 1;
                write_eeprom();           //保存数据
        }        
}
                                                                                                                                       
//显示单价,单位为元,四位整数,两位小数
void Display_Price()
{
            LCD1602_write_com(0x8c);
                        LCD1602_write_data(price/100 + 0x30);
                        LCD1602_write_data(price%100/10 + 0x30);
                        LCD1602_write_data('.');
                        LCD1602_write_data(price%10 + 0x30);
}

//显示重量,单位kg,两位整数,三位小数
void Display_Weight()
{
            LCD1602_write_com(0x82);
                        LCD1602_write_data(Weight_Shiwu/10000 + 0x30);
        LCD1602_write_data(Weight_Shiwu%10000/1000 + 0x30);
                        LCD1602_write_data('.');
                        LCD1602_write_data(Weight_Shiwu%1000/100 + 0x30);
                        LCD1602_write_data(Weight_Shiwu%100/10 + 0x30);
                        LCD1602_write_data(Weight_Shiwu%10 + 0x30);
        LCD1602_write_word("K ");
}
//显示总价,单位为元,四位整数,两位小数
void Display_Money()
{
  // unsigned int i,j;

   if (money>9999)         //超出显示量程
   {
     LCD1602_write_com(0xC2);
     LCD1602_write_word("---.-");
      return;      
   }
   if (money>=1000)
   {
       LCD1602_write_com(0XC2);
           LCD1602_write_data(money/1000 + 0x30);
           LCD1602_write_data(money%1000/100 + 0x30);
           LCD1602_write_data(money%100/10 + 0x30);
           LCD1602_write_data('.');
           LCD1602_write_data(money%10 + 0x30);
   }
   else if (money>=100)
   {
       LCD1602_write_com(0XC2);
           LCD1602_write_data(0x20);
           LCD1602_write_data(money%1000/100 + 0x30);
           LCD1602_write_data(money%100/10 + 0x30);
           LCD1602_write_data('.');
           LCD1602_write_data(money%10 + 0x30);
   }
    else if(money>=10)
   {
       LCD1602_write_com(0XC2);
          LCD1602_write_data(0x20);
            LCD1602_write_com(0XC3);
           LCD1602_write_data(0x20);
           LCD1602_write_data(money%100/10 + 0x30);
           LCD1602_write_data('.');
           LCD1602_write_data(money%10+ 0x30);
   }   
   else
     {
       LCD1602_write_com(0XC2);
           LCD1602_write_data(0x20);
           LCD1602_write_com(0xC3);
           LCD1602_write_data(0x20);
           LCD1602_write_com(0xC4);
           LCD1602_write_data(0 + 0x30);
           LCD1602_write_data('.');
           LCD1602_write_data(money%10 + 0x30);
   }
}
void Display_lm35()
{            
            LCD1602_write_com(0xcc);
                  lm35=lm35/10;
                        LCD1602_write_data(lm35*2/100+ 0x30);
                        LCD1602_write_data(lm35*2%100/10+0x30);
                        LCD1602_write_data('.');
                        LCD1602_write_data(lm35*2%10+ 0x30);
}                 

//数据初始化
void Data_Init()
{
   price = 0;
   DotPos = 0;
         lm35=0;
         money=0;
}

Q8M8VBTYT4WSOLU9`R[T9NX.png

电子秤.7z

82.65 KB, 下载次数: 50, 下载积分: 黑币 -5

评分

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

查看全部评分

回复

使用道具 举报

ID:611988 发表于 2020-12-8 10:23 | 显示全部楼层
楼主好人 学习使人进步
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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