#include<reg51.h>
#include<intrins.h>
#include<stdio.h>
sbit rs=P3^6;
sbit en=P3^7;
sbit eoc=P2^1;
sbit soc=P2^0;
sbit cha=P2^2;
sbit chb=P2^3;
sbit chc=P2^4;
void cmdwrt();
void delay();
void datawrt();
void asc();
void valconv();
unsigned char dis[6]={0x30,0x38,0x08,0x0c,0x06,0x80};
unsigned char a,b,c,d;
main()
{
int i;
for( i=0;i<6;i++)
{
a=dis;
cmdwrt();
delay();
}
//select channel
cha=0;
chb=0;
chc=0;
while(1)
{
a=0x80;
cmdwrt();
delay();
eoc=0x01;
soc=0x00;
delay();
soc=0x01;
delay();
soc=0x00;
while(eoc); //wait for conversion
delay();
a=P1;
asc(); //display
delay();
}
}
void asc()
{
d=a;
a=a>>4;
a=a & (0x0f);
valconv(); //conv to ascii
datawrt(); //disp on LCD
a=d;
a=a & (0x0f);
valconv();
datawrt();
}
void valconv()
{
if(a <= (0x09))
{
a=a+ (0x30);
}
else
{
a=a+ (0x37);
}
}
void cmdwrt()
{
rs=0;
P0=a;
en=1;
delay();
en=0;
}
void datawrt()
{
rs=1;
P0=a;
en=1;
delay();
en=0;
}
void delay()
{
int i;
for(i=0;i<1000;i++);
}