欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
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.raoushi.com/bbs/)
Powered by Discuz! X3.1