#include<reg51.h>
sbit A0 = P0^0;
sbit A1 = P0^1;
sbit A2 = P0^2;
sbit ADC_ALE = P0^3;
sbit ADC_OE = P0^4;
sbit ADC_EOC = P0^5;
sbit ADC_START = P0^7;
void msdelay(unsigned int);
void main(void)
{
while(1)
{
P0 = 0x00; // making all the bits of ports as 0
A0 = 1;
A1 = 1;
A2 = 1; // Selecting input channel 7 by putting A1 , A2 and A3 = 1
ADC_ALE = 0;
msdelay(50);
ADC_ALE =1; // this address of analog channel is latched with rising edge of ALE
msdelay(50);
ADC_START = 1;
msdelay(50);
ADC_START = 0; // falling edge of ADC_START atarts the conversion of ADC
msdelay(50);
if(ADC_EOC = 1)
{
ADC_OE = 1;
msdelay(50);
ADC_OE = 0;
msdelay(50);
}
}
}
//----------------------------- Delay Routine ---------------------
void msdelay(unsigned int i)
{
unsigned int j,k;
for(j=1; j<=i;j++)
{
for(k=1;k<=1275;k++)
{
}
}
}