You are on page 1of 1

#include<reg51.

h> //header file for 8051 microcontroller void Main() { P1=0xff; //initialize as an input port P2=0x00; //initialize as an output port while(1) //infinte loop { if(P1==0xf2) //check for key 2-decision is forward { P2=0x0a; //m1 and m2 forward as 1010 these are four lsb bits of port 2 } else if(P1==0xf4) //check for key 4-decision is left { P2=0x08; } else if(P1==0xf6) //check for key 6-decision is right { P2=0x02; } else if(P1==0xf8) //check for key 8-decision is backward { P2=0x05; } else if(P1==0xf5) //check for key 5-decision is stop { P2=0x00; } else P2=0x00; } }

You might also like