1、首先是系统初始化
Init_LCD1602(); //初始化LCD1602
EA = 0;
Data_Init();
Timer0_Init();
//初中始化完成,开断
EA = 1;
// Get_Maopi();
LCD1602_write_com(0x80); //指针设置
LCD1602_write_word(" Welcome To Use "); //
LCD1602_write_com(0x80+0x40); //指针设置
LCD1602_write_word("Wlectronic Scale");
// Delay_ms(2000);
Get_Maopi();
LCD1602_write_com(0x80); //指针设置
LCD1602_write_word("WE:0.000 PR:00.0");
LCD1602_write_com(0x80+0x40); //指针设置
LCD1602_write_word("MONEY: 0.00 ");
Display_Price();
// Get_Maopi(); //称毛皮重量
2、液晶显示程序
//****************************************************
//MS延时函数(12M晶振下测试)
//****************************************************
void LCD1602_delay_ms(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<123;j++);
}
//****************************************************
//写指令
//****************************************************
void LCD1602_write_com(unsigned char com)
{
LCD1602_RS = 0;
LCD1602_delay_ms(1);
LCD1602_EN = 1;
LCD1602_PORT = com;
LCD1602_delay_ms(1);
LCD1602_EN = 0;
}
//****************************************************
//写数据
//****************************************************
void LCD1602_write_data(unsigned char dat)
{
LCD1602_RS = 1;
LCD1602_delay_ms(1);
LCD1602_PORT = dat;
LCD1602_EN = 1;
LCD1602_delay_ms(1);
LCD1602_EN = 0;
}
3、按键程序
unsigned char Getkeyboard(void)
{
unsigned char number = 0;
unsigned char i;
//行输入低电平
ROW1=ROW2=ROW3=ROW4=0;
//如果列输出不全为高,则说明有键按下
if ((COL1!=1)||(COL2!=1)||(COL3!=1)||(COL4!=1))
{
//输入0111
ROW1=0;
ROW2=ROW3=ROW4=1;
for (i=0;i<20;i++);
if (COL1==0) return 1; // 7
else if (COL2==0) return 2; // 8
else if (COL3==0) return 3; // 9
else if (COL4==0) return 10; // 10
//输入1011
ROW2=0;
ROW1=ROW3=ROW4=1;
for (i=0;i<20;i++);
if (COL1==0) return 4; //4
else if (COL2==0) return 5; // 5
else if (COL3==0) return 6; // 6
else if (COL4==0) return 11; // 11
//输入1101
ROW3=0;
ROW1=ROW2=ROW4=1;
for (i=0;i<20;i++);
if (COL1==0) return 7; //1
else if (COL2==0) return 8; // 2
else if (COL3==0) return 9; // 3
else if (COL4==0) return 12; // 12
//输入0111
ROW4=0;
ROW1=ROW2=ROW3=1;
for (i=0;i<20;i++);
if (COL1==0) return 14;
else if (COL2==0) return 0;
else if (COL3==0) return 15;
else if (COL4==0) return 13;
//没有检测到列低电平
return 99;
}
return 99;
}
4、核心算法程序
//****************************************************
//读取HX711
//****************************************************
unsigned long HX711_Read(void) //增益128
{
unsigned long count;
unsigned char i;
HX711_DOUT=1;
Delay__hx711_us();
HX711_SCK=0;
count=0;
while(HX711_DOUT);
for(i=0;i<24;i++)
{
HX711_SCK=1;
count=count<<1;
HX711_SCK=0;
if(HX711_DOUT)
count++;
}
HX711_SCK=1;
count=count^0x800000;//第25个脉冲下降沿来时,转换数据
Delay__hx711_us();
HX711_SCK=0;
return(count);
}