pic simulation

Discussion in 'Embedded Systems and Microcontrollers' started by mosajawdet, Mar 5, 2013.

  1. mosajawdet

    Thread Starter New Member

    Mar 5, 2013
    6
    0
    Hi
    I'm made a program in micro c for pic16f877a but when i make a simulation using Proteus the program work the first step ok but the second no can help me ? my program :

    void main() {
    char i;
    trisd=0x00;
    portd=0;
    while(1){
    Portd.f0=1;
    Delay_ms(30000);
    Delay_ms(30000);
    Delay_ms(30000);
    Delay_ms(30000);
    portd.f0=0;
    for( i=1; i==120 ;i++);
    {
    Delay_ms(30000);
    Delay_ms(30000);
    }
    }
    }

    the delay for tow hours doesn't work
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Code ( (Unknown Language)):
    1. [COLOR="lime"]Your condition is false and will exit the loop[/COLOR]
    2. for( i=1;[COLOR="Lime"] i==120[/COLOR] ;i++)[COLOR="Red"];<- this semicolon means the for loop has no body[/COLOR]
    3. {
    4. Delay_ms(30000);
    5. Delay_ms(30000);
    6. }
     
    ErnieM likes this.
  3. mosajawdet

    Thread Starter New Member

    Mar 5, 2013
    6
    0
    Dear :
    I remove the semicolon but after one minute the port goes on it must be off for tow hours
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    ...did you fix what I hi-lighted in green?
     
  5. mosajawdet

    Thread Starter New Member

    Mar 5, 2013
    6
    0
    yes i do (i==120 )
     
  6. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    So, when the for-loop initialization sets i = 0, then tests whether i == 120, and evaluates to false( 0 != 120), this is desired operation?:confused:
     
  7. mosajawdet

    Thread Starter New Member

    Mar 5, 2013
    6
    0
    i make the for like this
    for( i=0; i==120 ;i++)
    but doesn't work :confused:
     
  8. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Yes, see my reasoning from the post you quoted.. You are setting i to 0, then entering the loop if i is 120, since it isn't, the loop isn't executed.

    FOR loop
     
  9. mosajawdet

    Thread Starter New Member

    Mar 5, 2013
    6
    0
    i make the for like this
    for( i=0; i==120 ;i++)
    but doesn't work :confused:
     
  10. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Your conditional statement is wrong. Again, go read the link I supplied in the previous post.
     
  11. mosajawdet

    Thread Starter New Member

    Mar 5, 2013
    6
    0
    you mean using if statement
     
  12. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    With your current usage, the test condition of i==120 will only run the loop if i==120, since the assignment starts by setting i=0, the loop will not run. If your initial assignment sets i=120, the loop would run one time.

    If you change i==120 to i<120, then i<=120 will be true, and it will run the loop until i > 120.
     
  13. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    I was hoping the OP could be bothered to read through the link so he/she would understand why it should be i <= 120, but there it is...

    @OP: Please try to help yourself and read the link provided....
     
  14. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    I believe the OP is a non-english speaker. That must be tough trying to figure out what is being said, then figure out what that means.
     
    thatoneguy likes this.
  15. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    ...ah yes, that would make sense....

    ...you can lead a horse to water, but you can't make it read Chinese...
     
Loading...