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 support@ccsinfo.com

for (i=0;i<=10;i++) don't work

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



Joined: 17 Apr 2005
Posts: 39
Location: Germany Stuttgart

View user's profile Send private message

for (i=0;i<=10;i++) don't work
PostPosted: Sun Apr 17, 2005 4:05 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Apr 17, 2005 5:37 pm     Reply with quote

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);
}
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