|
44~FEI6O2TAEG%LA2V]E$`Y.png (48.78 KB, 下載次數: 64)
下載附件
2020-12-5 19:24 上傳
單片機源程序如下:
#include <reg52.h>
#include <intrins.h>
#include <string.h>
bit bdata flag_key;
#include "main.h"
#include "LCD1602.h"
#include "HX711.h"
#include "keyboard.h"
#include "eeprom52.h"
#include "tlc549.h"
#define uchar unsigned char
#define uint unsigned int
unsigned long HX711_Buffer = 0;
unsigned long Weight_Maopi = 0;
unsigned long Weight_Maopi_0 = 0;
unsigned int qupi=0;
long Weight_Shiwu = 0;
//鍵盤處理變量
unsigned char keycode;
unsigned char DotPos; //小數點標志及位置
uint GapValue,GapValue1;
unsigned char idata price; //單價,長整型值,單位為分
unsigned char idata money; //總價,長整型值,單位為分
unsigned char idata lm35;
//定義標識
volatile bit FlagTest = 0; //定時測試標志,每0.5秒置位,測完清0
volatile bit FlagKeyPress = 0; //有鍵按下標志,處理完畢清0
//校準參數
//因為不同的傳感器特性曲線不是很一致,因此,每一個傳感器需要矯正這里這個參數才能使測量值很準確。
//當發現測試出來的重量偏大時,增加該數值。
//如果測試出來的重量偏小時,減小改數值。
//該值可以為小數
//#define GapValue 349
sbit LED=P3^2;
volatile bit ClearWeighFlag = 0; //傳感器調零標志位,清除0漂
/******************把數據保存到單片機內部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);
}
/******************把數據從單片機內部eeprom中讀出來*****************/
void read_eeprom()
{
GapValue = byte_read(0x2001);
GapValue = (GapValue<<8)|byte_read(0x2000);
a_a = byte_read(0x2060);
}
/**************開機自檢eeprom初始化*****************/
void init_eeprom()
{
read_eeprom(); //先讀
if(a_a != 1) //新的單片機初始單片機內問eeprom
{
GapValue = 3500;
a_a = 1;
write_eeprom(); //保存數據
}
}
//顯示單價,單位為元,四位整數,兩位小數
void Display_Price()
{
LCD1602_write_com(0x8c);
LCD1602_write_data(price/100 + 0x30);
LCD1602_write_data(price%100/10 + 0x30);
LCD1602_write_data('.');
LCD1602_write_data(price%10 + 0x30);
}
//顯示重量,單位kg,兩位整數,三位小數
void Display_Weight()
{
LCD1602_write_com(0x82);
LCD1602_write_data(Weight_Shiwu/10000 + 0x30);
LCD1602_write_data(Weight_Shiwu%10000/1000 + 0x30);
LCD1602_write_data('.');
LCD1602_write_data(Weight_Shiwu%1000/100 + 0x30);
LCD1602_write_data(Weight_Shiwu%100/10 + 0x30);
LCD1602_write_data(Weight_Shiwu%10 + 0x30);
LCD1602_write_word("K ");
}
//顯示總價,單位為元,四位整數,兩位小數
void Display_Money()
{
// unsigned int i,j;
if (money>9999) //超出顯示量程
{
LCD1602_write_com(0xC2);
LCD1602_write_word("---.-");
return;
}
if (money>=1000)
{
LCD1602_write_com(0XC2);
LCD1602_write_data(money/1000 + 0x30);
LCD1602_write_data(money%1000/100 + 0x30);
LCD1602_write_data(money%100/10 + 0x30);
LCD1602_write_data('.');
LCD1602_write_data(money%10 + 0x30);
}
else if (money>=100)
{
LCD1602_write_com(0XC2);
LCD1602_write_data(0x20);
LCD1602_write_data(money%1000/100 + 0x30);
LCD1602_write_data(money%100/10 + 0x30);
LCD1602_write_data('.');
LCD1602_write_data(money%10 + 0x30);
}
else if(money>=10)
{
LCD1602_write_com(0XC2);
LCD1602_write_data(0x20);
LCD1602_write_com(0XC3);
LCD1602_write_data(0x20);
LCD1602_write_data(money%100/10 + 0x30);
LCD1602_write_data('.');
LCD1602_write_data(money%10+ 0x30);
}
else
{
LCD1602_write_com(0XC2);
LCD1602_write_data(0x20);
LCD1602_write_com(0xC3);
LCD1602_write_data(0x20);
LCD1602_write_com(0xC4);
LCD1602_write_data(0 + 0x30);
LCD1602_write_data('.');
LCD1602_write_data(money%10 + 0x30);
}
}
void Display_lm35()
{
LCD1602_write_com(0xcc);
lm35=lm35/10;
LCD1602_write_data(lm35*2/100+ 0x30);
LCD1602_write_data(lm35*2%100/10+0x30);
LCD1602_write_data('.');
LCD1602_write_data(lm35*2%10+ 0x30);
}
//數據初始化
void Data_Init()
{
price = 0;
DotPos = 0;
lm35=0;
money=0;
}
|
評分
-
查看全部評分
|