51单片机驱动HX711,实现称重、单价选择、计价,显示使用的是LCD1602。已通过软件标定校准和砝码校准。附上视频链接:链接:https://pan.baidu.com/s/1laQH_O64TADYU5DC_vQFNQ
提取码:ljfe和源码。
单片机源程序如下:
- #include "lcd1602.h"
- #include "hx711.h"
- #include "key.h"
- typedef unsigned char u8;
- typedef unsigned int u16;
- u8 code word[] = "Weight: . KG";
- u8 word1[] = "SP:";
- u8 Weight_Val[5];
- u8 Price_Val[4];
- float Total_Price;
- void Weight_Datapro(unsigned int value)
- {
- Weight_Val[0] = value / 10000;
- Weight_Val[1] = value % 10000 / 1000;
- Weight_Val[2] = value % 1000 / 100;
- Weight_Val[3] = value % 100 / 10;
- Weight_Val[4] = value % 10;
-
- DisplayOneChar(7,0,Weight_Val[0]+0x30);
- DisplayOneChar(8,0,Weight_Val[1]+0x30);
- DisplayOneChar(10,0,Weight_Val[2]+0x30);
- DisplayOneChar(11,0,Weight_Val[3]+0x30);
- DisplayOneChar(12,0,Weight_Val[4]+0x30);
- }
- void Price_Datapro(unsigned int value)
- {
- value /= 10;
- Price_Val[0] = value / 1000;
- Price_Val[1] = value % 1000 /100;
- Price_Val[2] = value % 100 / 10;
- Price_Val[3] = value % 10;
-
- DisplayOneChar(8,1,Price_Val[0]+0x30);
- DisplayOneChar(9,1,Price_Val[1]+0x30);
- DisplayOneChar(10,1,'.');
- DisplayOneChar(11,1,Price_Val[2]+0x30);
- DisplayOneChar(12,1,Price_Val[3]+0x30);
- DisplayOneChar(13,1,'
- );
- }
- void main(void)
- {
- LcdInit();
- LcdShowStr(0, 0, word);
- LcdShowStr(0, 1, word1);
- LcdShowStr(5, 1, "TP:");
- Get_Maopi();
-
- while(1)
- {
- Key_Down();
- Get_Weight();
- Weight_Datapro(Weight_Shiwu);
- Total_Price = price * Weight_Shiwu;
- Price_Datapro(Total_Price);
- }
- }
复制代码
所有资料51hei提供下载:
QX-1602.rar
(47.02 KB, 下载次数: 69)
|