whmeade10 Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				| Returning a value from a function outside main program. | 
			 
			
				 Posted: Fri Apr 25, 2003 9:17 pm     | 
				     | 
			 
			
				
  | 
			 
			
				<html>
 
<body>
 
<pre>
 
 
I am trying to return a value in a function located in a driver
 
file to the calling function in the main program.  what I have below
 
should work but doesn't.  The driver file is included at the top of
 
the main program file.  When I compile the main program I get the
 
following error    'Undefined identifier value' and the word value
 
is highlighted in the 'value = read_adc_value(); line below.
 
 
 
 
Loop in main file
 
-----------------
 
 
do {                                                  
 
      value = read_adc_value();             // Goto read ADC value sub-routine
 
      lcd_gotoxy(7,1);                      // goto position 7 on line 1
 
      printf(lcd_putc,"\%lu ",value);        // display raw ADC value on line 1
 
      Delay_ms(500);                        // Delay 1/2 second
 
   }  While (TRUE);                                 
 
 
 
Function in driver file
 
-----------------------
 
 
// READ CS5516 ADC VALUE
 
int16 read_adc_value() {
 
   int16 value;                             // define value variable
 
   byte i;                                  // define counter variable
 
 
   While (!input(ADC_DI));                  // WAIT FOR ADC_DI TO GO HIGH
 
   while (input(ADC_DI));                   // WAIT FOR ADC_DI TO GO LOW
 
 
   for(i=1;i<=8;++i) {                      // repeat 8 times
 
      output_high(ADC_CLK);                 // set adc clock pin high
 
      output_low(ADC_CLK);                  // set adc clock pin low
 
   }
 
   for(i=1;i<=16;++i) {                     // repeat 16 times
 
      shift_left(&value,2,input(ADC_DI));   // shift bit into value
 
      output_high(ADC_CLK);                 // set adc clock pin high
 
      output_low(ADC_CLK);                  // set adc clock pin low
 
   }
 
   for(i=1;i<=8;++i) {                      // repeat 8 times
 
      output_high(ADC_CLK);                 // set adc clock pin high
 
      output_low(ADC_CLK);                  // set adc clock pin low
 
   }
 
   
 
   return value;
 
}
 
 
 
 
 |    |