View previous topic :: View next topic |
Author |
Message |
eabir
Joined: 16 Aug 2010 Posts: 19
|
No return from function, why? |
Posted: Wed Nov 16, 2011 10:01 am |
|
|
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
|
|
Posted: Wed Nov 16, 2011 10:03 am |
|
|
Semi colon _after_ the return help? |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Nov 16, 2011 8:32 pm |
|
|
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
|
|
Posted: Thu Nov 17, 2011 12:55 am |
|
|
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
|
|
Posted: Thu Nov 17, 2011 1:24 am |
|
|
Do you actually see it's not returning? How? Or is it only a conclusion? |
|
|
eabir
Joined: 16 Aug 2010 Posts: 19
|
HW problem |
Posted: Thu Nov 17, 2011 2:43 am |
|
|
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
|
|
Posted: Thu Nov 17, 2011 6:09 am |
|
|
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
|
|
Posted: Thu Nov 17, 2011 6:29 am |
|
|
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. |
|
|
|