1. gatoulisss

    Thread Starter Member

    Jan 23, 2015
    34
    0
    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
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,001
    What do you mean "repeat"?

    Have you heard of the for loop?

    Code (Text):
    1.  
    2. for (i=0; i<5; i++)
    3. {
    4.    delay_ms(5000);
    5.    if (porta.f0==0) {goto start;}
    6. }
    7.  
    8.  

    And you should avoid using goto. It makes for messy code. Use should be very rare. Using it a lot is as sign of newbie code.
     
  3. gatoulisss

    Thread Starter Member

    Jan 23, 2015
    34
    0

    i use loops but after 5 times of writting this then the programm excecutes ( i dont know why) i want to make 4 modes of checking an alarm sensor
    mode A: no ring only sensor check
    mode B: every 15sec ring with every 5sec sensor check
    mode C: every 30 sec ring with every 5sec sensor check
    mode D: every 60sec ring with every 5sec sensor check

    im using lot of time delays and also 12 different sounds so the program is big and maybe thats why i cant use more delays i dont know...
    the goto im usisng it because i want to break from loops but continue check them
     
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,001
    You are going to have to be more clear than that. I am not sure what you are trying to say.

    If I do understand you can have a variable to store the"mode". The have a switch statement and a case for each mode. Look up switch / case for C on google.
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    I don't now why either as you have shows such a small fragment of your code it is impossible to see what you are doing.

    What is this mysterious "start" label you refer to?

    What are these loops?

    Have you ever heard of the "break" command in C?
     
  6. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    Complete guess given the lack of detail but how about
    Code (Text):
    1. while(porta.f0==0) {
    2.      delay_ms(5000);
    3. }
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    One thing I do note in the following:
    Everything happens in an integer multiple of 5 seconds. Thus I have no idea why there is any reason for a delay other than 5 seconds.

    15 seconds between rings means wait 3 periods between rings.
    30 seconds between rings means wait 6 periods between rings.
    60 seconds between rings means wait 12 periods between rings.
     
Loading...