pic simulation

Thread Starter

mosajawdet

Joined Mar 5, 2013
6
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
 

tshuck

Joined Oct 18, 2012
3,534
Rich (BB code):
Your condition is false and will exit the loop
for( i=1; i==120 ;i++);<- this semicolon means the for loop has no body
{
Delay_ms(30000);
Delay_ms(30000);
}
 

Thread Starter

mosajawdet

Joined Mar 5, 2013
6
Rich (BB code):
Your condition is false and will exit the loop
for( i=1; i==120 ;i++);<- this semicolon means the for loop has no body
{
Delay_ms(30000);
Delay_ms(30000);
}
Dear :
I remove the semicolon but after one minute the port goes on it must be off for tow hours
 

thatoneguy

Joined Feb 19, 2009
6,359
you mean using if statement
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.
 

tshuck

Joined Oct 18, 2012
3,534
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....
 

tshuck

Joined Oct 18, 2012
3,534
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.
...ah yes, that would make sense....

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