View previous topic :: View next topic |
Author |
Message |
aaaaamartin
Joined: 17 Apr 2005 Posts: 39 Location: Germany Stuttgart
|
for (i=0;i<=10;i++) don't work |
Posted: Sun Apr 17, 2005 4:05 pm |
|
|
hi,
i tried:
int i,rota, rotb;
main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
for (i=0;i<=100;++i)
{
output_high(pin_c1);
delay_ms(30);
output_low (PIN_C1);
}
}
The Loop runs one time, and not ten times es expected.
Is this due to optimization ?
Writing more sophisticated things inside the loop makes it run 10 times.
I'm bored.
Please help
Martin |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Apr 17, 2005 5:37 pm |
|
|
Rule 1: Always post a complete program, including the #fuses and delay statements, etc. Often errors are in the #fuses statement so we can see what processor and clock speed you are using.
Rule 2: When posting code use the 'Code' button. This will help to preserve the layout of your code and makes it much easier for everybody to read.
The problem in your example is very likely because you have no delay after the output_low() function call, so in the next loop iteration the pin is set high again before you are able to detect the pin change.
change to:
Code: | for (i=0;i<=100;++i)
{
output_high(pin_c1);
delay_ms(30);
output_low (PIN_C1);
delay_ms(30);
} |
|
|
|
|