CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

No return from function, why?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
eabir



Joined: 16 Aug 2010
Posts: 19

View user's profile Send private message

No return from function, why?
PostPosted: Wed Nov 16, 2011 10:01 am     Reply with quote

Hi,

Why do the Visual_on () function is endless and dont return to main after finish the 'for' loop ?

Code:

#include <10F222.h>
#device adc=8

#FUSES NOWDT                      //No Watch Dog Timer
#FUSES NOMCLR                     //Master Clear pin: disable
#FUSES NOPROTECT                  //Code protected from reads
#FUSES NOMCPU                      //No Watch Dog Timer
#FUSES IOSC4
#use delay(Clock=4MHZ,OSC)
 //      #use delay(clock=40)         // Only for Debug Mode
 //     #use delay(clock=1000000)         // Only for Debug Mode
#bit OSCCAL_0 = 0x05.0           // Disable OSC on GP2, Enable as I/O

//==============================//
// Configuration bits:
//   1.MCPU = Pull up disabled
//  2.WDT = disabled
//  3.MCLRE = I/O & tied to VDD
//========================================================================


  Sound_on (void)
   {

      int8 step = 0;
            
      for(step = 0;step < 1 ;step++ ){  // 
        //   cnt0 = 0;
         
          output_low(PIN_B1); // Play sound
        }
 }
 
  Visual_on (void)
   {
      int16 step = 0;   
      for(step = 0;step < 1 ;step++ ){  //  Loop control
           output_low(PIN_B2); // Sound sequence       
           delay_ms(100); //6Khz     was 73??     
     
          }
      return:
      }
     
 void main()
{
 
   int8 step;
   int8 temp_val;
   int8 val_ref_lo = 0;
   int8 val_ref_hi = 0;
   int8 Val = 0;
   int8 avalue;
   int8 value;   
   int8 cnt0 = 0; // counter
   OSCCAL_0 = 0;         //set bit 0 in reg 5 to zero.
   setup_adc_ports(sAN0);
   setup_adc(ADC_CLOCK_DIV_4);
   setup_adc( ADC_ON );
       
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_counters(RTCC_INTERNAL,RTCC_DIV_1|DISABLE_PULLUPS); //|DISABLE_PULLUPS
   setup_wdt(WDT_2304MS);
     
  //   output_low(PIN_B2); 
      output_high(PIN_B2); 
 
set_adc_channel(0);
delay_ms( 20000 );       //wait
temp_val = read_adc(); // first reference adc read

while (1)  {

   
output_high(PIN_B1); // 
//output_low(PIN_B2); // 
output_high(PIN_B2); // 


 
         value = read_adc();

           delay_us(100);

            avalue = read_adc();

            delay_us(100);

             val_ref_lo = temp_val - 1; 
         val_ref_hi = temp_val + 1; 
         Val = value -avalue;      

       if (((avalue <= val_ref_lo) || (val_ref_hi <= avalue)) && (Val < 2))
         
         cnt0 = 1;

         delay_ms( 4000 );

         if (cnt0 == 1 && Val < 1)
       
// Activate  //   
    
        for(step = 0;step < 1 ;step++ ){
          delay_ms( 100);
       
           Visual_on (); //
                  Sound_on (); // 

         }
      
   
    else
   //   output_low(PIN_B2); //
       output_high(PIN_B2); //                        
 }
   
}
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Wed Nov 16, 2011 10:03 am     Reply with quote

Semi colon _after_ the return help?
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Nov 16, 2011 8:32 pm     Reply with quote

How about you explain what YOU WANT visual_on and
sound_on to do --- and why any loop is required.

And then also mention HOW Many times you think
the loops are executed in each ??
eabir



Joined: 16 Aug 2010
Posts: 19

View user's profile Send private message

PostPosted: Thu Nov 17, 2011 12:55 am     Reply with quote

I tried return(0), no help.

Even if there is no loop in the visual_on(), the function dont return to main.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Nov 17, 2011 1:24 am     Reply with quote

Do you actually see it's not returning? How? Or is it only a conclusion?
eabir



Joined: 16 Aug 2010
Posts: 19

View user's profile Send private message

HW problem
PostPosted: Thu Nov 17, 2011 2:43 am     Reply with quote

guys,

thank you all, but its a hardware problem of the I/O ports, (after checked with ICE)
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Nov 17, 2011 6:09 am     Reply with quote

It'd be interesting to see the listing to see how the compiler codes.....

for(step = 0;step < 1 ;step++ )

...
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Thu Nov 17, 2011 6:29 am     Reply with quote

Probably it'd code it just like any other for loop on an int loop variable. I doubt the compiler/optimiser is clever enough to realise the inner loop code is 'Allo 'Allo code (i.e. will execute only once), and that the loop test/increment can be optimised away.

RF D.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group