سلام دوستان

اگه میشه راهنماییم کنید چطوری تو یه برنامه از دو تا کانال بخونم.

البته از روی فیلم آموزشی یه کد نوشتم که از دو تا ADC بخونم و روی LCD نشون بدم و باقی کارا، تا جایی که شد خیلی دست تو کدای اصلی نبردم که خرابکاری نکنم، اما وقتی کد رو به این صورت مینویسم که یه تابع ADC_Read تعریف میکنم با آرگومان Channel و یه بار 6 قرارش میدم و یه بار 7، اول با آرگومان 6 میخونه و سر خط فراخونی تابع با آرگومان 7 میمونه.
ینی دستورات تا این خط اجرا میشه current_value = ADC_Read(7); و دیگه اجرا نمیشه.


کد:
unsigned short ADC_Read(unsigned char channel)
{
 unsigned int i;
 //-----------------------------
 if (channel == 6)
      LPC_PINCON->PINSEL0 |= 2 << 6;  /* p0.3 select as ADC0.6 */
 else if (channel == 7)
      LPC_PINCON->PINSEL0 |= 2 << 4;  /* p0.2 select as ADC0.7 */ 
 
 LPC_SC->PCONP |= (1 << 12); // Enable power to AD block 
 LPC_ADC->ADCR |= 1<<channel; //select AD0.4 TO AD0.5 depend adc channel nomber
 LPC_ADC->ADCR |= 0x0100;   //    ADCLK is 12.5 MHz
 //LPC_ADC->ADCR |= 0x10000;  // BURST bit  1 << 16
 LPC_ADC->ADCR |= 0x200000;  //Power up,  1 << 21
 //LPC_ADC->ADCR |= 0x08000000; //Start conversion on a falling edge on the selected CAP/MAT signal.
                    // 1 << 27
 //-----------------------------
 LPC_ADC->ADCR |= 0x01000000; // Start A/D Conversion
 do
 {
  switch (channel)
 {
  case 6:
    i = LPC_ADC->ADDR6; // Read A/D Data Register
  break;
  case 7:
    i = LPC_ADC->ADDR7; // Read A/D Data Register
  break;
 }
 }
 while ((i & 0x80000000) == 0); // Wait for end of A/D Conversion
 return (i >> 4) & 0x0FFF; // bit 4:15 is 10 bit AD value
}
 
 
int main (void) {
 
       unsigned short current_value;
       unsigned int l = 0;
       unsigned int r = 0;
       unsigned int m = 0;
       char h[100];
       char p[100];
  unsigned int n;
      LPC_GPIO0->FIODIR = ((1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)|(1<<10));
      LPC_GPIO0->FIOMASK = 0;
      LPC_GPIO0->FIOCLR = ((1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)|(1<<10));
      
      //LCD_4 BIT MODE
      lcd_init_4bit();
      SystemInit();
      command(0x01);
lcd_putsf(" NavaBehdasht 2 ");
  Delay(10000);
      command(0x01);
      command(0x0c);
 
while(1){
l=0;          
 
for(n=0;n<=10;n++)
{
Delay(1000);
current_value = ADC_Read(6);
 
 
l=l+current_value;
}            
l=l/10;
sprintf(h,"%i",l);
command(0x80);
lcd_putsf("L:   ");
command(0x82);            
lcd_putsf(h);
delay(11000);
 
 
r=0;
 
for(n=0;n<=10;n++)
{
Delay(1000);
current_value = ADC_Read(7);
 
 
r=r+current_value;
}            
r=r/10;
sprintf(p,"%d",r);
  
            
command(0x88);
lcd_putsf(" R:   ");
command(0x8b);            
lcd_putsf(p);
delay(11000);
 
m=l-r;
sprintf(p,"%i",m);
  
            
command(0xc0);
lcd_putsf("  Diff:   ");
command(0xc8);            
lcd_putsf(p);
delay(11000);
}
}
وقتیم به این صورت مینویسم و دو تا تابع تعریف میکنم یعنی یه تابع ADC_Read و یه تابع ADC_Read1 و هر کدومو جدا فراخونی میکنم هر دو رو میخونه ولی فقط یه بار، و حلقه بسته ای که گذاشتم که مرتب ADCها رو بخونم و بعد هر بار خوندن تو LCD نشون بدم این حلقه دیگه تکرار نمیشه.

کد:
unsigned short ADC_Read(unsigned char channel)
{
 unsigned int i;
 //-----------------------------
 if (channel == 6)
      LPC_PINCON->PINSEL0 |= 2 << 6;  /* p0.3 select as ADC0.6 */
 else if (channel == 7)
      LPC_PINCON->PINSEL0 |= 2 << 4;  /* p0.2 select as ADC0.7 */ 
 
 LPC_SC->PCONP |= (1 << 12); // Enable power to AD block 
 LPC_ADC->ADCR |= 1<<channel; //select AD0.4 TO AD0.5 depend adc channel nomber
 LPC_ADC->ADCR |= 0x0100;   //    ADCLK is 12.5 MHz
 //LPC_ADC->ADCR |= 0x10000;  // BURST bit  1 << 16
 LPC_ADC->ADCR |= 0x200000;  //Power up,  1 << 21
 //LPC_ADC->ADCR |= 0x08000000; //Start conversion on a falling edge on the selected CAP/MAT signal.
                    // 1 << 27
 //-----------------------------
 LPC_ADC->ADCR |= 0x01000000; // Start A/D Conversion
 do
 {
  switch (channel)
 {
  case 6:
    i = LPC_ADC->ADDR6; // Read A/D Data Register
  break;
  case 7:
    i = LPC_ADC->ADDR7; // Read A/D Data Register
  break;
 }
 }
 while ((i & 0x80000000) == 0); // Wait for end of A/D Conversion
 return (i >> 4) & 0x0FFF; // bit 4:15 is 10 bit AD value
}
 
unsigned short ADC_Read1(unsigned char channel)
{
 unsigned int i;
 //-----------------------------
 LPC_PINCON->PINSEL3 = 3 << 28;  /* p1.30 select as ADC0.4 */
 LPC_PINCON->PINSEL3 <<= ((channel-4)*2); //select AD0.4 & AD0.5 pin depend channel nomber
      
 LPC_SC->PCONP |= (1 << 12); // Enable power to AD block 
 LPC_ADC->ADCR |= 1<<channel; //select AD0.4 TO AD0.5 depend adc channel nomber
 LPC_ADC->ADCR |= 0x0100;   //    ADCLK is 12.5 MHz
 //LPC_ADC->ADCR |= 0x10000;  // BURST bit  1 << 16
 LPC_ADC->ADCR |= 0x200000;  //Power up,  1 << 21
 //LPC_ADC->ADCR |= 0x08000000; //Start conversion on a falling edge on the selected CAP/MAT signal.
                    // 1 << 27
 //-----------------------------
 LPC_ADC->ADCR |= 0x01000000; // Start A/D Conversion
 do
 {
  switch (channel)
 {
  case 4:
    i = LPC_ADC->ADDR4; // Read A/D Data Register
  break;
  case 5:
    i = LPC_ADC->ADDR5; // Read A/D Data Register
  break;
 }
 }
 while ((i & 0x80000000) == 0); // Wait for end of A/D Conversion
 return (i >> 4) & 0x0FFF; // bit 4:15 is 10 bit AD value
}
 
 
int main (void) {
 
       unsigned short current_value;
       unsigned int l = 0;
       unsigned int r = 0;
       unsigned int m = 0;
       char h[100];
       char p[100];
  unsigned int n;
      LPC_GPIO0->FIODIR = ((1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)|(1<<10));
      LPC_GPIO0->FIOMASK = 0;
      LPC_GPIO0->FIOCLR = ((1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)|(1<<10));
      
      //LCD_4 BIT MODE
      lcd_init_4bit();
      SystemInit();
      command(0x01);
lcd_putsf(" NavaBehdasht 2 ");
  Delay(10000);
      command(0x01);
      command(0x0c);
 
while(1){
l=0;          
 
for(n=0;n<=10;n++)
{
Delay(1000);
current_value = ADC_Read(6);
 
 
l=l+current_value;
}            
l=l/10;
sprintf(h,"%i",l);
command(0x80);
lcd_putsf("L:   ");
command(0x82);            
lcd_putsf(h);
delay(11000);
 
 
r=0;
 
for(n=0;n<=10;n++)
{
Delay(1000);
current_value = ADC_Read1(4);
 
 
r=r+current_value;
}            
r=r/10;
sprintf(p,"%d",r);
  
            
command(0x88);
lcd_putsf(" R:   ");
command(0x8b);            
lcd_putsf(p);
delay(11000);
 
m=l-r;
sprintf(p,"%i",m);
  
            
command(0xc0);
lcd_putsf("  Diff:   ");
command(0xc8);            
lcd_putsf(p);
delay(11000);
}
}

البته برنامه نه ارور میده و نه وارنینگ.