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.

Program a pic16f88 using mikroc to control a train......Please help!!!!!!!!!

Status
Not open for further replies.

lynford

New Member
Now iv'e got the code to move the train from station to station and the lights working but i need to get a timing system in that counts 10 seconds and if the train does not arrive at the sensor at a station the l.e.d's should start blinking on the part of the track the train is on........

i'm using three sensors for three stations they r a magnetic push button, a reflective, and a break beam.

and another timer to help get the train on time to each station so say if the train is delayed at one station it would make up for it at the other stations.

Now at the 1st station it stops for 5 secs the 2nd station it stops for 3 secs and the 3rd station it stops for 5 secs and returns to the 2nd station and stops for 3 secs and then the 1st and stops for 5 secs..and it takes a max time of 10 secs to travel between stations


This is the code to make the train to go from station to station and control the lights respectively.....

// Train Code V1 travels to stations sensors with lights.

CMCON = 0X07; //PORT A SET TO DIGITAL MODE
TRISA = 0B00011111; // RA.0-RA.4 set to input, rest set to output
TRISB = 0b00000000; // All ports on port b set to output

Void Main()
{
Switch()
{

Case 0:
RB.3 = 0; //all lights green
RB.4 = 0;
RB.5 = 0;
while (RA.0=0) //until station 1 sensor picks up something
{ //train will continue to travel towards station 1
RB.0=1;
RB.2=0;
}
if (RA.0 == 1) //when station1 sensor picks up something train will stop
{ //for 5 seconds and go on to case1 commands
RB.0 = 0;
RB.2 = 0;
delay_ms(500);
case = 1;
}
else //if nothing gets picked up on sensor0 then case 0 will repeat
{
case = 0;
}
break;



Case 1:
RB.3 = 1; //all lights red
RB.4 = 1;
RB.5 = 1;
while (RA.1 = 0) //train will travel towards station2 until sensor1 picks up
{ //something
RB.3 = 0; //Station1 light green
RB.0=0;
RB.2=1;
}
if (RA.1=1}) //if sensor1 picks something up it will stop for 3 seconds
{ //and go on to case2 commands
RB.3 = 1; //station1 light red
RB.0 = 0;
RB.2 = 0;
delay_ms(300);
case = 2;
}
else //if sensor1 doesnt pick something up case 1 will repeat
{
case = 1;
}
break;



Case 2:
while (RA.2 = 0)//train will travel towards station3 until seonsor 2 picks
{ //something up
RB.4 = 0; //station2 light green
RB.0 = 0;
RB.2 = 1;
}
if (RA.2 = 1) //if sensor 2 picks something up train will stop for 5 seconds
{ //and go on to case3 commands
RB.4 = 1; //station2 light red
RB.0 = 0;
RB.2 = 0;
delay_ms(500);
case = 3;
}
else //else case 2 will repeat
{
case = 2
}



Case 3:
while (RA.1 = 0) //train will travel towards station 2 until sensor 1 picks
{ //something up
RB.5 = 0; //station 3 light green
RB.0=1;
RB.2=0;
}
if (RA.1=1}) //if sensor 1 picks up something train will stop for 3 seconds
{ //and go on to case4 commands
RB.5 = 1; //station3 light red
RB.0 = 0;
RB.2 = 0;
delay_ms(300);
case = 4;
}
else //else it will repeat case 3 commands
{
case = 3;
}
break;


Case 4:
while (RA.0 = 0) //train will travel towards station 1 until sensor0 picks up
{ //something
RB.4 = 0; //station 2 light green
RB.0=1;
RB.2=0;
}
if (RA.0=1}) //if sensor0 picks soemthing up then train will stop for 5
{ //seconds and go on to case1 commands
RB.4 = 1; //station2 light red
RB.0 = 0;
RB.2 = 0;
delay_ms(500);
case = 1;
}
else //else it will repeat case 4 commands
{
case = 4;
}
break;


}
 
I can't see how that code even compiles. You have an empty switch statement, lots of comparisons that are assignments ( if(...=..) instead of if(...==..)) and you don't appear to have any variables.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top