基于hx711的51单片机电子秤设计
_string(5,76,"。");
//显示小数部分
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);
}
}
//显示重量,单位kg,两位整数,三位小数
void Display_Weight()
{
unsigned int i,j;
display_GB2312_string(3,60," "); //weight单位是g
i = weight/1000; //得到整数部分
j = weight - i*1000;//得到小数部分
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);
}
}
//显示总价,单位为元,四位整数,两位小数
void Display_Money()
{
unsigned int i,j;
display_GB2312_string(7,44," ");
if (money》999999) //超出显示量程
{
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);
}
//显示小数点
display_GB2312_string(7,76,"。"); //显示小数部分
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);
}
}
//数据初始化
void Data_Init()
{
price = 0;
DotPos = 0;
beep = 1;
alert = 1;
}
//管脚配置 void Port_Init()
{
}
//定时器0初始化
void Timer0_Init()
{
ET0 = 1; //允许定时器0中断 TMOD = 1;
//定时器工作方式选择 TL0 = 0x06;
TH0 = 0xf8; //定时器赋予初值
TR0 = 1; //启动定时器
}
//定时器0中断
void Timer0_ISR (void) interrupt 1 using 0
{
TL0 = 0x06;
TH0 = 0xf8; //定时器赋予初值
//每0.5秒钟刷新重量
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(); //初始化完成,开中断
EA = 1; //背光
LedA = 1;
clear_screen(); //clear all dots
display_GB2312_string(1,1,"电子秤初始化。。。。");
To_Zero();
display_GB2312_string(1,1,"电子秤初始化成功");
display_GB2312_string(3,1,"重量: kg");
display_GB2312_string(5,1,"单价: 元");
display_GB2312_string(7,1,"金额: 元");
Display_Price();
while(1)
{
//每0.5秒称重一次
if (FlagTest==1)
{
//称重,得到重量值weight,单位为g
AdVal=ReadCount();
weight=FullScale-AdVal/1000;
if (weight》0x8000) weight=0;
weight=10000*weight/FullScale;
weight=weight*RATIO; //如果超量程,则报警
if (weight 》= 10000)
{
beep = 0;
alert = 0;
display_GB2312_string(3,60,"------");
display_GB2312_string(7,44,"--------");
}
//如果不超量程
else
{
beep = 1;
alert = 1; //显示重量值
Display_Weight();
//如果单价设定好了,则计算价格
if (FlagSetPrice == 1)
{
money = weight*price/1000; //money单位为分
//显示总金额
Display_Money();
}
else
{
display_GB2312_string(7,44," ");
}
//清测试标志
FlagTest = 0;
}
}
//获取按键
keycode = Getkeyboard(); //有效键值0-15
if ((keycode《16)&&(FlagKeyPress==0))
{
FlagKeyPress = 1;
KeyPress(keycode);
FlagKeyPress = 0;
}
delay(20);
}
}
- hx711管脚图及管脚描述(09-19)
- hx711简介_hx711主要参数(09-19)
- hx711管脚接口应用说明(09-19)
- hx711电路图(09-19)
- hx711的精度是多少_hx的精度怎么算(09-20)
- hx711驱动程序(09-19)