Reverse parking alarm

As we all aware that sound is a function of frequency using this concept we can generate tune of different frequency. this property can be used as application purpose for producing specific sound while reversing your car.this is advanced model of RC-CAR we have designed earlier.it is assumed you know how to interfare LCD and DC-motor with MCU

                

Proteus Design

a sounder is attached to P3.0 pin which produces different sound corresponding to frequency being fed on it. frequency is produced using timer and by toggling P3.0 bit you can produce desired sound.

CODE

in this code 16 bit timer0 is used to produce exact delay. frequency that you would generate depends on x and y. you just need to put value of x and y through any function. function sounder(); will toggle the bit P3.0 which is assigned here as buzzer.

complete code

#include<reg51.h>
#define lcdport P2
sbit rs=P1^4;
sbit en=P1^6;
sbit rw=P1^5;
sbit buzzer=P3^0;
sbit sw1=P3^1;
sbit sw2=P3^2;
sbit sw3=P3^3;
sbit sw4=P3^4;
sbit m1a=P1^0;
sbit m1b=P1^1;// motor 1
sbit m2a=P1^2;
sbit m2b=P1^3;// motor 2
void lcdcmd(char);
void lcdint();
void lcddata(char);
void lcdstring(char *);
void delay(unsigned int);
void timer(unsigned char,unsigned char);
void sounder(unsigned char,unsigned char);

void timer(unsigned char x,unsigned char y)
{
TMOD=0x01;  
TL0=x;      
TH0=y;      
TR0=1;   
while(TF0==0); 
TR0=0;   
TF0=0;    
}
void main()
{
lcdport=0x00;
P1=0x00;
P3=0x00;
lcdint();
   delay(500);
   lcdstring("press 1 to move");
        lcdcmd(0xc0);
   lcdstring("forward...");
   delay(50000);
   lcdcmd(0x01);
   lcdcmd(0x02);
   lcdstring("press 2 to move");
    lcdcmd(0xc0);
   lcdstring("reverse...");
   delay(50000);
   lcdcmd(0x01);
   lcdcmd(0x02);
   lcdstring("press 3 to turn");
   lcdcmd(0xc0);
   lcdstring("right...");
   delay(50000);
   lcdcmd(0x01);
   lcdcmd(0x02);
   lcdstring("press 4 to turn");
   lcdcmd(0xc0);
   lcdstring("left...");
   delay(50000);
   lcdcmd(0x01);
   lcdcmd(0x02);
  while(1)
  {
  if(sw1==1)  //switch 1
   {
   m1a=1;
   m1b=0;
   m2a=0;
   m2b=1;
    lcdstring("moving forward...");
    delay(500000);
    lcdcmd(0x01);
   }
   if(sw2==1)  //switch 2
   {
   m1a=0;
   m1b=1;      
   m2a=1;
   m2b=0;
    lcdstring("moving reverse...");
    sounder(0xfc,0x66);
    delay(500000);
    lcdcmd(0x01);

   }

   if(sw3==1)     // switch 3
   {
   m1a=0;
   m1b=0;
   m2a=0;
   m2b=1;
    lcdstring("turning right...");
    delay(500000);
    lcdcmd(0x01);
   }
   if(sw4==1)       // switch 4
   {
   m1a=1;
   m1b=0;
   m2a=0;
   m2b=0;
    lcdstring("turning left...");
    delay(500000);
    lcdcmd(0x01);
   }
     
    else
    {
   m1a=0;
   m1b=0;
   m2a=0;
   m2b=0;
   }
  }
   
}
 void delay(unsigned int x)
{
 unsigned int i;
 for(i=0;i<x;i++);
}
void lcdint()
{
  lcdcmd(0x38);
  delay(500);
  lcdcmd(0x01);
  delay(500);
  lcdcmd(0x0c);
  delay(500);
  lcdcmd(0x80);
  delay(500);
  lcdcmd(0x0e);
  delay(500);
}
void lcdcmd(char value)
{
  lcdport = value;
  rw=0;
  rs=0;
  en=1;
  delay(500);
  en=0;
}
void sounder(unsigned char p,unsigned char q)
{
int i;
for(i=0;i<100;i++) 
{
  buzzer=1;
  timer(p,q);
  buzzer=0;
  timer(p,q);
}
}  
void lcdstring(char *p)
{
  while(*p!='\0')
   {
     lcddata(*p);
     delay(2000);
     p++;
   }
}
void lcddata(char value)
{
  lcdport = value;
  rs=1;
  rw=0;
  en=1; 
  delay(500);
  en=0;
}

Video

 

Category: 

tags: 

Share

Who's new

  • ravirajpatil871...
  • shubhambajoria
  • yassir
  • demiholyman890954
  • scottgillum51169040

Get Notified

 

Share

We are Social

Syndicate

Subscribe to Syndicate