找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3820|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

單片機(jī)+HX711壓力檢測

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
**HX711壓力檢測裝置**,要實(shí)現(xiàn)的功能:實(shí)時(shí)監(jiān)測當(dāng)前壓力并通過藍(lán)牙串口將數(shù)據(jù)傳輸至手機(jī),采用獨(dú)立按鍵調(diào)節(jié)壓力報(bào)警值,人機(jī)交互界面采用LCD12864控制內(nèi)核為STC89C52RC;接下來我們來說說材料清單控制主板:**STC89C52RC最小系統(tǒng)板  LCD12864  蜂鳴器 HC-05藍(lán)牙模塊 洞洞板 四個(gè)HX711芯片 四個(gè)HX711壓力傳感器**在此之前我們還需要學(xué)習(xí)一下HX711的壓力轉(zhuǎn)換,計(jì)算相應(yīng)線性系數(shù)以便獲取高精度的重量;

HX711AD模塊兩個(gè)IO口, 分別對應(yīng)SCK,DOUT。當(dāng)DOUT=1, 說明ad轉(zhuǎn)換器還沒準(zhǔn)備好輸出數(shù)據(jù)。當(dāng)DOUT=0,說明準(zhǔn)備好了,然后就得對SCK輸入脈沖,且輸入一次脈沖,DOUT就輸出一位數(shù)據(jù)(二進(jìn)制,數(shù)據(jù)從最高位到最低位依次輸出),24個(gè)脈沖后,再根據(jù)SCK的脈沖數(shù)對下次工作方式進(jìn)行選擇。我們選用A通道,128增益。
工作模式的選擇HX711AD模塊有上圖三種工作模式,A通道128增益、B通道32增益、A通道64增益。對應(yīng)不同的增益,其滿額度差分輸入信號幅值也不同。(還沒學(xué)模電數(shù)電,不知道這是個(gè)什么東東)根據(jù)相關(guān)的文檔以及網(wǎng)上的一些文章,不管選哪個(gè)通道的多少增益,其數(shù)據(jù)處理是類似的,只是不同的增益對應(yīng)不同的放大倍數(shù)。具體到程序編寫上,即為兩處改動(dòng)。
**詳細(xì)講解程序計(jì)算原理**:
**步驟 1**  :如何計(jì)算傳感器供電電壓
HX711 可以在產(chǎn)生  VAVDD  和  AGND  電壓,即 711 模塊上的  E+ 和  E- 電壓。該電壓通過  VAVDD=VBG(R1 +R2 )/R2 計(jì)算。VBG  為模塊兒基準(zhǔn)電壓 1.25v,R1 = 20K,R2 = 8.2K。 因此得出  VAVDD = 4.3V
(為了降低功耗,該電壓只在采樣時(shí)刻才有輸出, 因此用萬用表讀取的值可能低于 4.3v ,因?yàn)槿f用表測量的是有效值。   )
**步驟 2**  :如何計(jì)算  AD   輸出最大值
在 4.3V  的供電電壓下 5Kg  的傳感器最大輸出電壓是 4.3v*1mv/V = 4.3mV
經(jīng)過 128 倍放大后,最大電壓為 4.3mV*128 = 550.4mV
經(jīng)過 AD 轉(zhuǎn)換后輸出的24bit數(shù)字值最大為:550.4mV*2^ 24 /4.3V ≈ 2147483
**步驟 3**  :程序中數(shù)據(jù)如何轉(zhuǎn)換
程序中通過HX711_Buffer = HX711_Read(); 獲取當(dāng)前采樣的  AD  值,最大 2147483 ,存放在  long  型變量  HX711_Buffer 中,因 long 型變量計(jì)算速率和存放空間占用資源太多,固除以100 ,縮放為 int 型,便于后續(xù)計(jì)算。
Weight_Shiwu = HX711_Buffer/100;
Weight_Shiwu  最大為 21474 。
**步驟 4**  :如何將  AD   值反向轉(zhuǎn)換為重力值。
假設(shè)重力為  A Kg ,( x<5Kg ) , 測量出來的 AD 值為  y
5Kg 傳感器輸出,發(fā)送給 AD 模塊兒的電壓為  A Kg * 4.3mV / 5Kg = 0.86A mV
經(jīng)過 128 倍增益后為  128 * 0.86A = 110.08AmV
轉(zhuǎn)換為 24bit  數(shù)字信號為  110.08A mV * 2 ^24  / 4.3V = 429496.7296A
所以  y = 429496.7296A /100 = 4294.967296 A
因此得出  A = (y / 4294.967296) Kg ≈ y / 4.30 g
所以得出程序中計(jì)算公式
Weight_Shiwu = (unsigned int)((float)Weight_Shiwu/4.30+0.05);
//+0.05 是為了四舍五入百分位
**特別注意:
因?yàn)椴煌膫鞲衅餍甭侍匦郧不一樣,因此,每一個(gè)傳感器需要矯正這里的 4.30 這個(gè)除數(shù)。當(dāng)發(fā)現(xiàn)測出來的重量偏大時(shí),增加該數(shù)值。如果測試出來的重量偏小時(shí),減小改數(shù)值。該數(shù)值一般在 4.0-5.0 之間。因傳感器線性斜率不同而定。每個(gè)傳感器都要校準(zhǔn)。如果傳感器測量值偏大,則需改大該數(shù)值,若傳感器測量值偏小,則需改小該數(shù)值。**
使用A通道的arduino程序如下:
```c
/////以下為函數(shù)聲明  
extern unsigned long HX711_Read(void);
extern long Get_Weight();
///變量定義
float Weight = 0;
int HX711_SCK =2;   ///     作為輸出口
int HX711_DT= 3;    ///     作為輸入口
long HX711_Buffer = 0;
long Weight_Maopi = 0, Weight_Shiwu = 0;
#define GapValue 405       ///該值需校準(zhǔn) 每個(gè)傳感器都有所不同
void setup()
{  
//初始化HX711的兩個(gè)io口      
pinMode(HX711_SCK, OUTPUT);  ///SCK 為輸出口 ---輸出脈沖
pinMode(HX711_DT, INPUT); ///  DT為輸入口  ---讀取數(shù)據(jù)
Serial.begin(9600);
Serial.print("Welcome to use!\n");
delay(3000);    ///延時(shí)3秒  
//獲取毛皮重量
Weight_Maopi = HX711_Read();
}
void loop()    ///  一直循環(huán){}內(nèi)容  ----- 同while(1){xxx}
{
Weight = Get_Weight();  //計(jì)算放在傳感器上的重物重量
Serial.print(float(Weight/1000),3);  //串口顯示重量,3意為保留三位小數(shù)
Serial.print(" kg\n"); //顯示單位
Serial.print("\n");  //顯示單位
delay(2000);  //延時(shí)2s 兩秒讀取一次傳感器所受壓力
}
//稱重函數(shù)
long Get_Weight()
{
HX711_Buffer = HX711_Read();    ///讀取此時(shí)的傳感器輸出值
Weight_Shiwu = HX711_Buffer;     ///將傳感器的輸出值儲(chǔ)存
Weight_Shiwu = Weight_Shiwu - Weight_Maopi; //獲取實(shí)物的AD采樣數(shù)值。
Weight_Shiwu = (long)((float)Weight_Shiwu/GapValue);    //AD值轉(zhuǎn)換為重量(g)
return Weight_Shiwu;
}
unsigned long HX711_Read(void) //選擇芯片工作方式并進(jìn)行數(shù)據(jù)讀取
{
unsigned long count;   ///儲(chǔ)存輸出值  
unsigned char i;     
   ////high--高電平 1  low--低電平 0  
digitalWrite(HX711_DT, HIGH);   ////  digitalWrite作用: DT=1;
delayMicroseconds(1); ////延時(shí) 1微秒  
digitalWrite(HX711_SCK, LOW);  ////  digitalWrite作用: SCK=0;
delayMicroseconds(1);   ////延時(shí) 1微秒  
count=0;
  while(digitalRead(HX711_DT));    //當(dāng)DT的值為1時(shí),開始ad轉(zhuǎn)換
  for(i=0;i<24;i++)   ///24個(gè)脈沖,對應(yīng)讀取24位數(shù)值
{
   digitalWrite(HX711_SCK, HIGH);  ////  digitalWrite作用: SCK=0;
                                /// 利用 SCK從0--1 ,發(fā)送一次脈沖,讀取數(shù)值
  delayMicroseconds(1);  ////延時(shí) 1微秒  
  count=count<<1;    ///用于移位存儲(chǔ)24位二進(jìn)制數(shù)值
  digitalWrite(HX711_SCK, LOW);   //// digitalWrite作用: SCK=0;為下次脈沖做準(zhǔn)備
delayMicroseconds(1);
   if(digitalRead(HX711_DT))    ///若DT值為1,對應(yīng)count輸出值也為1
   count++;
}
  digitalWrite(HX711_SCK, HIGH);    ///再來一次上升沿 選擇工作方式  128增益
count ^= 0x800000;   //按位異或  不同則為1   0^0=0; 1^0=1;
///對應(yīng)二進(jìn)制  1000 0000 0000 0000 0000 0000  作用為將最高位取反,其他位保留原值
delayMicroseconds(1);
digitalWrite(HX711_SCK, LOW);      /// SCK=0;     
delayMicroseconds(1);  ////延時(shí) 1微秒  
return(count);     ///返回傳感器讀取值
}
```
**對于51、stm32等單片機(jī)的程序,只需做出簡單修改就可。
HX711  AD 轉(zhuǎn)換的計(jì)算詳細(xì)可參考知乎
https://zhuanlan.zhihu.com/p/938 ... 1000773993053503488**
[知乎,詳細(xì)AD 轉(zhuǎn)換講解](https://zhuanlan.zhihu.com/p/938 ... 1000773993053503488)
接下來我們就進(jìn)入正題,進(jìn)行主函數(shù)的編程;此次工程用到串口通信、EEPROM存入數(shù)值、AD轉(zhuǎn)換以及LCD12864并行通信;
所包含的庫函數(shù)(自己建立的庫函數(shù))
#include <12864.h>
#include <main.h>
#include <HX711.h>
#include <eeprom.h>
#include <USART.h>
```c
#include<reg52.h>
#include <intrins.h>
#include <string.h>
#include <stdio.h>
#include <12864.h>
#include <main.h>
#include <HX711.h>
#include <eeprom.h>
#include <USART.h>
/********************************************************************
*函數(shù)名: key_pros()
* 功能 按鍵掃描
* ???? : ??
* ??? : ??
***********************************************************************/
void key_pros
{
if(K1==0)   
{
  if(K1==0)    //加
  {
   delay1(100);
   if(K1==0)
   {
    I++;
    delay1(100);
    if(I>99999){I=50;beep=~beep;delay1(70);beep=1;}
   }
   while(!K1);
  }
  }
  if(K2==0)    //減
  {
   delay1(100);
   if(K2==0)
   {
    I--;
    delay1(100);
    if(I<0){I=50;beep=~beep;delay1(70);beep=1;}
   }
   while(!K2);
  }
}
/********************************************************************
* 函數(shù)名 : delay()
* 功能 : 延遲100us *t子函數(shù)
* ???? : t
* ??? : ??
***********************************************************************/
void delay(unsigned int t)
{
unsigned int p,j;
for(p=0; p<t;  p++)
    for(j=0; j<10; j++);
}
/********************************************************************
* 函數(shù)名 : Timer0_ISR (void) interrupt 1 using 0()
* 功能  : 定時(shí)器0中斷
* ???? : ??
* ??? : ??
***********************************************************************/
void Timer0_ISR (void) interrupt 1 using 0
{
        uchar Counter;
        TL0 = 0xb0;
        TH0 = 0x3c;     //???????????
        Counter ++;//?0.5???????????
    if (Counter >= 10)
    {
       FlagTest = 1;
           Counter = 0;
    }
}
/******************把數(shù)據(jù)保存到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);
}
/******************讀取數(shù)據(jù)從eeprom中*****************/
void read_eeprom()
{
GapValue   = byte_read(0x2001);
GapValue   = (GapValue<<8)|byte_read(0x2000);
a_a      = byte_read(0x2060);
}
/***************開機(jī)自檢初始化****************/
void init_eeprom()
{
read_eeprom();  //先讀
if(a_a != 1)  
{
  GapValue  = 210;
  a_a = 1;
  write_eeprom();    //保存
}
}
/********************************************************************
* 函數(shù)名 : keydat()
* 功能  : 報(bào)警鍵值
* ???? : ??
* ??? : ??
***********************************************************************/
void keydata()
{   
        int m;
  for(m=0;m<5;m++)
  {
     if(m==0)
     TX[7]=I/10000+0x30;  //數(shù)據(jù)處理對應(yīng)ASCII
     else if(m==1)
          TX[8]=I/10000%1000+0x30;
     else if(m==2)
     TX[9]=I%1000/100+0x30;
     else if(m==3)
     TX[10]=I%100/10+0x30;
     else
     TX[11]=I%10+0x30;
     }
  }
/********************************************************************
* 函數(shù)名: Test()
* 功能  : 顯示子函數(shù)
* ???? : ??
* ??? : ??
***********************************************************************/
void Test()
{  
LCD12864_COM_Write(0x80);   //設(shè)置指針
LCD12864_write_word("    PRESSURE");    //顯示內(nèi)容
LCD12864_COM_Write(0x90);   //設(shè)置指針
LCD12864_write_word(pro1);   //顯示內(nèi)容
LCD12864_COM_Write(0x88);   //設(shè)置指針
LCD12864_write_word(pro);  //顯示內(nèi)容
LCD12864_COM_Write(0x98);   //設(shè)置指針
LCD12864_write_word(TX);    //顯示內(nèi)容
}
/********************************************************************
* 函數(shù)名: TEST1()
* 功能  : 開機(jī)畫面
* ???? : ??
* ??? : ??
***********************************************************************/
void TEST1()
{  
LCD12864_COM_Write(0x80);   //設(shè)置指針
LCD12864_write_word("    PRESSURE");    //顯示內(nèi)容?
LCD12864_COM_Write(0x90);   //設(shè)置指針
LCD12864_write_word("    壓力檢測");   //顯示內(nèi)容
LCD12864_COM_Write(0x88);   //設(shè)置指針
LCD12864_write_word("Welcome to use");  //顯示內(nèi)容
LCD12864_COM_Write(0x98);   //設(shè)置指針
LCD12864_write_word("    歡迎使用");    //顯示內(nèi)容
}
/********************************************************************
* 函數(shù)名: TEST1()
* 功能  : 清屏函數(shù)
* ???? : ??
* ??? : ??
***********************************************************************/
void TEST0()
{  
LCD12864_COM_Write(0x80);   //設(shè)置指針
LCD12864_write_word("                   ");   
LCD12864_COM_Write(0x90);   //設(shè)置指針
LCD12864_write_word("                   ");   
LCD12864_COM_Write(0x88);   //設(shè)置指針
LCD12864_write_word("                   ");  
LCD12864_COM_Write(0x98);   //設(shè)置指針
LCD12864_write_word("                   ");  
}
/********************************************************************
* 函數(shù)名: datat()
* 功能  : 實(shí)際重量轉(zhuǎn)換 存放數(shù)組
* ???? : ??
* ??? : ??
***********************************************************************/
void datat()
{
   pro1[2] = Weight_Shiwu1/10000 + 0X30;
   pro1[3] = Weight_Shiwu1/10000%1000 + 0X30;
   pro1[4] = Weight_Shiwu1%1000/100 + 0X30;
   pro1[5] = Weight_Shiwu1%100/10 + 0X30;
   pro1[6] = Weight_Shiwu1%10 + 0x30;
   pro1[7]='g';
   pro1[10] = Weight_Shiwu2/10000 + 0X30;
   pro1[11] = Weight_Shiwu2/10000%1000 + 0X30;
   pro1[12] = Weight_Shiwu2%1000/100 + 0X30;
   pro1[13] = Weight_Shiwu2%100/10 + 0X30;
   pro1[14] = Weight_Shiwu2%10 + 0x30;
   pro1[15]='g';
    pro[2] = Weight_Shiwu/10000 + 0X30;
   pro[3] = Weight_Shiwu/10000%1000 + 0X30;
   pro[4] = Weight_Shiwu%1000/100 + 0X30;
   pro[5] = Weight_Shiwu%100/10 + 0X30;
   pro[6] = Weight_Shiwu%10 + 0x30;
   pro[7]='g';
   pro[10] = Weight_Shiwu3/10000 + 0X30;;
   pro[11] = Weight_Shiwu3/10000%1000 + 0X30;
   pro[12] = Weight_Shiwu3%1000/100 + 0X30;
   pro[13] = Weight_Shiwu3%100/10 + 0X30;
   pro[14] = Weight_Shiwu3%10 + 0X30;
   pro[15]='g';
   pro[18]='\r';
   pro[19]='\n';  //串口顯示換行
   }
   /********************************************************************
* 函數(shù)名: send()
* 功能 : 串口發(fā)送函數(shù)
* ???? : ??
* ??? : ??
***********************************************************************/
void send()
{
int G;
   for(G=0;G<16 ;G++)
{
  SBUF=pro1[G];
  delay1(20); //等待發(fā)送完畢
}
   for(G=0;G<20 ;G++)
{
  SBUF=pro[G];
  delay1(20); //等待發(fā)送完畢
}
}
/********************************************************************
*函數(shù)名: Main()
* 功能  : 主函數(shù)
* ???? : ??
* ??? : ??
***********************************************************************/
void Main()
{
init_eeprom();  //初始化eeprom
Init();
LCD12864_Reset();        //液晶初始化
LCD12864_HAIZI_SET();       //設(shè)計(jì)為普通模式
TEST1();             //開機(jī)畫面
Delay_ms1(1000);   //等待
Get_Maopi();    //獲取毛皮重量
Delay_ms1(100);   //等待
    Get_Maopi();    //獲取毛皮重量
Delay_ms1(100);   //等待
    Get_Maopi();    //獲取毛皮重量
Delay_ms1(100);   //等待
    Get_Maopi();    //獲取毛皮重量多獲取幾次,數(shù)值更加精確
TEST0();
  while(1)
{
     key_pros();  //按鍵檢測
  keydata();  //鍵值處理
  Delay_ms1(100); //等待
  Get_Weight(); //和獲取重量
  datat();  //數(shù)據(jù)存放
        send();   //發(fā)送至串口
  Test();   //LCD12864顯示
  delay(30);  //等待顯示完全
}
}
/********************************************************************
* 函數(shù)名: Get_Weight()
* 功能  :獲取重量及報(bào)警
* ???? : ??
* ??? : ??
***********************************************************************/
void Get_Weight()
{
Weight_Shiwu = HX711_Read00();
Weight_Shiwu = Weight_Shiwu - Weight_Maopi;      //獲取1凈重
Weight_Shiwu1 = HX711_Read01();
Weight_Shiwu1 = Weight_Shiwu1 - Weight_Maopi1;  //獲取2凈重
Weight_Shiwu2 = HX711_Read02();
Weight_Shiwu2 = Weight_Shiwu2 - Weight_Maopi2;  //獲取3凈重
Weight_Shiwu3 = HX711_Read03();
Weight_Shiwu3 = Weight_Shiwu3 - Weight_Maopi3;  //獲取4凈重
  if(Weight_Shiwu > 0||Weight_Shiwu1 > 0||Weight_Shiwu2 > 0||Weight_Shiwu3 > 0)   
{
  Weight_Shiwu = (unsigned int)((float)Weight_Shiwu/GapValue);  //計(jì)算實(shí)際重量1
  Weight_Shiwu1 = (unsigned int)((float)Weight_Shiwu1/GapValue);  //計(jì)算實(shí)際重量2               
  Weight_Shiwu2 = (unsigned int)((float)Weight_Shiwu2/GapValue);  //計(jì)算實(shí)際重量3
  Weight_Shiwu3 = (unsigned int)((float)Weight_Shiwu3/GapValue);  //計(jì)算實(shí)際重量4               
  if(Weight_Shiwu > I||Weight_Shiwu1 > I||Weight_Shiwu2 > I||Weight_Shiwu3 > I)  //判斷是否超出鍵值 選擇報(bào)警
  {
   beep = 0;
  }
  else
  {
   beep = 1;
  }
    }
   else
{
  Weight_Shiwu = 0;
  Weight_Shiwu1 = 0;
  Weight_Shiwu2 = 0;
  Weight_Shiwu3 = 0;
    }
}
/********************************************************************
* 函數(shù)名 : Get_Maopi()
* 功能 : 獲取毛皮
* ???? : ??
* ??? : ??
***********************************************************************/
void Get_Maopi()
{
Weight_Maopi = HX711_Read00();
    Weight_Maopi1 = HX711_Read01();
Weight_Maopi2 = HX711_Read02();
Weight_Maopi3 = HX711_Read03();
}
/********************************************************************
* 函數(shù)名 : Delay_ms1(unsigned int n)
* 功能  : MS延遲(12M晶振下)
* ???? : ??
* ??? : ??
***********************************************************************/
void Delay_ms1(unsigned int n)
{
unsigned int  i,j;
for(i=0;i<n;i++)
  for(j=0;j<123;j++);
}
```
MAIN.h
```c
#ifndef __MAIN_H__
#define __MAIN_H__
#include <reg52.h>
#define uchar unsigned char
#define uint  unsigned int
typedef unsigned char  U8;     
typedef unsigned int   U16;  
sbit beep=P1^0;
sbit K1=P2^0;  //+
sbit K2=P2^1;  //-
int I=50;
unsigned char a=12;
U8 pro[]={"3:      4:"};
U8 pro1[]={"1:      2:"};
U8 TX[]={"報(bào)警值      g"};   
U8  count, count_r=0;
uint GapValue,GapValue1;
volatile bit ClearWeighFlag = 0; //????????????λ?????0?
volatile bit FlagTest = 0;  //????????????0.5????λ????????0  
unsigned long Weight_Maopi = 0;// ???1???
unsigned long Weight_Maopi_0 = 0;
unsigned long Weight_Maopi1 = 0;//???2???
unsigned long Weight_Maopi_1 = 0;
unsigned long Weight_Maopi2 = 0;//???2???
unsigned long Weight_Maopi3 = 0;//???2???
unsigned int qupi=0;
long Weight_Shiwu = 0;
long Weight_Shiwu1 = 0;
long Weight_Shiwu2 = 0;
long Weight_Shiwu3= 0;
extern void Delay_ms1(unsigned int n);
extern void Get_Maopi();
//extern void Get_Maopi1();
extern void Get_Weight();
//extern void Get_Weight1();
void key_pros();
void Delay_ms1(unsigned int n);
```


接下來展示一下自己編寫的庫函數(shù),由于代碼過多就不會(huì)展示.h文

件,只要在.h文件中
#ifndef _HX711_H_
#define _HX711_H_在這里定義自己的庫函數(shù)名稱,包含進(jìn)去就行,就是套公式啦
..................
..................
..................   在中間聲明一下自己的寫的函數(shù)就好
..................
#endif     再來個(gè)結(jié)尾就結(jié)束啦     這大概就.h文件編寫的要求,就類似于公式,套進(jìn)去就好
藍(lán)牙串口
```c
#include<USART.h>
void delay1(int xms)
{
  int m,n;
  for(m=xms;m>=0;m--)
      for(n=110;n>=0;n--);
}
void Init()
{
ES=0;
SCON = 0x50;    //工作方式1 設(shè)置波特率9600bps 允許接收
TMOD = 0x20;   //定時(shí)器T1選擇工作方式2
TH1=TL1=0xFD;
PCON &= 0x7f;
TR1 = 1;          // 開啟計(jì)時(shí)器
TI = 0;
RI = 0;     
ES = 1;
EA = 1;           // 打開總中斷  

}
void Timer0_Init()
{
        ET0 = 1;        //????????0?ж?
        TMOD = 1;       //???????????????
        TL0 = 0xb0;     
        TH0 = 0x3c;     //???????????
        TR0 = 1;        //????????
}
```
**12864.c**
```c
#include "12864.H"
void LCD12864_WaitIdle()
{
unsigned char i;
LCD12864_DA_PORT = 0xff;
LCD12864_RS_PORT = 0;
LCD12864_RW_PORT = 1;
LCD12864_E_PORT = 1;
while((LCD12864_DA_PORT&0x80)==1); /*???BF ???1*/
LCD12864_E_PORT = 0;
for(i=0;i<5;i++);
}
void LCD12864_COM_Write( unsigned char com_da)
{
LCD12864_WaitIdle();
LCD12864_RS_PORT = 0;
LCD12864_RW_PORT = 0;
LCD12864_DA_PORT = com_da;
LCD12864_E_PORT = 1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
LCD12864_E_PORT = 0;
}
void LCD12864_NoWaitIdle_COM_Write(unsigned char com_da)
{
LCD12864_RS_PORT = 0;
LCD12864_RW_PORT = 0;
LCD12864_DA_PORT = com_da;
LCD12864_E_PORT = 1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
LCD12864_E_PORT = 0;
}
void LCD12864_Data_Write(unsigned char da)
{
LCD12864_WaitIdle(); /*???????*/
LCD12864_RS_PORT = 1;
LCD12864_RW_PORT = 0;
LCD12864_DA_PORT = da;
LCD12864_E_PORT = 1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
LCD12864_E_PORT = 0;
}
void LCD12864_write_word(unsigned char *s)
{
while(*s>0)
{
  LCD12864_Data_Write(*s);
  s++;
}
}
void lcd_delay_ms(unsigned char x)
{
    unsigned char j;
    while(x--){
        for(j=0;j<125;j++)
            {;}
        }   
}
void LCD12864_Reset()
{
lcd_delay_ms(100); /*????????LCD?????λ???*/
LCD12864_NoWaitIdle_COM_Write(0x30); /*???8λ??????*/
lcd_delay_ms(10);
LCD12864_NoWaitIdle_COM_Write(0x30); /*???8λ??????*/
lcd_delay_ms(10);
LCD12864_NoWaitIdle_COM_Write(0x0c); /*??????????????*/
lcd_delay_ms(10);
LCD12864_NoWaitIdle_COM_Write(0x01); /*???????*/
lcd_delay_ms(30);
LCD12864_NoWaitIdle_COM_Write(0x06); /*DDRAM????????????AC????1*/
lcd_delay_ms(30);
}
void LCD12864_HAIZI_SET()
{
LCD12864_COM_Write(0x30);
lcd_delay_ms(10);
LCD12864_COM_Write(0x30);
lcd_delay_ms(10);
}
void Delay_ms(unsigned int n)
{
unsigned int  i,j;
for(i=0;i<n;i++)
  for(j=0;j<123;j++);
}
```
HX711.c
```c
#include <HX711.h>
void Delay__hx711_us(void)
{
_nop_();
_nop_();
}
unsigned long HX711_Read00(void) //????128
{
unsigned long count;
unsigned char i;
   HX711_DOUT00=1;
Delay__hx711_us();
   HX711_SCK00=0;
   count=0;
   while(HX711_DOUT00);
   for(i=0;i<24;i++)
{
    HX711_SCK00=1;
    count=count<<1;
  HX711_SCK00=0;
    if(HX711_DOUT00)
   count++;
}
  HX711_SCK00=1;
    count=count^0x800000;//??25???????????????????????
Delay__hx711_us();
HX711_SCK00=0;  
return(count);
}
unsigned long HX711_Read01(void) //????128
{
unsigned long count;
unsigned char i;
   HX711_DOUT01=1;
Delay__hx711_us();
   HX711_SCK01=0;
   count=0;
   while(HX711_DOUT01);
   for(i=0;i<24;i++)
{
    HX711_SCK01=1;
    count=count<<1;
  HX711_SCK01=0;
    if(HX711_DOUT01)
   count++;
}
  HX711_SCK01=1;
    count=count^0x800000;//??25???????????????????????
Delay__hx711_us();
HX711_SCK01=0;  
return(count);
}
unsigned long HX711_Read02(void) //????128
{
unsigned long count;
unsigned char i;
   HX711_DOUT02=1;
Delay__hx711_us();
   HX711_SCK02=0;
   count=0;
   while(HX711_DOUT02);
   for(i=0;i<24;i++)
{
    HX711_SCK02=1;
    count=count<<1;
  HX711_SCK02=0;
    if(HX711_DOUT02)
   count++;
}
  HX711_SCK02=1;
    count=count^0x800000;//??25???????????????????????
Delay__hx711_us();
HX711_SCK02=0;  
return(count);
}
unsigned long HX711_Read03(void) //????128
{
unsigned long count;
unsigned char i;
   HX711_DOUT03=1;
Delay__hx711_us();
   HX711_SCK03=0;
   count=0;
   while(HX711_DOUT03);
   for(i=0;i<24;i++)
{
    HX711_SCK03=1;
    count=count<<1;
  HX711_SCK03=0;
    if(HX711_DOUT03)
   count++;
}
  HX711_SCK03=1;
    count=count^0x800000;//??25???????????????????????
Delay__hx711_us();
HX711_SCK03=0;  
return(count);
}
```
接下來要?jiǎng)觿?dòng)我們的小手來準(zhǔn)備搭建電路啦;


![如圖所示藍(lán)牙界面](

https://img-blog.csdnimg.cn/20200516232939851.jpg?x-oss


資料:http://www.torrancerestoration.com/bbs/dpj-92524-1.html

20200518173223.png (166.59 KB, 下載次數(shù): 37)

20200518173223.png

51hei.png (7.95 KB, 下載次數(shù): 28)

51hei.png

壓力檢測.zip

81.86 KB, 下載次數(shù): 16, 下載積分: 黑幣 -5

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

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

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表