Title:DC Motor Interface With PIC18f4520 using L293D
Program:
//Author : Palak Patel(M.Tech)
//Contact No:9173211683
//Title:DC motor
//Platform: PIC18f4520
//Software:MPLAB
#include<p18f4520.h>
#define in1 PORTDbits.RD0
#define in2 PORTDbits.RD1
#define en1 PORTDbits.RD2
#define sw PORTBbits.RB0
#define sw1 PORTBbits.RB1
#define sw2 PORTBbits.RB2
#define lcd PORTC
void cmd(unsigned char);
void dat(unsigned char);
void Delay_ms(unsigned char);
void main()
{
unsigned char i,name[]="Reverse Running",j,name1[]="Forward
Running",k,name2[]="MotorOff";
TRISB=0xFF;
TRISC=0x00;
TRISD=0x00;
ADCON1=0x0F;
cmd(0x01);
cmd(0x02);
cmd(0x28);
cmd(0x06);
cmd(0x0c);
while(1)
{
if(sw==0 && sw1==1 && sw2==1)
{
while(1)
{
en1=1;
in1=1;
in2=0;
cmd(0x01);
i=0;
cmd(0x80);
while(name[i]!='\0')
{
dat(name[i]);
i++;
}
if(sw1==0 || sw2==0)
break;
}
}
if(sw==1 && sw1==0 && sw2==1)
{
while(1)
{
en1=1;
in1=0;
in2=1;
cmd(0x01);
i=0;
cmd(0x80);
while(name1[i]!='\0')
{
dat(name1[i]);
i++;
}
if(sw==0 || sw2==0)
break;
}
}
if(sw2==0 && sw==1 && sw1==1)
{
while(1)
{
en1=0;
cmd(0x01);
j=0;
cmd(0x80);
while(name2[j]!='\0')
{
dat(name2[j]);
j++;
}
if(sw==0 || sw1==0)
break;
}
}
else
{
while(1)
{
en1=0;
cmd(0x01);
j=0;
cmd(0x80);
while(name2[j]!='\0')
{
dat(name2[j]);
j++;
}
if(sw==0 || sw1==0)
break;
}
}
}
}
void cmd(unsigned char k)
{
lcd &=0x0F;
lcd |=(k & (0xF0));
lcd |=(2<<0);
Delay_ms(20);
lcd=lcd & 0xFC;
Delay_ms(20);
lcd &=0x0F;
lcd |=((k<<4) & (0xF0));
lcd |=(2<<0);
Delay_ms(20);
lcd=lcd & 0xFC;
Delay_ms(20);
}
void dat(unsigned char k)
{
lcd &=0x0F;
lcd |=(k & 0xF0);
lcd |=(3<<0);
Delay_ms(20);
lcd=lcd & 0xFD;
Delay_ms(20);
lcd &=0x0F;
lcd |=((k<<4) & (0xF0));
lcd |=(3<<0);
Delay_ms(20);
lcd=lcd & 0xFD;
Delay_ms(20);
}
void Delay_ms(unsigned char p)
{
unsigned char i,j;
for(i=0;i<p;i++)
{
for(j=0;j<50;j++);
}
}
Simulation:
1. Motor Off:
2.Reverse Running:
3.Forward Running:
For Basic Electronics Kindally follow this Link:
This comment has been removed by the author.
ReplyDeleteawat coding fail
ReplyDelete