标题:
hx711数字式压力表的设计,原理图和单片机源程序代码
[打印本页]
作者:
王51hei44
时间:
2018-4-8 11:20
标题:
hx711数字式压力表的设计,原理图和单片机源程序代码
电路原理图如下:
0.jpg
(45.54 KB, 下载次数: 70)
下载附件
2018-4-8 15:23 上传
单片机源程序如下:
#include <reg52.h>
#include <intrins.h>
#include <string.h>
#include "LCD1602.h"
#include "hx711.h"
//#include "keyboard.h"
#define uchar unsigned char
#define uint unsigned int
//定义量程系数
#define RATIO 1800/1000 //1574/1000 //2114/1623
//超声波程序
#define WD 30
void delay_ms(uint q);
void delay_10us();
void send_wave();
void time_init();
sbit c_send = P2^0; //超声波发射
sbit c_recive = P2^1; //超声波接收
sbit alarm=P1^0;
sbit S1=P1^4;
sbit S2=P1^5;
sbit S3=P1^6;
sbit S4=P1^7;
sbit deng=P1^1;
bit Flag_ON=1;
bit flag_300ms ;
long distance; //距离
uint Set_Dis=50; //设置距离
uchar flag;
uchar flag_csb_juli; //超声波超出量程
uint flag_time0; //用来保存定时器0的时候的
uint count=0;
uchar HG=5;
uchar LG=1;
float speed;
//定义标识
volatile bit FlagSetPrice = 0; //价格设置状态标志,设置好为1。
//显示用变量
int Counter;
int i, iTemp;
//称重用变量
unsigned long idata FullScale; //满量程AD值/1000
unsigned long AdVal; //AD采样值
unsigned long weight; //重量值,单位g
unsigned long idata price; //单价,长整型值,单位为分
unsigned long idata money; //总价,长整型值,单位为分
unsigned long idata pre_weight; //重量值,单位g
unsigned long idata pre_money;
//键盘处理变量
unsigned char keycode;
unsigned char DotPos; //小数点标志及位置
void Data_Init();
void INT1_Init();
void To_Zero();
void Display_Weight();
/*延时*/
void delay(int i)
{
int j,k;
for(j=0; j<i; j++)
for(k=0; k<500; k++);
}
//重新找回零点,每次测量前调用
void To_Zero()
{
FullScale=ReadCount()/1000;
}
//显示重量,单位kg,两位整数,三位小数
void Display_Weight()
{
LCD1602_write_com(0x83);
LCD1602_write_data(weight/1000 + 0x30);
LCD1602_write_data('.');
LCD1602_write_data(weight%1000/100 + 0x30);
LCD1602_write_data(weight%100/10 + 0x30);
LCD1602_write_data(weight%10 + 0x30);
}
void Display_juli()
{
LCD1602_write_com(0x82+0x40);
LCD1602_write_data(distance/100 + 0x30);
LCD1602_write_data('.');
LCD1602_write_data(distance%100/10 + 0x30);
LCD1602_write_data(distance%10 + 0x30);
}
unsigned short weight_value_filter(unsigned short wvalue)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
unsigned char i,j;
static unsigned short idata lastest_5times_value[5] = {0};
static unsigned char idata filter_count = 0;
static unsigned short idata calibration_voltage = 0;
unsigned char max_equal_index = 0;
unsigned char value_equal_count[5] = {0};
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if(filter_count < 5)
{
filter_count ++;
lastest_5times_value[filter_count -1] = wvalue;
return lastest_5times_value[filter_count -1];
}
else
{
i = 0;
while(i < 4)
{
lastest_5times_value[i] = lastest_5times_value[i + 1];
i ++;
}
lastest_5times_value[4] = wvalue;
}
/*Find Most Times Digit*/
for(i = 0; i < 5; i ++)
{
for(j = 0; j < 5; j ++)
{
if(lastest_5times_value[i] == lastest_5times_value[j])
{
value_equal_count[i] ++;
}
}
}
for(i = 0; i < 4; i ++)
{
if(value_equal_count[max_equal_index] < value_equal_count[i + 1])
{
max_equal_index = i + 1;
}
}
/*If "calibration_voltage" exist in the "lastest_5times_value";Return the
"calibration_voltage"*/
for(i = 0; i < 5; i ++)
{
if(calibration_voltage == lastest_5times_value[i])
{
return calibration_voltage;
}
}
calibration_voltage = lastest_5times_value[max_equal_index];
return calibration_voltage;
}
//===============main program===================//
void main(void)
{
unsigned short idata test_interval;
Init_LCD1602();
To_Zero();
LCD1602_write_com(0x80); //指针设置
LCD1602_write_word("WE: . kg ");
LCD1602_write_com(0x80+0x40); //指针设置
LCD1602_write_word(" L:1Kg H:5Kg ");
while(1)
{
//每0.5秒称重一次
if (test_interval ++ > 50)
{
test_interval = 0;
//称重,得到重量值weight,单位为g
AdVal=ReadCount();
weight=FullScale-AdVal/1000;
if (weight>0x8000) weight=0;
weight=10000*weight/FullScale;
weight=weight*RATIO;
weight = weight_value_filter(weight);
if (pre_weight != weight)
{
pre_weight = weight;
Display_Weight();
if((pre_weight/1000)>=HG)
{alarm=0;
deng=0;
}
else if((pre_weight/1000)<LG)
{alarm=0;
deng=0;
}
else
{alarm=1;
deng=1;
}
}
if(S1==0)
{ delay(10);
if(S1==0)
{
while(!S1);
LG++;
if(LG>9)
{LG=9;}
LCD1602_write_com(0x83+0x40);
LCD1602_write_data(LG + 0x30);
}
}
if(S2==0)
{ delay(10);
if(S2==0)
{
while(!S2);
LG--;
if(LG<1)
{LG=1;}
LCD1602_write_com(0x83+0x40);
LCD1602_write_data(LG + 0x30);
}
}
if(S3==0)
{ delay(10);
if(S3==0)
{
while(!S3);
HG++;
if(HG>9)
{HG=9;}
LCD1602_write_com(0x8C+0x40);
LCD1602_write_data(HG + 0x30);
}
}
if(S4==0)
{ delay(10);
if(S4==0)
{
while(!S4);
HG--;
if(HG<1)
{HG=1;}
LCD1602_write_com(0x8C+0x40);
LCD1602_write_data(HG + 0x30);
}
}
delay(1);
}
}
}
//超声波测距程序
/***********************1ms延时函数*****************************/
void delay_ms(uint q)
{
uint i,j;
for(i=0;i<q;i++)
for(j=0;j<120;j++);
}
/******************小延时函数*****************/
void delay_10us()
{
_nop_(); //执行一条_nop_()指令就是1us
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
/*********************超声波测距程序*****************************/
void send_wave()
{
c_send = 1; //10us的高电平触发
delay_10us();
c_send = 0;
while(!c_recive); //当c_recive为零时等待
TR0=1;
while(c_recive); //当c_recive为1计数并等待
TR0=0;
flag_time0 = TH0 * 256 + TL0;
TH0 = 0; //给定时器0清零
TL0 = 0;
if((flag_time0 > 40000)) //当超声波超过测量范围时,显示3个888
{
TR0 = 0;
flag_csb_juli = 2;
distance = 888;
}
else
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
压力设计.zip
(204.58 KB, 下载次数: 41)
2018-4-8 11:18 上传
点击文件名下载附件
芯片AT89C52,lcd1602液晶显示,有需要的朋友可以看看
下载积分: 黑币 -5
作者:
ilove51dxp
时间:
2019-8-31 21:03
学习下,好资料
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1