How to make robot car using 8051
YouTube link here How to make robot car using 8051
Please find the Code details below:
#include<reg51.h>
sbit m1p = P2^0; // Motor 1 positive terminal is assigned to port 2(P2^0)
sbit m1n = P2^1; //Motor 1 negative terminal is assigned to port 2(P2^1)
sbit m2p = P2^2; // Motor 2 positive terminal is assigned to port 2(P2^2)
sbit m2n = P2^3; // Motor 2 negative terminal is assigned to port 2(P2^3)
sbit m3p = P2^4; // Motor 3 positive terminal is assigned to port 2(P2^4)
sbit m3n = P2^5; // Motor 3 negative terminal is assigned to port 2(P2^5)
sbit m4p = P2^6; // Motor 4 positive terminal is assigned to port 2(P2^6)
sbit m4n = P2^7; // Motor 4 negative terminal is assigned to port 2(P2^7)
sbit F = P1^0; // Forward switch is connected to port 1(P1^0)
sbit Ba = P1^1; // Backward switch is connected to port 1(P1^1)
sbit R = P1^2; // Right switch is connected to port 1(P1^2)
sbit L = P1^3; // Left switch is connected to port 1(P1^3)
void forward() // Robot forwarding function
{
m1p = 1;
m2p = 1;
m3p = 1;
m4p = 1;
m1n = 0;
m2n = 0;
m3n = 0;
m4n = 0;
}
void backward() // Robot backward function
{
m1p = 0;
m2p = 0;
m3p = 0;
m4p = 0;
m1n = 1;
m2n = 1;
m3n = 1;
m4n = 1;
}
void left() // Robot left turning function
{
m1p = 1;
m1n = 0;
m2p = 1;
m2n = 0;
m3p = 0;
m3n = 1;
m4p = 0;
m4n = 1;
}
void right() // Robot right turning function
{
m1p = 0;
m1n = 1;
m2p = 0;
m2n = 1;
m3p = 1;
m3n = 0;
m4p = 1;
m4n = 0;
}
void stop() // Robot stop function
{
m1p = 0;
m1n = 0;
m2p = 0;
m2n = 0;
m3p = 0;
m3n = 0;
m4p = 0;
m4n = 0;
}
void main() // Main function
{
F = 0; // Initialize all switches are equal to zero
Ba = 0;
L = 0;
R = 0;
while(1)
{
if(F==1)
forward();
else if(Ba==1)
backward();
else if(L==1)
left();
else if(R==1)
right();
else
stop();
}
}
Thank You :)
Comments
Post a Comment