Controlling 2 motors in
both forward, reverse and one forward one reverse operation according to the 4
input pins. When input is 1110=both in forward;1101=both in reverse;1011=left
one forward right one stop; 0111=left one stop and right one forward.
MicroCode:
#include<reg51.h>
sfr sw=0x90;
sbit EN1=P2^0;
sbit EN2=P3^0;
sbit MTR1_0=P2^1;
sbit MTR1_1=P2^2;
sbit MTR2_0=P3^1;
sbit MTR2_1=P3^2;
void main( )
{
EN1=0;
MTR1_0=0;
MTR1_1=0;
EN2=0;
MTR2_0=0;
MTR2_1=0;
while(1)
{
EN1=1;
EN2=1;
if(sw==0xFE)
{
MTR1_0=0;
MTR1_1=1;
MTR2_0=0;
MTR2_1=1;
}
else if(sw==0xFD)
{
MTR1_0=1;
MTR1_1=0;
MTR2_0=1;
MTR2_1=0;
}
else if(sw==0xFB)
{
MTR1_0=0;
MTR1_1=1;
MTR2_0=0;
MTR2_1=0;
}
else if(sw==0xF7)
{
MTR1_0=0;
MTR1_1=0;
MTR2_0=0;
MTR2_1=1;
}
else
{
MTR1_0=0;
MTR1_1=0;
MTR2_0=0;
MTR2_1=0;
}
}
}
Result: to see output
No comments:
Post a Comment
comment here