0% found this document useful (0 votes)
75 views2 pages

ADC Prog

This C program is reading an analog input from a pin and displaying the value on an LCD. It defines functions for sending data to the LCD and inserting delays. The main function sets up timers and ports, then enters a loop to continually read the analog pin, convert the value to a 3 digit number, and display it on the LCD.

Uploaded by

chandrasekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views2 pages

ADC Prog

This C program is reading an analog input from a pin and displaying the value on an LCD. It defines functions for sending data to the LCD and inserting delays. The main function sets up timers and ports, then enters a loop to continually read the analog pin, convert the value to a 3 digit number, and display it on the LCD.

Uploaded by

chandrasekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <REGX51.

H> void delay(unsigned int msec) // Function to


#define ADC P1 provide time delay in msec.
{
sbit CH1 = P2^0; int i,j ;
sbit CH2 = P2^1; for(i=0;i<msec;i++)
sbit CH3 = P2^2; for(j=0;j<1275;j++);
}
sbit ALE=P2^3;
sbit OE=P2^4; void send(unsigned char dat) //Function to
send command to LCD
sbit SC=P2^5; {
sbit EOC=P2^6; TI=0;
void send(unsigned char); SBUF=dat;
unsigned char x,y,z; while(TI==0);
void delay(unsigned int msec); TI=0;
unsigned char val; }

void main()
{ ADC Program
TMOD=0x20;
SCON=0x50;
TH1=-3;
TR1=1;
EOC = 1; /* EOC as input */
ALE = OE = SC = 0;
while(1)
{
CH1=1;
CH2=0;
CH3=0;
ALE=1;
SC=1;
ALE=0;
SC=0;
while(EOC==1);
while(EOC==0);
OE=1;
val=ADC;

send('A');
x=val/100;
send(x+0x30);

y=((val%100)/10);
send(y+0x30);

z=val%10;
send(z+0x30);
delay(1);
OE=0;
}
}

You might also like