Microcontroller › 8051 › Interfacing of three sensors with 8051 together.
- This topic has 2 replies, 2 voices, and was last updated 10 years, 6 months ago by
Pradip Saikia.
-
AuthorPosts
-
March 5, 2013 at 11:50 am #2161
Pradip Saikia
ParticipantHi all I want to interface a temp sensor (LM35) , a Light sensor (LDR) & a Humidity sensor together to a 8051 MC (p89v21rd2) using adc0808. Plz help me how can I write the program in c. Plz help me…
March 5, 2013 at 4:07 pm #9248preethi
ParticipantThe input which is to be converted to digital form can be selected by using three address lines using three address lines. So, that you can connect three sensors at a time..
the code is as follows… but you have to write the logics of 3 sensors which you are using….i have left space for that ..and also once check the ports that you are using for adc, lcd connection as per your circuit diagram..i have declared roughly..
#include<reg51.h>sbit ale=P1^0; // Address latch enablesbit oe=P1^3; // Output enablesbit sc=P1^1; // Start conversionsbit eoc=P1^2; // End of conversionsbit clk=P1^7; // Clocksbit 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 P2sbit rs=P3^0;sbit rw=P3^1;sbit en=P3^6;sfr input_port=0x80; //Port P0void 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_data(unsigned char *disp) //Function to send string data to LCD.{int x;for(x=0;disp[x]!=0;x++){lcd_data(disp[x]);}}here you declare the function of your 3 sensors logic seperatlyvoid lcd_ini() //Function to inisialize the LCD{lcd_command(0x38); // for using 8-bit 2 row LCDdelay(5);lcd_command(0x0F); // for display on cursor blinkingdelay(5);lcd_command(0x80);delay(5); //Force cursor to blink at line 1 positon 0}void adc( ) //Function to drive ADC{while(1){if(temp1==0){ADD_C=0; // Selecting input channel 1 using address linesADD_B=0;ADD_A=0;}if(temp1==1){ADD_C=0; // Selecting input channel 2 using address linesADD_B=0;ADD_A=1;}if(temp1==2){ADD_C=0; // Selecting input channel 3 using address linesADD_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=)
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();here you add your desired sensor call statementadc( );}March 8, 2013 at 7:22 pm #9282Pradip Saikia
ParticipantPlz complete this prog for LM35(temp sensor), LDR (light sensor) and HR201(humidity sensor). thanks
-
AuthorPosts
- You must be logged in to reply to this topic.