Basic blocks of a "Data Acquistion System"
- This is a simple system that convert two physical quantities (Temperate & light intensity) into Digital quantities.
- For temp i used LM35 sensor which convert the physical signal into voltage(in mV).
- To make it compatible with micro controller (PIC18f452) , i used op amp 741 to boost the voltage from 10mV to 5V , this is nothing but "Signal Conditioning".
- same with light,where i used LDR as sensor.
CODE
- #include<p18f452.h>
//FOR WATCHDOG TIMER
#pragma config WDT=OFF
#pragma config OSC=HS,OSCS=OFF
#pragma config BORV=45,PWRT=ON,BOR=ON
#define rs PORTCbits.RC5
#define rw PORTCbits.RC6
#define en PORTCbits.RC7
#define sdata PORTD
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void adc_con(int);
void adc_con1(int);
void adc_init(void);
void Print_string(char *A);
void Delay_ms(int);
char data[6]="TEMP";
char data1[3]="|";
char data2[6]="LUX";
float TEMPRATURE[10],avg_output=0,temp;
float LDR[10],avg_output1=0,temp1;
unsigned int i=0;
void main(void)
{
TRISA=0x0f; // Configure RA0 as input pin
TRISB=0; // Configure Port B as output port
TRISC=0;
TRISD=0;
lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
lcdcmd(0x0C); // Display On and Cursor Off
lcdcmd(0x01); // Clear display screen
lcdcmd(0x06); // Increment cursor
lcdcmd(0x80); // Set cursor position to 1st line, 1st column
Print_string(data);
lcdcmd(0x87);
Print_string(data1);
lcdcmd(0xC7);
Print_string(data1);
lcdcmd(0x8C);
Print_string(data2);
adc_init(); //ADC Initialization
while(1)
{
ADCON0=0x81;
temp=0;
for(i=0;i<10;i++)
{
ADCON0bits.GO=1; // Start A/D
while(ADCON0bits.DONE==1); // Wait
TEMPRATURE[i]=ADRES ; //Store data
Delay_ms(5);
temp=temp+TEMPRATURE[i];
}
avg_output=temp/10;
avg_output=(avg_output/1024)*150; // Take average
adc_con(avg_output); // decimal to ASCII
ADRES=0;
ADCON0=0x89;
temp1=0;
for(i=0;i<10;i++)
{
ADCON0bits.GO=1; // Start A/D
while(ADCON0bits.DONE==1); // Wait
LDR[i]=ADRES ; //Store data
Delay_ms(5);
temp1=temp1+LDR[i];
}
avg_output1=temp1/10;
avg_output1=(1024-avg_output1); // Take average
adc_con1(avg_output1); // decimal to ASCII
}
}
void Print_string(char *a)
{
int i;
for(i=0;(*(a+i))!='\0';i++)
{
lcddata(*(a+i));
}
}
void adc_init()
{
ADCON1=0xC5; // Make RA0/AN0 ,RA1,RA2 ANALOG
// Select Channel0 & ADC off
// ADCON2=0x85; // Fosc/32 clock option
ADCON0=0x81; // Enable ADC
}
void adc_con( int adc_out)
{
int adc_out1;
int i=0;
char position=0xC3;
for(i=0;i<=3;i++)
{
adc_out1=adc_out%10; // To exract the unit position digit
adc_out=adc_out/10;
lcdcmd(position);
lcddata(48+adc_out1); // Convert into its corresponding ASCII
position--;
}
}
void adc_con1( int adc)
{
int adc_out2;
int i=0;
char position=0xCF;
for(i=0;i<=3;i++)
{
adc_out2=adc%10; // To exract the unit position digit
adc=adc/10;
lcdcmd(position);
lcddata(48+adc_out2); // Convert into its corresponding ASCII
position--;
}
}
void lcdcmd(unsigned char cmdout)
{
sdata=cmdout; //Send command to lcdport=PORTB
rs=0;
rw=0;
en=1;
Delay_ms(20);
en=0;
}
void lcddata(unsigned char dataout)
{
sdata=dataout; //Send data to lcdport=PORTB
rs=1;
rw=0;
en=1;
Delay_ms(30);
en=0;
}
void Delay_ms(int d)
{
int i,j;
for(i=0;i<d;i++)
{
for(j=0;j<d;j++)
{
}
}
}
4 Comments:
Dude is it working ?
yup...recently i implemented this in hardware its working fine.
i have trouble regarding the conversion of 10 bit data into 8 bit ...can plzz help me out?
use c18 compilier n just use the line "data=ADRES" into your program.
Post a Comment