Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

Project Request

Return
karthik selvaraj
karthiks012

posted on 2014/04/16 05:52:19 PM CEST

Measurement

How to Read 5 adc ports simultaneously in pic 16f877a

In my program I can able to read 3 adc ports simultaneously

but when i read 5 ports simultaneously it does not reads it freezes.in proteous simulation
my code is below............ please help i need it to read 5 ports simultaneously ...

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

char look(int a)
{
switch(a)
{
case 0:
return '0';
case 1:
return '1';
case 2:
return '2';
case 3:
return '3';
case 4:
return '4';
case 5:
return '5';
case 6:
return '6';
case 7:
return '7';
case 8:
return '8';
case 9:
return '9';
default:
return '.';
}
}
unsigned long int vr,vy,vb;
unsigned long int cr,cy;
//unsigned long int j;
char voltr[] = "000";
char volty[] = "000";
char voltb[] = "000";
char curtr[] = "00";
char curty[] = "00";
void get()
{

vr=adc_read(0);
vy=adc_read(1);
vb=adc_read(2);
cr=adc_read(6);
cy=adc_read(7);
}
// End LCD module connections
void calculate_curr()
{
cr=((cr*4.89)*12);
curtr[0] = look(cr/10000);
curtr[1] = look((cr/1000)%10);
}
void calculate_cury()
{
cy=((cy*4.89)*12);
curty[0] = look(cy/10000);
curty[1] = look((cy/1000)%10);
}
void cal_voltr()
{
vr=((vr*4.89)/20)*2020;
voltr[0] = look((vr/100000));
voltr[1] = look((vr/10000)%10);
voltr[2] = look((vr/1000)%10);
}
void cal_volty()
{
vy=((vy*4.89)/20)*2020;
volty[0] = look((vy/100000));
volty[1] = look((vy/10000)%10);
volty[2] = look((vy/1000)%10);
}
void cal_voltb()
{
vb=((vb*4.89)/20)*2020;
voltb[0] = look((vb/100000));
voltb[1] = look((vb/10000)%10);
voltb[2] = look((vb/1000)%10);
}
void dis_volt1()
{
//Lcd_Out_Cp("THREE PHASE VOLT");
Lcd_Out(1,1,"R");
Lcd_Out(1,2,voltr);
}
void dis_volt2()
{
Lcd_Out(1,7,"Y");
Lcd_Out(1,8,volty);
}
void dis_volt3()
{
Lcd_Out(1,13,"B");
Lcd_Out(1,14,voltb);
}
void dis_cur1()
{
//Lcd_Out(1,1,"CURRENT APMS");
Lcd_Out(2,1,"CR=");
Lcd_Out(2,5,curtr);
}
void dis_cur2()
{
Lcd_Out(2,8,"CY=");
Lcd_Out(2,11,curty);
}

void main()
{
TRISA = 0xFF; // ' set PORTA as input
TRISE = 0x07; // ' set RE0 (AN5), RE0 (AN6) and RE2(AN7) as input //' Turn off comparators
TRISD.f0=0xFF;
TRISD.f1=0xFF;
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
while(1)
{
get();
cal_voltr();
dis_volt1();
cal_volty();
dis_volt2();
cal_voltb();
dis_volt3();
//calculate_curr();
//dis_cur1();
//calculate_cury();
//dis_cur2();
}
}