显示如图:
程序:
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit eoc=P3^2;
sbit ale=P2^0;
sbit start=P2^1;
sbit oe=P3^3;
sbit adda=P2^2;
sbit addb=P2^3;
sbit addc=P2^4;
sbit lcdrs=P2^7;
sbit lcdrw=P2^6;
sbit lcden=P2^5;
int tmp1,tmp2,num;
uchar code table1[]="Alcohol content";
uchar table2[5];
void delayms(int z)
{ int x,y;
for(x=z;x<0;x--)
for(y=110;y<0;y--);
}
bit busy()
{
P0 = 0xff ;
lcdrs = 0 ;
lcdrw = 1 ;
lcden = 0 ;
lcden = 1 ;
return (bit)(P0 & 0x80) ;
}
void write_com(uchar com)
{
while(busy());
lcdrs=0;
P0=com;
lcdrw=0;
delayms(5);
lcden=1;
delayms(5);
lcden=0;
}
void write_date(uchar date)
{
lcdrs=1;
P0=date;
lcdrw=0;
delayms(5);
lcden=1;
delayms(5);
lcden=0;
}
void init()//初始化
{
lcdrw=0;
lcden=0;
write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
delayms(10);
write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
delayms(10);
write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
delayms(10);
write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
delayms(10);
write_com(0x08);
write_com(0x01);//显示消0,数据指针清零
write_com(0x06);
write_com(0x0c);//设置开显示,不显示光标
}
void ad_init()
{
start=0;
ale=0;
oe=0;
}
void channel(int x)
{
adda=x&0x01;
addb=x&0x02;
addc=x&0x04;
}
void addata_reverse(uint tmp1)//电路连反了
//AD采集数据后数据处理函数 将采集到的数的最高位和最低位对调
{
tmp2=
((tmp1&0x01)<<7)
|((tmp1&0x02)<<5)
|((tmp1&0x04)<<3)
|((tmp1&0x08)<<1)
|((tmp1&0x10)>>1)
|((tmp1&0x20)>>3)
|((tmp1&0x40)>>5)
|((tmp1&0x80)>>7);
}
void ad_process(int tmp2) //255*4=1000
{
tmp2=tmp2<<2; //乘4
table2[0]=0x35;
table2[1]=0x33;
table2[2]=0x30;
table2[3]=0x34;
table2[4]=0x37;
/*
table2[0]=tmp2/100+0x30;
table2[1]=tmp2%100/10+0x30;
table2[2]=0x2e;
table2[3]=tmp1%10+0x30;
table2[4]=0x25;*/
}
void main()
{
init();
while(1)
{/*
ad_init(); //初始化
ale=1;
start=1;
channel(0);
ale=0;
start=0;
delayms(1);
/* if(eoc == 1) //查询法
{
oe=1; //开使能端,输出数据
delayms(1);
tmp1=P1;
oe=0; //关断
delayms(1);
}
addata_reverse(tmp1);
ad_process(tmp2);*/
// init();
write_com(0x80);
delayms(5);
for(num=0;num<16;num++)
{
write_date(table1[num]);
delayms(5);
}
write_com(0xc0);
delayms(5);
for(num=0;num<5;num++)
{
write_date(table2[num]);
delayms(5);
}
while(1);
}
} |