基于压力传感器的测重系统
扫描二维码
随时随地手机看文章
#include
unsigned char code dispbitcode[]={0xfe,0xfd,0xfb,0xf7,
0xff,0xff,0xff,0xff};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x00};
unsigned char dispbuf[8]={0,0,0,0,0,0,0,0};
unsigned char dispcount;
unsigned char getdata;
unsigned int temp;
unsigned char i,m=1;
sbit ST=P3^0;
sbit OE=P3^1;
sbit EOC=P3^2;
sbit CLK=P3^3;
/********延时字程序************/
void delay10ms()
{
unsigned char j,k;
for(j=20;j>0;j--)
for(k=248;k>0;k--);
}
/********键盘扫描************
void scan_key()
{
}
/********主程序************/
void main(void)
{
ST=0;
OE=0;
ET0=1;
ET1=1;
EA=1;
TMOD=0x12;
TH0=216;
TL0=216;
TH1=(65536-4000)/256;
TL1=(65536-4000)%256;
TR1=1;
TR0=1;
ST=1;
ST=0;
while(1)
{
if(EOC==1)
{
OE=1;
getdata=P0;
OE=0;
temp=getdata*250;
temp=temp/128;
i=0;
dispbuf[0]=0;
dispbuf[1]=0;
dispbuf[2]=0;
dispbuf[3]=0;
dispbuf[4]=10;
dispbuf[5]=10;
dispbuf[6]=10;
dispbuf[7]=10;
// scan_key();
while(temp/10)
{
dispbuf=temp%10;
temp=temp/10;
i++;
}
dispbuf=temp;
ST=1;
ST=0;
}
}
}
/********中断程序************/
void t0(void) interrupt 1 using 0
{
CLK=~CLK;
}
void t1(void) interrupt 3 using 0
{
TH1=(65536-4000)/256;
TL1=(65536-4000)%256;
P1=dispcode[dispbuf[dispcount]];
P2=dispbitcode[dispcount];
dispcount++;
/*if(dispcount>2)
{
P1=P1 | 0x80;
}
if(dispcount==4)
{
P1=dispcode[m];
}*/
if(dispcount==8)
{
dispcount=0;
}
}