Code:

Rich (BB code):

```
sbit up at P1_0_bit;
sbit down at P1_1_bit;
sbit left at P1_2_bit;
sbit right at P1_3_bit;
sbit led1 at P3_4_bit;
sbit led2 at P3_5_bit;
sbit IN1 at P2_0_bit;
sbit IN2 at P2_1_bit;
sbit IN3 at P2_2_bit;
sbit IN4 at P2_3_bit;
void main()
{
P1=0xff;
P2=0x00;
while(1)
{
led1=0;
led2=0;
IN1=0;
IN2=0;
IN3=0;
IN4=0;
while(up==0)
{
led1=1;
IN1=1;
IN2=0;
IN3=1;
IN4=0;
}
while(down==0)
{
led1=1;
IN1=0;
IN2=1;
IN3=0;
IN4=1;
}
while(left==0)
{
led2=1;
IN1=0;
IN2=1;
IN3=1;
IN4=0;
}
while(right==0)
{
led2=1;
IN1=1;
IN2=0;
IN3=0;
IN4=1;
}
}
}
```

When I press any button it starts motor but after sometime motor stops and led remains glowing and when I press any button nothing works but led remain glowing.So I reset micro controller and then its starts working again but then again same problem arises. So I have to reset controller again and again. Please tell me why its happening like that and how to correct it.