Making a LIGHT FOLLOWING ROBOT | 8051 Tamil Tutorial




Source Code:

#include<reg51.h>
#include<string.h>
sfr LCD = 0x90; 
sbit RS =  P3^5;
sbit EN =  P3^4;
sbit RW =  P3^6;

sbit IN1=P2^0;   //   naming IN1 for P2.0 to connect the in1 pin of the L293d
sbit IN2=P2^1;   //   naming IN2 for P2.1 to connect the in2 pin of the L293d
sbit IN3=P2^2;   //   naming IN3 for P2.2 to connect the in3 pin of the L293d
sbit IN4=P2^3;   //   naming IN4 for P2.3 to connect the in4 pin of the L293d

sbit SENSOR=P0^0;   // connecting sensor output to P0.0

void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
void lcdstr(unsigned char msg[]);
void Delay(unsigned int itime);
void main()
{
SENSOR=1;
lcdcmd(0x38);
    Delay(1);
    lcdcmd(0x01);
    Delay(1);
    lcdcmd(0x06);
    Delay(1);
lcdcmd(0x0C);
Delay(1);
    lcdcmd(0x80);
Delay(1);
    lcdstr(" Light Following");
lcdcmd(0xc0);
Delay(1);
    lcdstr("      Robot      ");

while(1)
{
if(SENSOR==1)
{
IN1=IN3=1;
IN2=IN4=0;
}
else
{
IN1=IN3=0;
IN2=IN4=0;
}
}
}
void lcdcmd(unsigned char value)
{
    LCD = value;
    RS = 0;
    RW = 0;
    EN = 1;
    Delay(1);
    EN = 0;
}
void lcddata(unsigned char value)
{
    LCD = value;
    RS = 1;
    RW = 0;
    EN = 1;
    Delay(1);
    EN = 0;
}
void Delay(unsigned int itime)
{
    unsigned int i,j;
    for(i=0;i<1275;i++)
    for(j=0;j<itime;j++);
}
void lcdstr(unsigned char msg[])
{
    unsigned short int len,i;
    len = strlen(msg);
    for(i=0;i<len;i++)
    {
        lcddata(msg[i]);
        Delay(1);
    }
}

Comments