Can't seem to stop the motor

Hi guys, i'm having some problems with my programme for a school project.


while(1); //repeat

{
if (PORTBbits.RB0==1) //_____________________
{
PORTD=0b00000101; //______________________
Delay10KTCYx(1000);
Delay10KTCYx(1000);
Delay10KTCYx(1000);
Delay10KTCYx(1000);

PORTDbits.RD0=0;
Delay10KTCYx(250);
Delay10KTCYx(250);
Delay10KTCYx(250);
Delay10KTCYx(250);
}
else if (PORTAbits.RA0==1)
{
PORTD=0b00000011; //______________________
Delay10KTCYx(1000);
Delay10KTCYx(1000);
Delay10KTCYx(1000);
Delay10KTCYx(1000);
PORTDbits.RD0=0;
Delay10KTCYx(250);
Delay10KTCYx(250);
Delay10KTCYx(250);
Delay10KTCYx(250);
}

The main idea of this project is for a motor to turn clockwise when a switch has been pressed and that said motor will continue turning for a certain time and then it will stop. after a 2nd switch is pressed, the motor will then turn anti-clockwise for a certain time and then it will stop. my problem is that it simply cannot stop looping. can any kind souls here help me out? my lecturer told me to put another "while(1)" at the end of the delay but that just stops the whole programme.
while(1); //repeat
Is this actually in your code, or does your code say this (no semi-colon)?
while(1) //repeat
there's that function time():

http://www.cplusplus.com/reference/clibrary/ctime/time/

The accuracy is just seconds. But if that suffice you could write something like this:

1
2
3
4
5
time_t seconds = time(NULL) + 2; // Not + 2 means 2 seconds in the future. You may want to change that
while(time(NULL) < seconds) // This will loop for 2 seconds
{
...
}
Topic archived. No new replies allowed.