/* wired robo car program for 8051 microcontroller
design description:;: contains two motors one on left(ml) and one on right(mr)::
contains headlights and backlights::moreover this is wired robo car (not wireless) */
#include<reg51.h>
sbit mr_p = P2^0;
sbit mr_n = P2^1; //motor_right_negetive
sbit ml_p = P2^2; //motor_left_positive
sbit ml_n = P2^3; //motor_left_negetive
sbit leds_front = P2^4;
sbit en_mr = P2^6; //motor_right_enable
sbit en_ml = P2^7; //motor_left_enable
sbit led_backL = P3^0;
sbit led_backR = P3^1;
sbit head_lights = P1^6;
sbit key = P1^5;
sbit fw = P1^0;
sbit re = P1^1;
sbit left = P1^2;
sbit right = P1^3;
sbit stop = P1^4;
void main()
{
int i;
fw = re = left = right = stop = head_lights = key = 1;
mr_p = mr_n = ml_p = ml_n = leds_front = en_mr = en_ml = 0;
led_backL = led_backR = 0;
while(1)
{
while(key==0)
{
if(head_lights==0)
leds_front=1;
else
leds_front=0;
while(fw==0)
{
en_ml=1;en_mr=1;
mr_p=1; mr_n=0;
ml_p=1; ml_n=0;
if(head_lights==0)
leds_front=1;
else
leds_front=0;
while(left==0)
{
led_backL=1;
en_ml=0;
for(i=0;i<100;i++);
led_backL=0;
}
while(right==0)
{
led_backR=1;
en_mr=0;
for(i=0;i<100;i++);
led_backR=0;
}
if(stop==0)
{
en_ml=0;
en_mr=0;
}
}
while(re==0)
{
en_ml=1;en_mr=1;
mr_p=0; mr_n=1;
ml_p=0; ml_n=1;
if(head_lights==0)
leds_front=1;
else
leds_front=0;
while(left==0)
en_mr=0;
while(right==0)
en_ml=0;
if(stop==0)
{
en_ml=0;
en_mr=0;
}
}
while(left==0)
{
if(head_lights==0)
leds_front=1;
else
leds_front=0;
en_ml=0;en_mr=1;
mr_p=1; mr_n=0;
}
while(right==0)
{
if(head_lights==0)
leds_front=1;
else
leds_front=0;
en_ml=1;en_mr=0;
ml_p=1; ml_n=0;
}
en_ml=0;
en_mr=0;
}
leds_front=0;
}
}
No comments:
Post a Comment