Many applications need to measure and/or monitor the physical quantities like temperature, pressure, light intensity etc. The sensors used to measure the physical quantities give the output in analog form, which are converted to digital through an ADC for further processing. This circuit demonstrates the principle and operation of interfacing ADC0808 with three LDR. The output of the sensor is displayed on the LCD. The external clock needed by the ADC0808 is provided by the controller using interrupt. The output is displayed on the LCD. The circuit is divided into four parts: LDR, ADC, 8051 microcontroller and LCD. Its applications could be measuring and monitoring the light intensity level.
ADC0808 is an 8-bit resolution ADC with eight input channels. At any point of time only one input can be read. The output of LDR
s are used as inputs. An LDR will detect the intensity of light and generate voltage depending upon light intensity.
Project Source Code
###
// Program to interface 3 LDRs with ADC 0808 using three input channels of ADC 0808. The output pins are connected to LCD to show intensity value between (0-255). Controller interrupt is used to generate the clock for driving the ADC 0808. #include<reg51.h> sbit ale=P1^0; //address latch enable sbit oe=P1^3; //output enable sbit sc=P1^1; //start conversion sbit eoc=P1^2; //end of conversion sbit clk=P1^7; // clock sbit ADD_A=P1^4; //Address pins for selecting input channels. sbit ADD_B=P1^5; sbit ADD_C=P1^6; sfr lcd_data_pin=0xA0; //Port P2 sbit rs=P3^0; sbit rw=P3^1; sbit en=P3^6; sfr input_port=0x80; //Port P0 unsigned int key,value,number,ascii1,ascii2,ascii3,flag,temp1,key1/*,data1,data2,data3,data11,data12,data13,data21,data22,data23*/; void timer0() interrupt 1 // Function to generate clock of frequency 500KHZ using Timer 0 interrupt. { clk=~clk; } void delay(unsigned int count) // Function to provide time delay in msec. { int i,j; for(i=0;i<count;i++) for(j=0;j<1275;j++); } void lcd_command(unsigned char comm) //Function to send command to LCD. { lcd_data_pin=comm; en=1; rs=0; rw=0; delay(1); en=0; } void lcd_data(unsigned char disp) //Function to send data to LCD. { lcd_data_pin=disp; en=1; rs=1; rw=0; delay(1); en=0; } lcd_dataa(unsigned char *disp) //Function to send string data to LCD. { int x; for(x=0;disp[x]!=0;x++) { lcd_data(disp[x]); } } void lcd_ini() //Function to inisialize the LCD { lcd_command(0x38); // for using 8-bit 2 row LCD delay(5); lcd_command(0x0F); // for display on cursor blinking delay(5); lcd_command(0x80); delay(5); //Force cursor to blink at line 1 positon 0 } void BCD() // Binary to decimal conversion to send the data to LCD { key1++; key=0; flag=0; number=input_port; value=number%10; number=number/10; ascii1=value+48; if(number!=0) { value=number%10; number=number/10; ascii2=value+48; flag=1; } else { ascii2=48; flag=1; } if(number!=0) { value=number%10; number=number/10; ascii3=value+48; key=2; } else { ascii3=48; key=2; } if(key1==1) { lcd_command(0xC0); } if(key1==2) { lcd_command(0xC5); } if(key1==3) { lcd_command(0xCA); } if(key==2) lcd_data(ascii3); if(flag==1) lcd_data(ascii2); lcd_data(ascii1); if(key1==3) { key1=0; ascii3=0; ascii2=0; ascii1=0; delay(10); } } void adc() //Function to drive ADC { while(1) { if(temp1==0) { ADD_C=0; // Selecting input channel 1 using address lines ADD_B=0; ADD_A=0; } if(temp1==1) { ADD_C=0; // Selecting input channel 2 using address lines ADD_B=0; ADD_A=1; } if(temp1==2) { ADD_C=0; // Selecting input channel 3 using address lines ADD_B=1; ADD_A=0; } delay(2); ale=1; delay(2); sc=1; delay(1); ale=0; delay(1); sc=0; while(eoc==1); while(eoc==0); oe=1; BCD(); delay(2); oe=0; temp1++; if(temp1==3) temp1=0; } } void main() { eoc=1; ale=0; oe=0; sc=0; TMOD=0x02; //Timer0 setting for generating clock of 500KHz using interrupt enable mode. TH0=0xFD; IE=0x82; TR0=1; temp1=0; key1=0; lcd_ini(); lcd_dataa("SN1:"); lcd_dataa(" SN2:"); lcd_dataa(" SN3:"); adc(); }###
Circuit Diagrams
Project Components
Project Video
Filed Under: 8051 Microcontroller
Filed Under: 8051 Microcontroller
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.