Microcontroller › 8051 › Interfacing of three sensors with 8051 together. › The input which is to be
March 5, 2013 at 4:07 pm
#9248
preethi
Participant
The 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 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
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_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 seperatly
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 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=)
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 statement
adc( );
}