Qaisar Azeemi
Member
hi friends,
i am getting 3 analog signals at the inputs of ADC0808 and i am displaying it on LCD. they are voltage current and temperature signals. the problem is that when i vary one of the analog input it also effects the data from other inputs. that is if i vary voltage it resutls in the variation of voltage data, current data and temprature data on tha Screen of LCD. i tried my best to isolate it from each other by putting delays and clearing the arrays and data memory locations but the problem is as it is... please help me to rectify my problem...
following is my code:
and here is my circuit diagram..
View attachment 62590
thanking you in anticipation.
regards
Qaisar azeemi.
i am getting 3 analog signals at the inputs of ADC0808 and i am displaying it on LCD. they are voltage current and temperature signals. the problem is that when i vary one of the analog input it also effects the data from other inputs. that is if i vary voltage it resutls in the variation of voltage data, current data and temprature data on tha Screen of LCD. i tried my best to isolate it from each other by putting delays and clearing the arrays and data memory locations but the problem is as it is... please help me to rectify my problem...
following is my code:
Code:
#include <reg52.h>
#define select P3
#define Port P2 // control port
#define adc_input P1
#define data_port P0 // data from microcontroller to LCD
#define sec 50
#define scan 10
sbit ADC_A=Port^0; //ADC
sbit ADC_B=Port^1; //ADC
sbit RS=Port^7; //LCD
sbit E=Port^5; //LCD
sbit ctl=Port^6; //LCD
sbit SC=Port^4; //ADC
sbit CLK=Port^3; //ADC
sbit ALE=Port^2; //ADC
sbit v28=select^4; // carger 28v selected
sbit v14=select^5;
sbit v7=select^6;
sbit off=select^7;
sbit intr=select^2;
sbit c28=select^0;
sbit c14=select^1;
sbit c7=select^3;
unsigned int test_intermediate3=0, test_final=0, select_mem=0, x=0;
unsigned int test_intermediate1[scan], test_intermediate2[3]={0,0,0};
unsigned char temp[]={"Temp: "}, vna[]={" Volt: Amp: "}, hnm[]={" hr min %"}, bnc[]={"Backup: %Charge"};
//------------------- . --------------------------
void delay(unsigned int msec)
{
int i,j;
for(i=0; i==msec; i++)
for(j=0; j==1275; j++);
}
//...........;;;;;;;;;;..........................
void long_delay(unsigned int second)
{
int i,j;
for (j=0; j<second ; j++)
for (i=0; i<0xffff; i++);
}
//---------------- timer 0 interrupt----------------
void timer0() interrupt 1
{
CLK=~CLK; // Toggle port bit p3.5
TR0=0; // stop timer
TH0=0xff; // 500hz clock for adc
TL0=0xff;
TR0=1; // start timer
}
//;;;;;;;;;;;;;;;;;;;;;;;;;;;
void switch2(void)
{
if (v7==1 & v14==0 & v28==0)
{
c7=1; c14=0; c28=0;
}
else
if(v14==1 & v7==0 & v28==0)
{
c14=1; c7=0; c28=0;
}
else
if (v28==1 & v7==0 & v14==0)
{
c28=1; c14=0; c7=0;
}
}
//---------------- External 0 interrupt----------------
void switching() interrupt 0
{
intr=1;
delay(sec*4);
select = select_mem;
intr=1;
delay(sec*4);
// ...............---------........................
if(v28==0 & v14==0 & v7==0 & off==1)
{ off=0; v7=1; v28=0; v14=0; }
else
if(v28==0 & v14==0 & v7==1 & off==0) //e1
{ v7=0; v14=1; v28=0; off=0; }
else
if(v28==0 & v14==1 & v7==0 & off==0) //e2
{ v14=0; v28=1; v7=0; off=0; }
else
if(v28==1 & v14==0 & v7==0 & off==0) //e3
{ v28=0; v14=0; v7=0; off=1; }
delay(sec*4);
intr=1;
c7=0; c14=0; c28=0;
delay(sec*4);
select_mem = select;
long_delay(10);
switch2();
}
//.................. LCD .................
void lcd_cmd( unsigned int item )
{
data_port=item; //command on data port p0 of lcd
RS=0; // selecting command register of lcd
// RW=0;
E=1;
delay(1);
E=0;
}
void lcd_data( unsigned int item )
{
data_port=item; //data on data port p0 of lcd
RS=1; // selecting data register of lcd
// RW=0;
E=1;
delay(1);
E=0;
}
//----------- custom character Generation for Degree symbol-----------
void shape()
{
lcd_cmd(64); // first location in CGRAM
delay(sec);
lcd_data(2);
delay(sec);
lcd_data(5);
delay(sec);
lcd_data(2);
delay(sec);
lcd_data(0);
delay(sec);
lcd_data(0);
delay(sec);
lcd_data(0);
delay(sec);
lcd_data(0);
delay(sec);
lcd_data(0);
delay(sec);
}
//-------------------- for volt symbol-----------------
void shape2()
{
lcd_cmd(72); // second location in CGRAM
delay(sec);
lcd_data(0);
delay(sec);
lcd_data(0);
delay(sec);
lcd_data(17);
delay(sec);
lcd_data(17);
delay(sec);
lcd_data(17);
delay(sec);
lcd_data(10);
delay(sec);
lcd_data(4);
delay(sec);
lcd_data(0);
delay(sec);
}
//---------------------- for current symbol-------------------
void shape3()
{
lcd_cmd(80); // Third location in CGRAM
delay(sec);
lcd_data(0);
delay(sec);
lcd_data(0);
delay(sec);
lcd_data(4);
delay(sec);
lcd_data(10);
delay(sec);
lcd_data(17);
delay(sec);
lcd_data(31);
delay(sec);
lcd_data(17);
delay(sec);
lcd_data(0);
delay(sec);
}
//..... Converting binary value of ADC to ASCII value of LCD for Temprature........
void convert()
{
int s;
test_final=(((9*test_intermediate3)/5)+32); // Farenhite conversion
s=test_final/100;
test_final=test_final%100;
lcd_cmd(0xc5);
delay(sec);
if (s!=0)
{
lcd_data(s+48); //c5
delay(sec);
}
else
{
lcd_cmd(0x06);
delay(sec);
}
s=test_final/10;
test_final=test_final%10;
lcd_data(s+48); //c6
delay(sec);
lcd_data(test_final+48); //c7
delay(sec);
lcd_data(0); // space for degree symbol
delay(sec);
lcd_data('F');
delay(sec);
lcd_data(' ');
delay(sec);
//------------------- for Celcius scale----------------
test_final=test_intermediate3;
s=test_final/100;
test_final=test_final%100;
lcd_cmd(0xcB);
delay(sec);
if (s!=0)
{
lcd_data(s+48); // 1st digit MS
delay(sec);
}
else
{
lcd_cmd(0x06);
delay(sec);
}
s=test_final/10; // 2nd digit
test_final=test_final%10; // 3rd digit LS
lcd_data(s+48); //89
delay(sec);
lcd_data(test_final+48); //88
delay(sec);
lcd_data(0); // space for degree symbol
delay(sec);
lcd_data('C');
delay(sec);
lcd_data(' ');
delay(sec);
}
// Converting binary value of ADC to ASCII value of LCD for volts
void Convert2()
{
int s;
//.................... Voltage conversion ............................
test_final=test_intermediate3/5;
s=test_final/100;
test_final=test_final%100;
lcd_cmd(0x85);
delay(sec);
if (s!=0)
{
lcd_data(s+48);
delay(sec);
}
else
{
lcd_cmd(0x06);
delay(sec);
}
s=test_final/10;
test_final=test_final%10;
lcd_data(s+48);
delay(sec);
lcd_data(test_final+48);
delay(sec);
lcd_data(1);
delay(sec);
lcd_data(' ');
delay(sec);
}
//-------------------..................-------------------
void Convert3()
{
int s;
//.................... current conversion ............................
test_final=test_intermediate3;
s=test_final/100;
test_final=test_final%100;
lcd_cmd(0x8D);
delay(sec);
if (s!=0)
{
lcd_data(s+48);
delay(sec);
}
else
{
lcd_cmd(0x06);
delay(sec);
}
s=test_final/10;
test_final=test_final%10;
lcd_data(s+48);
delay(sec);
lcd_data(test_final+48);
delay(sec);
lcd_data(2);
delay(sec);
}
//.........--------.......Main Program.......-------........
void main()
{
int i,j,k,l,m,n;
adc_input=0xff; // making p1 as input port
TMOD=0x01; // timer 0, mode 1
TH0=0xff; // 500hz clock for adc
TL0=0xff;
TR0=1; // timer start
IE=0x83; // interrupt enable ; timer interrupt, external interrupt and globle interrupt.
v28=0; v14=0; v7=0; off=1; // intializing charger selection to 0V
c28=0; c14=0; c7=0;
intr=1;
select_mem = select;
delay(sec);
lcd_cmd(0x38); // initializing LCD module
delay(sec);
lcd_cmd(0x0c);
delay(sec);
lcd_cmd(0x01);
delay(sec);
lcd_cmd(0x06);
delay(sec);
//;;;;;;;;;;;;;;-----------;;;;;;;;;;;;;;;
//......... volt and ampere display........
lcd_cmd(0x80);
delay(sec);
for(i=0; vna[i]!='\0'; i++)
{
lcd_data(vna[i]);
delay(sec);
}
//;;;;;;;;;;;;-----------------------;;;;;;;;;;;;;;;;;
//..........- Back up and %Charge display ----........
lcd_cmd(0x90);
delay(sec);
for(i=0; bnc[i]!='\0' ; i++)
{
lcd_data(bnc[i]);
delay(sec);
}
//;;;;;;;;;;;;;;-----------;;;;;;;;;;;;;;;
//......... ----Temp: display-----........
lcd_cmd(0xc0);
delay(sec);
for(i=0; temp[i]!='\0' ; i++)
{
lcd_data(temp[i]);
delay(sec);
}
//;;;;;;;;;;;;;;-------------------------;;;;;;;;;;;;;;;;;
//.............- hour and minute display ------...........
lcd_cmd(0xD0);
delay(sec);
for(i=0; hnm[i]!='\0'; i++)
{
lcd_data(hnm[i]);
delay(sec);
}
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
while(1)
{
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Temprature samples;;;;;;;;;;;;;;;;;;;;;;
test_intermediate3=0;
test_final=0;
test_intermediate2[0]=0;
test_intermediate2[1]=0;
test_intermediate2[2]=0;
for(j=0;j<3;j++)
{
for(i=0;i<scan;i++)
{ ctl=0;
delay(10);
ADC_A=0;
ADC_B=0; // channel 0 is selected ; pin 26 of ADC
delay(200);
ALE=0;
SC=0;
delay(1);
ALE=1;
delay(1);
SC=1;
delay(1);
ALE=0;
delay(1);
SC=0;
delay(200);
test_intermediate1[i]=adc_input/scan;
}
for(i=0;i<scan;i++)
test_intermediate2[j]+=test_intermediate1[i];
}
test_intermediate2[0]=test_intermediate2[0]/3;
test_intermediate2[1]=test_intermediate2[1]/3;
test_intermediate2[2]=test_intermediate2[2]/3;
test_intermediate3=test_intermediate2[0] + test_intermediate2[1] + test_intermediate2[2];
convert();
shape();
long_delay(1);
ctl=1;
delay(10);
ADC_A=1;
ADC_B=0; // channel 1 is selected for voltage
//;;;;;;;;;;;;;;;;; Voltage samples;;;;;;;;;;;;;;;;;;;;;;;;;
test_intermediate3=0;
test_final=0;
test_intermediate2[0]=0;
test_intermediate2[1]=0;
test_intermediate2[2]=0;
for( k=0;k<3;k++)
{
for(l=0;l<scan;l++)
{
delay(10);
ADC_A=1;
ADC_B=0; // channel 1 is selected
delay(200);
ALE=0;
SC=0;
delay(1);
ALE=1;
delay(1);
SC=1;
delay(1);
ALE=0;
delay(1);
SC=0;
delay(200);
test_intermediate1[l]=adc_input/scan;
}
for(i=0;i<scan;i++)
test_intermediate2[k]+=test_intermediate1[i];
}
test_intermediate2[0]=test_intermediate2[0]/3;
test_intermediate2[1]=test_intermediate2[1]/3;
test_intermediate2[2]=test_intermediate2[2]/3;
test_intermediate3=test_intermediate2[0] + test_intermediate2[1] + test_intermediate2[2];
Convert2();
shape2();
long_delay(1);
ADC_A=0;
ADC_B=1; // channel 2 is selected for current
//;;;;;;;;;;;;;;;;; Current samples;;;;;;;;;;;;;;;;;;;;;;;;;
test_intermediate3=0;
test_final=0;
test_intermediate2[0]=0;
test_intermediate2[1]=0;
test_intermediate2[2]=0;
for( m=0;m<3;m++)
{
for( n=0;n<scan;n++)
{
delay(10);
ADC_A=0;
ADC_B=1; // channel 2 is selected
delay(200);
ALE=0;
SC=0;
delay(1);
ALE=1;
delay(1);
SC=1;
delay(1);
ALE=0;
delay(1);
SC=0;
delay(200);
test_intermediate1[n]=adc_input/scan;
}
for(i=0;i<scan;i++)
test_intermediate2[m]+=test_intermediate1[i];
}
test_intermediate2[0]=test_intermediate2[0]/3;
test_intermediate2[1]=test_intermediate2[1]/3;
test_intermediate2[2]=test_intermediate2[2]/3;
test_intermediate3=test_intermediate2[0] + test_intermediate2[1] + test_intermediate2[2];
Convert3();
shape3();
long_delay(1);
}
}
and here is my circuit diagram..
View attachment 62590
thanking you in anticipation.
regards
Qaisar azeemi.