Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

code repeat???

Status
Not open for further replies.

gatoulisss

New Member
hello guys!
is there any way of repeat this code line without writing them?

delay_ms(5000);
if (porta.f0==0) {goto start;}

because if i write it the programm crashes i dont know why... maybe the delay times are too big
 
You can try the program in PicBasicPro or other BASIC and I think it should work, assuming "start" is a label at delay_ms. Does C support "goto"? I doubt it....:eek:

Allen
 
Last edited:
Without knowing where start is, it's hard to advise but the normal method is,
Code:
while(1){                         //loop forever
    delay_ms(5000);
    if (porta.f0==0)
        {/*do something here*/}
} //end while loop

Mike.
Edit, got my remarks mixed up.
 
Last edited:
Yeah, goto's are highly discouraged in C, due to the fact that it makes readability of the code difficult. Its hard to track flow, which impacts maintainability.

Like Pommie suggests, rather write it like that, and make START a function or similar.
Code:
void start(void) {
/* many 'start' things */
}

int main (void) {
  while(1){                       
    delay_ms(5000);
    if (porta.f0=0) {
      start();
    }
  }
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top