#include<reg51.h>
sfr adcdata = 0x90; //assigning adc data to port 1
sfr ldata = 0x80 ; //assigning lcd data to port 0
sbit rs=P2^7; // assining control pins to port2.5,6,7
sbit rw=P2^6;
sbit en=P2^5;
// channel selection bits of adc
sbit addr_c=P3^2;
sbit addr_b=P3^3;
sbit addr_a=P3^4;
// control pins of adc
sbit ale=P3^5; //address latch enble pin
sbit eoc=P3^6; // end of converssion pin
sbit sc=P3^7; //select chip pin
sbit oe=P3^1;
sbit wave = P2^4;
void delay(unsigned int k);
void cmd(unsigned char y); //lcd command function
void lcddata(unsigned char y);
void lcdinit(void);
unsigned char z;
unsigned char convertanddisplay(unsigned char value)
{
unsigned char x,d1,d2,d3;
d1=value%10;
value=value/10;
d2=value%10;
value=value/10 ;
d3=value%10 ;
lcddata(d3+0x30) ;
lcddata(d2+0x30) ;
lcddata(d1+0x30) ;
cmd(0x01); //move data d1 to lcd
z=d1*100+d2*10+d3;
delay(1) ;
return(z);
}
void timer0(void) interrupt 1
{
wave= ~wave ;
}
void main()
{
unsigned char value;
TMOD =0x02;
TH0=-1;
IE=0x82;
TR0=1 ;
adcdata=0xff;
eoc =1 ;
ale = 0;
oe=0 ;
lcdinit();
sc=0 ;
while(1)
{
addr_c=0;
addr_b=0;
addr_a=1;
delay(1);
ale=1;
delay(1);
sc=1;
delay(1);
ale=0;
sc=0;
while(eoc==1);
while(eoc==0);
oe=1;
//delay(1);
value=adcdata;
z= convertanddisplay(value);
oe=0;
}
}
void delay(unsigned int k)
{
unsigned int i,j;
for(i=0;i<k;i++)
for(j=0;j<1200;j++);
}
void cmd(unsigned char ch)
{
ldata = ch;
rs = 0;
rw = 0;
en = 1;
delay(1);
en = 0;
return;
}
void lcddata(unsigned char cm)
{
ldata = cm;
rs = 1;
rw = 0;
en = 1;
delay(1);
en=0;
return;
}
void lcdinit() //lcd initialize
{
cmd(0x38); // 2 lines and 5x7 matrix
cmd(0x0e); //display on, cursor blinking
cmd(0x01); //clear display screen
cmd(0x06); //increment cursor
cmd(0x80);
}