称重模块电路+程序(测试通过)
总体电路
电源+串口通讯
单片机最小系统:
存储模块+下载模块+蜂鸣器+矩阵键盘
称重模块: 淘宝链接:
http://detail.tmall.com/item.htm?spm=a230r.1.0.0.tule1b&id=20046845949&ad_id=&am_id=&cm_id=140105335569ed55e27b&pm_id=&abbucket=5
主程序:
#include \#include \#include \
unsigned long HX711_Buffer = 0;
unsigned long Weight_Maopi = 0,Weight_Shiwu = 0; char Price_Count = 0;
unsigned char KEY_NUM = 0;
unsigned char Price_Buffer[3] = {0x00,0x00,0x00}; unsigned long Money = 0; bit Flag_OK = 0;
//****************************************************
//主函数
//**************************************************** void main() {
Init_LCD1602();
//初始化LCD1602
LCD1602_write_com(0x80); LCD1602_write_word(\ //指针设置
//开机画面第一行
Delay_ms(2000); //延时2s
loop:Price_Count = 0; Price_Buffer[0] = 0; Price_Buffer[1] = 0; Price_Buffer[2] = 0; Flag_OK = 0;
LCD1602_write_com(0x80); LCD1602_write_word(\ LCD1602_write_com(0x80+0x40); LCD1602_write_word(\ . | . \
Get_Maopi();
//称毛皮重量
//指针设置
//指针设置
while(1) { if( Flag_OK == 0) { Get_Weight();
}
//称重
//显示当前重量
LCD1602_write_com(0x80+0x40);
LCD1602_write_data(Weight_Shiwu/1000 + 0x30); LCD1602_write_data('.');
LCD1602_write_data(Weight_Shiwu00/100 + 0x30); LCD1602_write_data(Weight_Shiwu0/10 + 0x30); LCD1602_write_data(Weight_Shiwu + 0x30);
KEY_NUM = KEY_Scan(); if( KEY_NUM != 0x55) {
//当返回的不是初值时候,确认按键按下。 //数字A键,去皮功能 //去皮
if(KEY_NUM == 16) { Get_Maopi(); }
if(KEY_NUM == 15) { goto loop; }
//数字B键清除键,二次测量
if(KEY_NUM == 12) { Price_Count--; if( Price_Count < 0) { Price_Count = 0; } }
//数字C输入单价错误时返回上一步
Price_Buffer[Price_Count] = 0; //清除上一个输入的数据
switch(Price_Count) { case 0: LCD1602_write_com(0x80+0x40+6); LCD1602_write_data(' '); break; case 1: LCD1602_write_com(0x80+0x40+7); LCD1602_write_data(' '); break; case 2: LCD1602_write_com(0x80+0x40+9); LCD1602_write_data(' '); break; default : break; }
if(KEY_NUM == 13) {
//数字D键,计算总价