Design of 51 single chip electronic scale based on hx711

The electronic scale is an electronic weighing device that integrates modern sensor technology, electronic technology and computer technology to meet and solve the “fast, accurate, continuous and automatic” weighing requirements proposed in real life, and effectively eliminate human error. It is more in line with the application requirements of legal metrology management and industrial production process control.

Design of 51 single chip electronic scale based on hx711

hardware design

Design of 51 single chip electronic scale based on hx711

The load cell senses the measured gravity and outputs a weak millivolt-level voltage signal. The voltage signal is conditioned and converted by the electronic scale dedicated analog/digital (A/D) converter chip hx711. The HX711 adopts the patented technology of Haixin Technology IC. It is a 24-bit A/D converter chip designed for high-precision electronic scales. It has built-in gain control with high precision and stable performance. The HX711 chip communicates with the microcontroller through a 2-wire serial method. The MCU reads the measured data, performs calculation and conversion, and then displays it on the LCD screen.

The matrix keyboard is mainly used to calculate the amount. When the weight of the measured object is obtained, the user can input the unit price through the matrix keyboard, and the electronic scale automatically calculates the total amount and displays it on the LCD screen. The power supply system supplies power to the microcontroller, HX711 circuit and sensor.

24-digit AD conversion chip HX711 circuit for electronic scale

Design of 51 single chip electronic scale based on hx711
Design of 51 single chip electronic scale based on hx711

Single chip STC89C52 circuit

Design of 51 single chip electronic scale based on hx711
Design of 51 single chip electronic scale based on hx711

LCD circuit

Design of 51 single chip electronic scale based on hx711

Matrix keyboard circuit

Design of 51 single chip electronic scale based on hx711

The matrix keyboard can display 0-9 digits, a decimal point and five function keys. The keyboard scan signal is ROW1-ROW4, and the column scan signal is COL1-COL4. The line signal is an input signal, active low; the column signal is an output signal. When no key is pressed, even if the line scan inputs a low level signal, the column signal is still high; when the line scan is low and a key is pressed, the corresponding column outputs a low level. This low level signal can be positioned to the position where the key is pressed.

Sound and light alarm circuit

Design of 51 single chip electronic scale based on hx711

When the measured weight exceeds the range, beep and alert give a low level signal, the buzzer sounds and the alarm light is on.

Power circuit

Design of 51 single chip electronic scale based on hx711

The power supply is powered by a USB interface and the power supply voltage is 5V. At the same time, the USB interface is programmed by the conversion circuit including the PL2303 chip.

software design

The main program uses a timer to implement the function of weighing once every 0.5 seconds. The flow chart is as follows:

Design of 51 single chip electronic scale based on hx711Design of 51 single chip electronic scale based on hx711

Clock interrupt program flow chart keyboard scanner flow chart

Design of 51 single chip electronic scale based on hx711

Main program flow chart

Main program writing

The following describes the main.c main program, other programs are slightly.

(1) header files and some macro definitions

#include 《reg52.h》

#include "intrins.h"

#include 《string.h》

#include "lcd.h"

#include "hx711.h"

#include "keyboard.h"

/ / Define the range factor

#define RATIO 2114/1623

(2) Pin, constant, variable definition

/ / Define the logo

volaTIle bit FlagTest = 0;

/ / Timing test mark, set every 0.5 seconds, after the test is cleared

volaTIle bit FlagKeyPress = 0; //There is a key press flag, and the processing is cleared.

volaTIle bit FlagSetPrice = 0; //Price setting status flag, set to 1

// pin definition sbit LedA = P2^2;

Sbit beep = P1^0;

Sbit alert = P1^1;

/ / Display with the variable int Counter;

Uchar idata str1[6] = "000000";

Int i, iTemp; / / weighing variable

Unsigned long idata FullScale; // full scale AD value / 1000

Unsigned long AdVal; //AD sample value

Unsigned long weight; //weight value, unit g

Unsigned long idata price; //unit price, long integer value, the unit is

Unsigned long idata money; // total price, long integer value, the unit is

/ / keyboard processing variables

Uchar keycode; uchar DotPos;

// decimal point mark and location

(4) Subroutines

// integer to string function, conversion range 0--65536 void int2str(int x, char* str)

{

Int i=1;

Int tmp=10;

While(x/tmp!=0)

{

i++;

Tmp*=10;

}

Tmp=x;

Str[i]='\0';

While(i)1)

{

Str[--i]='0'+(tmp%10);

Tmp/=10;

}

Str[0]=tmp+'0';

}

/ / Re-recover the zero point, call before each measurement

Void To_Zero() {

FullScale=ReadCount()/1000;

Price=0;

}

/ / Display unit price, the unit is yuan, four-digit integer, two decimal places

Void Display_Price()

{

Unsigned int i,j;

display_GB2312_string(5,44," ");

i = price/100; //get the integer part

j = price - i*100;//get the fractional part

Int2str(i,str1); //Show the integer part

If (i)=1000)

{

display_GB2312_string(5,44,str1);

}

Else if (i)=100)

{

display_GB2312_string(5,52,str1);

}

Else if (i)=10)

{

display_GB2312_string(5,60,str1);

}

Else

{

display_GB2312_string(5,68,str1);

}

/ / Show the decimal point

display_GB2312_string(5,76, ".");

/ / Display the decimal part

Int2str(j,str1);

If (j"10)

{

display_GB2312_string(5,84, "0");

display_GB2312_string(5,92,str1);

}

Else

{

display_GB2312_string(5,84,str1);

}

}

/ / Display weight, unit kg, two integers, three decimals

Void Display_Weight()

{

Unsigned int i,j;

display_GB2312_string(3,60," "); //weight unit is g

i = weight/1000; //get the integer part

j = weight - i*1000;//get the fractional part

Int2str(i,str1);

If (i)=10)

{

display_GB2312_string(3,60,str1);

}

Else

{

display_GB2312_string(3,68,str1);

}

display_GB2312_string(3,76,".");

Int2str(j,str1);

If (j"10) else if (j"100)

{

display_GB2312_string(3,84,"0"));

display_GB2312_string(3,92,str1);

}

Else

{

display_GB2312_string(3,84,str1);

}

}

/ / Display the total price, the unit is the yuan, four-digit integer, two decimals

Void Display_Money()

{

Unsigned int i,j;

display_GB2312_string(7,44," ");

If (money)999999) //Out of display range

{

display_GB2312_string(7,44,"--------");

Return;

}

display_GB2312_string(7,44,str1);

}

Else if (i)=100)

{

display_GB2312_string(7,52,str1);

}

Else if (i)=10)

{

display_GB2312_string(7,60,str1);

}

Else

{

display_GB2312_string(7,68,str1);

}

/ / Show the decimal point

display_GB2312_string(7,76,"."); //Show fractional part

Int2str(j,str1);

If (j"10)

{

display_GB2312_string(7,84,"0"));

display_GB2312_string(7,92,str1);

}

Else

{

display_GB2312_string(7,84,str1);

}

}

/ / Data initialization

Void Data_Init()

{

Price = 0;

DotPos = 0;

Beep = 1;

Alert = 1;

}

/ / Pin configuration void Port_Init ()

{

}

/ / Timer 0 initialization

Void Timer0_Init()

{

ET0 = 1; //Allow timer 0 interrupt TMOD = 1;

/ / Timer working mode selection TL0 = 0x06;

TH0 = 0xf8; //The timer gives the initial value

TR0 = 1; //Start timer

}

//Timer 0 interrupt

Void Timer0_ISR (void) interrupt 1 using 0

{

TL0 = 0x06;

TH0 = 0xf8; //The timer gives the initial value

// refresh the weight every 0.5 seconds

Counter ++;

If (Counter 》= 200)

{

FlagTest = 1;

Counter = 0;

}

}

//===============main program====================/

Void main(void)

{

Rom_CS=1;

Initial_lcd();

EA = 0;

Data_Init();

Port_Init();

Timer0_Init(); //Initialization completed, open interrupt

EA = 1; //Backlight

LedA = 1;

Clear_screen(); //clear all dots

display_GB2312_string(1,1, "electronic scale initialization...");

To_Zero();

display_GB2312_string(1,1, "electronic scale initialization success");

display_GB2312_string(3,1,"Weight: kg");

display_GB2312_string(5,1, "Unit price: yuan");

display_GB2312_string(7,1,"Amount: Yuan");

Display_Price();

While(1)

{

//Weigh once every 0.5 seconds

If (FlagTest==1)

{

/ / Weigh, get the weight value weight, the unit is g

AdVal=ReadCount();

Weight=FullScale-AdVal/1000;

If (weight) 0x8000) weight=0;

Weight=10000*weight/FullScale;

Weight=weight*RATIO; //If overrange, then alarm

If (weight 》= 10000)

{

Beep = 0;

Alert = 0;

display_GB2312_string(3,60,"------");

display_GB2312_string(7,44,"--------");

}

/ / If you do not exceed the range

Else

{

Beep = 1;

Alert = 1; //display weight value

Display_Weight();

//If the unit price is set, calculate the price

If (FlagSetPrice == 1)

{

Money = weight*price/1000; //money unit is minute

/ / Show the total amount

Display_Money();

}

Else

{

display_GB2312_string(7,44," ");

}

/ / Clear test mark

FlagTest = 0;

}

}

/ / Get the button

Keycode = Getkeyboard(); //valid key value 0-15

If ((keycode"16)&&(FlagKeyPress==0))

{

FlagKeyPress = 1;

KeyPress(keycode);

FlagKeyPress = 0;

}

Delay(20);

}

}

ZGAR Disposable Vape

ZGAR Disposable Vape


ZGAR electronic cigarette uses high-tech R&D, food grade disposable pod device and high-quality raw material. All package designs are Original IP. Our designer team is from Hong Kong. We have very high requirements for product quality, flavors taste and packaging design. The E-liquid is imported, materials are food grade, and assembly plant is medical-grade dust-free workshops.


Our products include disposable e-cigarettes, rechargeable e-cigarettes, rechargreable disposable vape pen, and various of flavors of cigarette cartridges. From 600puffs to 5000puffs, ZGAR bar Disposable offer high-tech R&D, E-cigarette improves battery capacity, We offer various of flavors and support customization. And printing designs can be customized. We have our own professional team and competitive quotations for any OEM or ODM works.


We supply OEM rechargeable disposable vape pen,OEM disposable electronic cigarette,ODM disposable vape pen,ODM disposable electronic cigarette,OEM/ODM vape pen e-cigarette,OEM/ODM atomizer device.




Disposable E-cigarette, ODM disposable electronic cigarette, vape pen atomizer , Device E-cig, OEM disposable electronic cigarette

ZGAR INTERNATIONAL TRADING CO., LTD. , https://www.zgarette.com