#include "keyscan.h"
#define uchar unsigned char
unsigned char JP()
{
unsigned char x=0x00;
bit i=0;
x=P2; //é¨ÃèY×ø±ê
delay(125); //Ïû¶¶
P2=0x0f;
delay(2);
x+=P2; //é¨ÃèX×ø±ê
switch(x)
{
case 0xee:x=0x30;break; //°′ÏÂ0
case 0xed:x=0x31;break; //°′ÏÂ1
case 0xeb:x=0x34;break; //°′ÏÂ4
case 0xe7:x=0x37;break; //°′ÏÂ7
case 0xde:x=0x46;break; //°′ÏÂF/.
case 0xdd:x=0x32;break; //°′ÏÂ2
case 0xdb:x=0x35;break; //°′ÏÂ5
case 0xd7:x=0x38;break; //°′ÏÂ8
case 0xbe:x=0x45;break; //°′ÏÂE
case 0xbd:x=0x33;break; //°′ÏÂ3
case 0xbb:x=0x36;break; //°′ÏÂ6
case 0xb7:x=0x39;break; //°′ÏÂ9
case 0x7e:x=0x44;break; //°′ÏÂD
case 0x7d:x=0x43;break; //°′ÏÂC
case 0x7b:x=0x42;break; //°′ÏÂB
case 0x77:x=0x41;break; //°′ÏÂA
default:x=0xff;break;
}
while(i==0) //°′¼üËé¿a
{
P2=0xf0;
delay(150);
if(P2==0xf0)
{
i=1;
}
else{i=0;}
}
return x; //·μ»Øx(ASCIIÂë)
}
//--------------------Ñóê±oˉêy--------//
void delay(unsigned char m)
{
uchar i,j;
for(i=0;i<m;i++)
{
for(j=0;j<121;j++)
{;}
}
}
#include "main.h"
#include "LCD12864.h"
#include "HX711.h"
#include "keyscan.h"
#define uchar unsigned char
#define uint unsigned int
unsigned long HX711_Buffer = 0;
//****************************************************
//Ö÷oˉêy
//****************************************************
void main(void)
{
uchar LCD[16]={"0123456789ABCDEF"};
code uchar JM1[]={0xb5,0xda,0xc8,0xfd,0xd7,0xe9,0xb5,0xe7,0xd7,0xd3,0xb3,0xc6};
code uchar JM2[]={"μ¥¼Û: 00.0 "};
code uchar JM3[]={"ÖØá¿: 00.000KG "};
code uchar JM4[]={"×ü¼Û: 0000.0Ôa "};
uchar DJ[3]; //μ¥¼Û
uchar ZL[5]; //ÖØá¿
uchar QPZL[5]; //è¥ƤoóμÄÖØá¿
uchar ZJ[5]; //×ü¼Û
unsigned long J1;
uint J2,J3,J6=0;
bit J5=1;
uint J7;
uchar i;
uchar JM5[]={5679};
LCD12864_Reset(); //3õê¼»ˉ
for(i=0;i<3;i++) //μ¥¼Ûêäèë
{
DJ[i]=0;
}
for(i=0;i<5;i++) //ÖØá¿
{
ZL[i]=0;
}
for(i=0;i<5;i++) //¾»ÖØ
{
QPZL[i]=0;
}
for(i=0;i<5;i++) //×ü¼Û
{
ZJ[i]=0;
}
LCD12864_COM_Write(0x81); //¶¨Î»
for(i=0;i<12;i++)
{
LCD12864_Data_Write(JM1[i]); //ÏÔê¾μúèy×éμç×ó3ó
}
LCD12864_COM_Write(0x90); //¶¨Î»
for(i=0;JM2[i]!='\0';i++)
{
LCD12864_Data_Write(JM2[i]); //ÏÔê¾μ¥¼Û:00.0Ôa
}
LCD12864_COM_Write(0x88); //¶¨Î»
for(i=0;JM3[i]!='\0';i++)
{
LCD12864_Data_Write(JM3[i]); //ÏÔê¾ÖØá¿: 00.000KG
}
LCD12864_COM_Write(0x98); //¶¨Î»
for(i=0;JM4[i]!='\0';i++)
{
LCD12864_Data_Write(JM4[i]); //×ü¼Û: 0000.0Ôa
}
P2=0xf0;
while(1)
{
while(P2==0xf0) //μ±Ã»óD°′¼ü°′ÏÂê±½øè룬óD°′¼ü°′ÏÂê±ìø3öà′
{
J1=HX711_Read(); //¶áè¡ADÖμ
J3=((J1-8388608)/150)-11; //è¡Öμ
ZL[0]=(J3/10000)%10; //ÖØá¿ê®Î»
if(ZL[0]>3){FMQ=0;} //3¬Öر¨¾ˉ
else{FMQ=1;}
ZL[1]=(J3/1000)%10; //ÖØῸöλ
ZL[2]=(J3/100)%10; //¼ÆËãλ
ZL[3]=(J3/10)%10;
ZL[4]=J3%10;
J7=ZL[4];
J7+=ZL[3]*10;
J7+=ZL[2]*100;
J7+=ZL[1]*1000;
J7+=ZL[0]*10000;
J3=QPZL[4];
J3+=QPZL[3]*10;
J3+=QPZL[2]*100;
J3+=QPZL[1]*1000;
J3+=QPZL[0]*10000;
J7-=J3;
ZL[0]=J7/10000;
J7%=10000;
ZL[1]=J7/1000;
J7%=1000;
ZL[2]=J7/100;
J7%=100;
ZL[3]=J7/10;
J7%=10;
ZL[4]=J7;
LCD12864_COM_Write(0x8b); //¶¨Î»
LCD12864_Data_Write(LCD[ZL[0]]); //ËíÏÔê¾£¬ÏÂí¬
LCD12864_Data_Write(LCD[ZL[1]]);
LCD12864_Data_Write(0x2e);
LCD12864_Data_Write(LCD[ZL[2]]);
LCD12864_Data_Write(LCD[ZL[3]]);
LCD12864_Data_Write(LCD[ZL[4]]);
J7=DJ[2]*ZL[3];
J7+=DJ[2]*ZL[2]*10;
J7+=DJ[2]*ZL[1]*100;
J7+=DJ[2]*ZL[0]*1000;
J7/=10;
J7+=DJ[1]*ZL[3];
J7+=DJ[1]*ZL[2]*10;
J7+=DJ[1]*ZL[1]*100;
J7+=DJ[1]*ZL[0]*1000;
J7/=10;
J7+=DJ[0]*ZL[3];
J7+=DJ[0]*ZL[2]*10;
J7+=DJ[0]*ZL[1]*100;
J7+=DJ[0]*ZL[0]*1000;
ZJ[0]=J7/10000;
J7%=10000;
ZJ[1]=J7/1000;
J7%=1000;
ZJ[2]=J7/100;
J7%=100;
ZJ[3]=J7/10;
J7%=10;
ZJ[4]=J7;
LCD12864_COM_Write(0x9b);
i=ZJ[0];
i=LCD[i];
LCD12864_Data_Write(i);
i=ZJ[1];
i=LCD[i];
LCD12864_Data_Write(i);
i=ZJ[2];
i=LCD[i];
LCD12864_Data_Write(i);
i=ZJ[3];
i=LCD[i];
LCD12864_Data_Write(i);
LCD12864_Data_Write(0x2e);
i=ZJ[4];
i=LCD[i];
LCD12864_Data_Write(i);
P2=0xf0;
delay(1);
}
J2=JP();
if(J6>2){J6=0;}
if(J2<0x40)
{
J2-=0x30;
DJ[J6]=J2;
J2=0xff;
J6++;
}
else
{
switch(J2)
{
case 0x41:P2=0xf0;while(P2==0xf0);J2=0xff;break; //°′ÏÂAËø¶¨½çÃæ
case 0x42:J2=0xff;break; //½a3yËø¶¨
case 0x43:HX711_Read(); //è¥Ƥ
J3=((J1-8388608)/150)-11;
QPZL[0]=(J3/10000)%10;
QPZL[1]=(J3/1000)%10;
QPZL[2]=(J3/100)%10;
QPZL[3]=(J3/10)%10;
QPZL[4]=J3%10;
J2=0xff;
break;
case 0x44:DJ[0]=0;DJ[1]=0;DJ[2]=0;J6=0;J2=0xff;break; //μ¥¼Û¸′λ
case 0x45:QPZL[0]=0;QPZL[1]=0;QPZL[2]=0;QPZL[3]=0;QPZL[4]=0;J2=0xff;break; //ÖØῸ′λ
case 0x46:DJ[0]=0;DJ[1]=0;DJ[2]=0;J6=0;QPZL[0]=0;QPZL[1]=0;QPZL[2]=0;QPZL[3]=0;QPZL[4]=0;J2=0xff;break; //μ¥¼ÛÖØá¿ ¸′λ
default:break;
}
}
LCD12864_COM_Write(0x93);
i=DJ[0];
i=LCD[i];
LCD12864_Data_Write(i); |