新手上路
- 积分
- 40
- 金钱
- 40
- 注册时间
- 2014-4-25
- 在线时间
- 0 小时
|
发表于 2014-5-19 16:20:33
|
显示全部楼层
楼主帮我看一下,这段程序可以用12864显示不
#include "main.h"
#include "lcd.h"
#include <stdio.h>
#include "HX711.h"
unsigned char buf[20];
unsigned long HX711_Buffer = 0;
unsigned int Weight_Maopi = 0,Weight_Shiwu = 0; // Weight_Shiwu????
float Weight,Price,FMoney;
char rice_Count = 0; //×???
unsigned char KEY_NUM = 0;
unsigned char rice_Buffer[3] = {0x00,0x00,0x00};
unsigned long Money = 0;
bit Flag_OK = 0;
//****************************************************
//?÷????
//****************************************************
void main()
{
init_lcd(); //??????LCD
WriteString( 2, 0 ,"Welcome to use!") ;
/*
write_com(0x80); //?????è??
WriteStr("Welcome to use! "); //???ú??????????
*/
delayms(2000); //???±2s
delayms(2000);
delayms(2000);
ClrSreen();
looprice_Count = 0;
Price_Buffer[0] = 0;
Price_Buffer[1] = 0;
Price_Buffer[2] = 0;
Flag_OK = 0;
WriteString( 1 ,0,"??????0.000KG ") ;
WriteString( 2,0 ,"????: . ??") ;
WriteString( 3 ,0,"×????? . ??") ;
WriteString( 4,0, "??????????") ;
/*
write_com(0x80); //?????è??
WriteStr("+WEI |PRI | MON ");
write_com(0x80+0x40); //?????è??
WriteStr("0.000| . | . ");
*/
Get_Maopi(); //?????¤????
while(1)
{
if( Flag_OK == 0)
{
Get_Weight(); //????
write_com(0x80+3);
write_data(Weight_Shiwu/1000 + 0x30);
write_data('.');
write_data(Weight_Shiwu%1000/100 + 0x30);
write_data(Weight_Shiwu%100/10 + 0x30);
write_data(Weight_Shiwu%10 + 0x30);
//?????±?°????
/*
write_com(0x80+0x40);
write_data(Weight_Shiwu/1000 + 0x30);
write_data('.');
write_data(Weight_Shiwu%1000/100 + 0x30);
write_data(Weight_Shiwu%100/10 + 0x30);
write_data(Weight_Shiwu%10 + 0x30);
*/
}
KEY_NUM = KEY_Scan();
if( KEY_NUM != 0x55) //?±·??????????????±?ò???·??°??ü°?????
{
if(KEY_NUM == 16) //??×?A?ü?????¤????
{
Get_Maopi(); //???¤
}
if(KEY_NUM == 15) //??×?B?ü?????ü??????????
{
goto loop;
}
if(KEY_NUM == 12) //??×?C?????????í?ó?±·?????????
{
Price_Count--;
if( rice_Count < 0)
{
Price_Count = 0;
}
Price_Buffer[Price_Count] = 0; //????????????????????
switch(Price_Count)
{
case 0:
write_com(0x90+3);
write_data(' ');
break;
case 1:
write_com(0x80+3);
write_data(0x20);//
write_data(' ');
break;
case 2:
write_com(0x80+4);
write_data('.');
write_data(' ');
break;
default: break;
}
}
if(KEY_NUM == 13) //??×?D?ü??????×???
{
Money = rice_Buffer[0] * 100 + rice_Buffer[1] * 10 + rice_Buffer[2];
Money = Money * Weight_Shiwu / 1000;
write_com(0x88+3);
write_data(Money/1000 + 0x30);
write_data(Money%1000/100 + 0x30);
write_data(Money%100/10 + 0x30);
write_data('.');
write_data(Money%10 + 0x30);
/*
write_com(0x80+0x40+11);
write_data(Money/1000 + 0x30);
write_data(Money%1000/100 + 0x30);
write_data(Money%100/10 + 0x30);
write_data('.');
write_data(Money%10 + 0x30);
*/
Flag_OK = 1;
}
if(KEY_NUM >= 0 && KEY_NUM <= 9) //????????????????
{
Price_Buffer[Price_Count] = KEY_NUM;
switch(Price_Count)
{
case 0:
write_com(0x90+3);
write_data(Price_Buffer[0] + 0x30);
/*
write_com(0x80+0x40+6);
write_data(Price_Buffer[0] + 0x30);
*/
break;
case 1:
write_com(0x90+3);
write_data(0x20);//
write_data(Price_Buffer[1] + 0x30);
/*
write_com(0x80+0x40+7);
write_data(Price_Buffer[1] + 0x30);
*/
break;
case 2:
write_com(0x90+4);
write_data('.');//
write_data(Price_Buffer[2] + 0x30);
/*
write_com(0x80+0x40+9);
write_data(Price_Buffer[2] + 0x30);
*/
break;
default: break;
}
Price_Count++;
if( rice_Count >= 3)
{
Price_Count = 3;
}
}
}
}
}
//****************************************************
//???ó?ü???¨?è
//****************************************************
unsigned char KEY_Scan()
{
unsigned char temp = 0;
unsigned char com = 0x55 , com1 = 0 , com2 = 0;
P3=0xf0;
if(P3!=0xf0)
{
com1=P3;
P3=0x0f;
com2=P3;
}
P3=0xf0;
while(P3!=0xf0);
temp=com1|com2;
if(temp==0xee)com=1;//??×?1
if(temp==0xed)com=4;//??×?4
if(temp==0xeb)com=7;//??×?7
if(temp==0xe7)com=11;//±????ü*???ü
if(temp==0xd7)com=0;//??×?0
if(temp==0xb7)com=14;//±????ü*???ü
if(temp==0xde)com=2; //??×?2
if(temp==0xdd)com=5; //??×?5
if(temp==0xdb)com=8;//??×?8
if(temp==0xbe)com=3;//??×?3
if(temp==0xbd)com=6; //??×?6
if(temp==0xbb)com=9;//??×?9
if(temp==0x7e)com=16;//??×?A?ü?????¤????
if(temp==0x7d)com=15;//??×?B?ü?????ü??????????
if(temp==0x7b)com=12;//??×?C?????????í?ó?±·?????????
if(temp==0x77)com=13;//??×?D?ü??????×???
return(com);
}
//****************************************************
//????
//****************************************************
void Get_Weight()
{
HX711_Buffer = HX711_Read();
HX711_Buffer = HX711_Buffer/100;
if(HX711_Buffer > Weight_Maopi)
{
Weight_Shiwu = HX711_Buffer;
Weight_Shiwu = Weight_Shiwu - Weight_Maopi; //??????????AD???ù??????
Weight_Shiwu = (unsigned int)((float)Weight_Shiwu/4.22+0.05); //??????????????????
//?ò?????????????÷?????ú???????ù???ò???????????????÷?è????????????4.30??????????
//?±·????????????????????ó?±??????????????
//???????????????????????±??????????????
//????????°???4.0-5.0???????ò?????÷???????¨??
//+0.05?????????á????°?·???
Buzzer = 1; //??±???±¨
}
else if(HX711_Buffer < Weight_Maopi - 30)
{
Buzzer = 0; //??????±¨??
}
else if(HX711_Buffer > Weight_Maopi + 24970) //?ó??5Kg??×??ó??????±¨??
{
Buzzer = 0;
}
}
//****************************************************
//???????¤????
//****************************************************
void Get_Maopi()
{
HX711_Buffer = HX711_Read();
Weight_Maopi = HX711_Buffer/100;
}
//****************************************************
//MS???±????(12M?§????????)
//****************************************************
void Delay_ms(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<123;j++);> |
|