You are on page 1of 5

#include <16F877A.

h>
#use delay (clock = 20000000)
#fuses HS, NOBROWNOUT, NOWDT, NOLVP//,PROTECT
#use rs232(baud=9600,xmit=PIN_C6, rcv=PIN_C7)//gsm serial
#define LCD_RS_PIN PIN_b0
#define LCD_RW_PIN PIN_b1
#define LCD_ENABLE_PIN PIN_b2
#define LCD_DATA4
PIN_b4
#define LCD_DATA5
PIN_b5
#define LCD_DATA6
PIN_b6
#define LCD_DATA7
PIN_b7
#include <lcd.c>
///////////////////////////////////////////////////////////////////////////////
void ultrasonic_d2 ();
void ultrasonic_d1();
void process_speed();
int16 distance, time;
// Defining variables
#define trig pin_d0 // Change as you wish, can use any pin in the MCU
#define echo pin_d1 // Change as you wish, can use any pin in the MCU
///////////////////////////////////////////////////////////////////////////////
float speed_gsm;
int1 over_flag;
int16 time_counter,d1,d2=0,t1,t2;
///////////////////////////////////////////////////////////////////////////////
void send_sms();
void enter();
#INT_RTCC
void RTCC_isr(void)
{
time_counter++;
}
///////////////////////////////////////////////////////////////////////////////
void main()
{
delay_ms(500);
lcd_init();
lcd_putc(" GSM BSD U-SONIC");

lcd_gotoxy(1,2);
lcd_putc(" SPEED GUN ");
delay_ms(2000);

lcd_putc('\f');
lcd_putc("PROJECT ADVISOR");
lcd_gotoxy(1,2);
lcd_putc("SIR SALEEM ATA");
delay_ms(2000);
lcd_putc('\f');
lcd_putc("DIRECTOR PROJECT");
lcd_gotoxy(1,2);
lcd_putc("SIR KHAN M NAZIR");
delay_ms(2000);
lcd_putc('\f');
lcd_putc(" GROUP MEMBERS ");
delay_ms(2000);
lcd_putc('\f');
lcd_putc("AQIL LATIF MIAN");
lcd_gotoxy(1,2);
lcd_putc(" 071020-098");
delay_ms(2000);
lcd_putc('\f');
lcd_putc("KAMRAN BIN ABDUS");
lcd_gotoxy(1,2);
lcd_putc("SALAM 081220-103");
delay_ms(2000);
lcd_putc('\f');
lcd_putc("SCHOOL OF ");
lcd_gotoxy(1,2);

lcd_putc("ENGINEERING");
delay_ms(2000);
lcd_putc('\f');
lcd_putc("UNI - MANAGEMENT");
lcd_gotoxy(1,2);
lcd_putc(" & TECHNOLOGY");
delay_ms(2000);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32|RTCC_8_bit); //1.6 ms overflow
enable_interrupts(GLOBAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // initiating timer
output_high(pin_a0);
delay_ms(1000);
output_low(pin_a0);
delay_ms(3000);
printf("AT");
putc(13);
delay_ms(1000);
printf("ATE0");
putc(13);
while(true)
{
output_toggle(pin_d2); //code working
time_counter=0;
enable_interrupts(int_rtcc);
ultrasonic_d1();
// reading1
delay_ms(100);
disable_interrupts(int_rtcc);
ultrasonic_d2();
process_speed();
}
}
//////////////////////////////////////////////
void send_sms()
{
delay_ms(1000);

printf("AT+CMGF=1");
enter();
printf("AT+CMGS=\"03124002221\";");
//printf("AT+CMGS=\"03464426168\";");
enter();
printf("OVER SPEEDING ");
printf("SPEED=%3f"speed_gsm);
enter();
putc(26);
}
////////////////////////////////////////////////////////////////////////////////
void enter()
{
putc(13);
delay_ms(500);
}
//////////////////////////////
VOID ultrasonic_d1()
{
output_high(trig);
// start the pulse
delay_us(20);
// sending 20us pulse
output_low(trig);
while(!input(ECHO)) {}
// wait for high state of echo pin and do nothing
set_timer1(0);
// setting timer zero
while(input(ECHO)) {;}
// Wait for high state of echo pin and do nothing
time=get_timer1();
// Getting the time
d1=time*0.028 + 1.093 ;
// Calculating the distance
}
/////////////////////////////////////////////////////
VOID ultrasonic_d2(void)
{
output_high(trig);
// start the pulse
delay_us(20);
// sending 20us pulse
output_low(trig);
while(!input(ECHO)) {}
// wait for high state of echo pin and do nothing

set_timer1(0);
// setting timer zero
while(input(ECHO)) {;}
// Wait for high state of echo pin and do nothing
time=get_timer1();
// Getting the time
d2=time*0.028 + 1.093 ;
// Calculating the distance
}
////////////////////////////////////////////////////////////////////////////////
void process_speed()
{
float dis1,dis2,delta,time_speed;
float speed;
if(d1<100){
if((d1>d2)&&((d1-d2)>10))
{
delta=d1-d2;
delta=delta*0.001;
time_counter=time_counter*1.6;
time_speed=time_counter*0.001;
lcd_gotoxy(1,1);
printf(lcd_putc,"TIME= %3f"time_speed);
lcd_gotoxy(1,2);
//printf(lcd_putc,"d1=%3Lu d2=%3Lu"d1,d2);
speed=delta/time_speed;
speed=(speed*3600)/1000;
printf(lcd_putc"speed=%3f"speed);
delay_ms(2000);
speed_gsm=speed;
if(speed>2) {lcd_putc('\f'); lcd_putc("OVER SPEED"); send_sms(); }
delay_ms(2000);
lcd_gotoxy(1,1);
printf(lcd_putc,"TIME= %3f"time_speed);
lcd_gotoxy(1,2);
printf(lcd_putc"speed=%3f"speed);
}
}
}