Hi.I write a program in C for my microcontroller(PIC 18F452) but
faced to a problem that related only to C language and that is;
as you can see in my Main program and the two Functions I want to
pass an array of ; " int adcvalmax[8] " which got valued in the Function;
" int CHS_Read(int adcvalmax[8]) ", between " Main " program and
Function; void Display_AdcX(int adcvalmax[8] ) for processing.
But I do not know if my "Main & Functions" are right or not?

Here are the descriptions of my Functions and Main program;

1.int CHS_Read(int adcvalmax[8]); Reading input values by analog to digital module of the PIC18F452 and save the results in the array
" adcvalmax[m] ".

2.void Display_AdcX(int adcvalmax[8] ) ;get the array
" adcvalmax[m] "and by using it display its value on LCD.

3.In the Main program I call Function; " void Display_AdcX(int adcvalmax[8] ) " as; Display_AdcX( adcvalmax[] ); .

Would you please help me and tell me if my program and functions are right or not?And what is/are wrong in my program?

Thanks,

unsigned char ch0=0,ch1=0;
int t0=0,t1=0;
char *tc;
int adcvalmax[8]=0;

#define stepsize  98
int  interb0=0;


void Display_AdcX(int adcvalmax[8] ) {
   int i=0,m=0;
   char ch[i]=0;
   adcvalmax[8]=0;
   
  for(i,m=0;i,m<8;i++,m++){ //IS THIS FOR STATEMENT RIGHT? ****************
  
  ch[i]  = adcvalmax[m] /1000;
  Lcd_Chr(2, 1, 48 + ch[i]); //write ASCII at 2nd row,1st column
  Lcd_Chr_Cp('.');

  ch[i]  = ( adcvalmax[m] /100) % 10;
  Lcd_Chr_Cp(48 + ch[i]);

  ch[i]  = ( adcvalmax[m] /10) % 10;
  Lcd_Chr_Cp(48 + ch[i]);

  ch[i]  = adcvalmax[m] % 10;
  Lcd_Chr_Cp(48 + ch[i]);
  Lcd_Chr_Cp('A');

  }

}//~


int CHS_Read(int adcvalmax[8]){

 long longadc=0;
 adcvalmax[8]=0;
 int ch[8];//declares a array of 8 integers
 int m=0,i=0;
 int Px=0,P1st=0,P2nd=0;

 
  for(i=0;i<8;i++){
  
     for(m=0;m<8;m++){
     
       do{
          ch[i]=ADC_Read(i);
          Px=ch[i];
         }while(Px!=0)
         
      P1st=ADC_Read(m);
      Delay_ms(10);//10 ms pause
      P2nd=ADC_Read(m);
      
       while(P1st<=P2nd){
            P1st=P2nd;
            P2nd=0;
         P2nd=ADC_Read(m);
       }
                    
   adcvalmax[m] = P1st;// if (vf>vn)
   index = (stepsize);
   ADRESH = (ADRESH)&&(0b00000011);
   longadc = ADRESH + ADRESL;
   adcvalmax[m] = longadc * index;//in mA or mv
         
     }
  }
  
 return[adcvalmax[]];
 
}//~



void main() {

  Display_AdcX( adcvalmax[] )

  Delay_ms(2000);

  }//~!
unsigned char ch0=0,ch1=0;
int t0=0,t1=0;
char *tc;
int adcvalmax[8]=0;

#define stepsize  98
int  interb0=0;


void Display_AdcX(int adcvalmax[8] ) {
   int i=0,m=0;
   char ch[i]=0;
   adcvalmax[8]=0;
   
  for(i,m=0;i,m<8;i++,m++){ //IS THIS FOR STATEMENT RIGHT? ****************
  
  ch[i]  = adcvalmax[m] /1000;
  Lcd_Chr(2, 1, 48 + ch[i]); //write ASCII at 2nd row,1st column
  Lcd_Chr_Cp('.');

  ch[i]  = ( adcvalmax[m] /100) % 10;
  Lcd_Chr_Cp(48 + ch[i]);

  ch[i]  = ( adcvalmax[m] /10) % 10;
  Lcd_Chr_Cp(48 + ch[i]);

  ch[i]  = adcvalmax[m] % 10;
  Lcd_Chr_Cp(48 + ch[i]);
  Lcd_Chr_Cp('A');

  }

}//~


int CHS_Read(int adcvalmax[8]){

 long longadc=0;
 adcvalmax[8]=0;
 int ch[8];//declares a array of 8 integers
 int m=0,i=0;
 int Px=0,P1st=0,P2nd=0;

 
  for(i=0;i<8;i++){
  
     for(m=0;m<8;m++){
     
       do{
          ch[i]=ADC_Read(i);
          Px=ch[i];
         }while(Px!=0)
         
      P1st=ADC_Read(m);
      Delay_ms(10);//10 ms pause
      P2nd=ADC_Read(m);
      
       while(P1st<=P2nd){
            P1st=P2nd;
            P2nd=0;
         P2nd=ADC_Read(m);
       }
                    
   adcvalmax[m] = P1st;// if (vf>vn)
   index = (stepsize);
   ADRESH = (ADRESH)&&(0b00000011);
   longadc = ADRESH + ADRESL;
   adcvalmax[m] = longadc * index;//in mA or mv
         
     }
  }
  
 return[adcvalmax[]];
 
}//~



void main() {

  Display_AdcX( adcvalmax[] )

  Delay_ms(2000);

  }//~!

Dude there are many mistakes in your program

Hi.I write a program in C for my microcontroller(PIC 18F452) but
faced to a problem that related only to C language and that is;
as you can see in my Main program and the two Functions I want to
pass an array of ; " int adcvalmax[8] " which got valued in the Function;
" int CHS_Read(int adcvalmax[8]) ", between " Main " program and
Function; void Display_AdcX(int adcvalmax[8] ) for processing.
But I do not know if my "Main & Functions" are right or not?

Here are the descriptions of my Functions and Main program;

1.int CHS_Read(int adcvalmax[8]); Reading input values by analog to digital module of the PIC18F452 and save the results in the array
" adcvalmax[m] ".

2.void Display_AdcX(int adcvalmax[8] ) ;get the array
" adcvalmax[m] "and by using it display its value on LCD.

3.In the Main program I call Function; " void Display_AdcX(int adcvalmax[8] ) " as; Display_AdcX( adcvalmax[] ); .

Would you please help me and tell me if my program and functions are right or not?And what is/are wrong in my program?

Thanks,

unsigned char ch0=0,ch1=0;
int t0=0,t1=0;
char *tc;
// This is not allowed. I guess what you want to do is declare an array of 8 and initialize all the elements to 0. You want some thing of this sort int arr[8]={0,0,0,0,0,0,0,0};
int adcvalmax[8]=0;

#define stepsize  98
int  interb0=0;


void Display_AdcX(int adcvalmax[8] ) {
   int i=0,m=0;

// This statement means char ch[0]=0. I dont think this what you wanted as well 
   char ch[i]=0;
// Quick note you have 2 arrays by the same name now. In the function the local array( the one which is an argument to the function will get preference. The size of the array is 8 means the indexes which are valid are 0-7 and not 8
   adcvalmax[8]=0;
   

  for(i,m=0;i,m<8;i++,m++){ //IS THIS FOR STATEMENT RIGHT? ****************
  
  ch[i]  = adcvalmax[m] /1000;
  Lcd_Chr(2, 1, 48 + ch[i]); //write ASCII at 2nd row,1st column
  Lcd_Chr_Cp('.');

  ch[i]  = ( adcvalmax[m] /100) % 10;
  Lcd_Chr_Cp(48 + ch[i]);

  ch[i]  = ( adcvalmax[m] /10) % 10;
  Lcd_Chr_Cp(48 + ch[i]);

  ch[i]  = adcvalmax[m] % 10;
  Lcd_Chr_Cp(48 + ch[i]);


  Lcd_Chr_Cp('A');

  }

}//~


int CHS_Read(int adcvalmax[8]){

 long longadc=0;
 adcvalmax[8]=0;
 int ch[8];//declares a array of 8 integers
 int m=0,i=0;
 int Px=0,P1st=0,P2nd=0;

 
  for(i=0;i<8;i++){
  
     for(m=0;m<8;m++){
     
       do{
          ch[i]=ADC_Read(i);
          Px=ch[i];
         }while(Px!=0)
         
      P1st=ADC_Read(m);
      Delay_ms(10);//10 ms pause
      P2nd=ADC_Read(m);
      
       while(P1st<=P2nd){
            P1st=P2nd;
            P2nd=0;
         P2nd=ADC_Read(m);
       }
                    
   adcvalmax[m] = P1st;// if (vf>vn)
   index = (stepsize);
   ADRESH = (ADRESH)&&(0b00000011);
   longadc = ADRESH + ADRESL;
   adcvalmax[m] = longadc * index;//in mA or mv
         
     }
  }
  
 return[adcvalmax[]];
 
}//~


// Make it int main. Also let return 0 be the last statement in the main function
void main() {

// this call is wong. Its should be Display_AdcX( adcvalmax)
  Display_AdcX( adcvalmax[] )

  Delay_ms(2000);

  }
commented: Such a helpful post. I was wondering why he asked for help! -2

Hi.Thanks a lot from abhimanipal.

Hi.Thanks a lot from abhimanipal.

instead of

Display_AdcX( adcvalmax[] )

use

Display_AdcX( adcvalmax )

this does not work

#
for(i,m=0;i,m<8;i++,m++){ //IS THIS FOR STATEMENT RIGHT? ****************

there are other error

your way of commenting is not correct.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.