Home Login Sign Up Blogs & Articles Jobs Mobiles & Tablets Online Calculators Engineering Projects List Groomix Enterprises Publish your topics Ask Question About Blogs & Articles Feedback

programming

views : 101

Highway vehicle speed detector or checker Embedded C language code in MikroC AVR Framework also applicable for 8051 Microcontroller

This code is tested on AVR ATmega8 microcontroller with buzzer, 16x2 LCD and IR proximity sensors. In this code, time taken is measured for a vehicle to cross fix distance. And from obtained time and distance, speed is culcutated. Buzzer is used to sound when time measurement is starts and then at the time of crossing the second point where time measurement is ended.

Embedded C language code in mikroc AVR

Note : Pin connection should be in according to code below. if any confusion then ask in comments below... 

//start global variables
char str[10] = "000";
unsigned char body_temp_str[7]="000 ";
unsigned char heart_beat_str[4]="00 0";
unsigned char in_char =0;
unsigned char out_char =0;
float time = 1;
float speed = 0;
// End global variables
// LCD module connections
sbit LCD_RS at PORTB0_bit;
sbit LCD_EN at PORTB1_bit;
sbit LCD_D4 at PORTB2_bit;
sbit LCD_D5 at PORTB3_bit;
sbit LCD_D6 at PORTB4_bit;
sbit LCD_D7 at PORTB5_bit;
sbit LCD_RS_Direction at DDB0_bit;
sbit LCD_EN_Direction at DDB1_bit;
sbit LCD_D4_Direction at DDB2_bit;
sbit LCD_D5_Direction at DDB3_bit;
sbit LCD_D6_Direction at DDB4_bit;
sbit LCD_D7_Direction at DDB5_bit;
// End LCD module connections
//start buttons
#define button_PIN1 PINC
#define button_DDR1 DDRC
#define button_PORT1 PORTC
#define button1_1 2
#define button1_2 3
#define button1_3 4
void init_buttons(){  //initialise buttons
button_DDR1 &= ~((1<<button1_3)|(1& lt;<button1_2)|(1<&l t;button1_1));
button_PORT1 |= (1<<button1_3)|(1< ;<button1_2)|(1<< button1_1);
}
//End buttons
//Start Sensors
#define sensors_PIN1 PINC
#define sensors_DDR1 DDRC
#define sensors_PORT1 PORTC
#define sensor1_0 0
#define sensor1_1 1
//define sensor1_2 2
void init_sensors(){ //initialise sensors
sensors_DDR1 &= ~((1<<sensor1_0)|(1& lt;<sensor1_1));
sensors_PORT1 &= ~((1<<sensor1_0)|(1& lt;<sensor1_1));
}
//End sensors
// Start outputs
#define outputs_PORT1 PORTD
#define outputs_DDR1 DDRD
#define buzzer 0         //pin number
//#define relay 1         //pin number
void init_outputs(){    //initialise outputs
outputs_DDR1 |= 1<<buzzer;
//outputs_DDR1 |= 1<<relay;
}
//End outputs

/********************* ************************** ************************** ******
* MAIN PROGRAM
********************** ************************** ************************** *****/
void main(){
  Lcd_Init();                        // Initialize Lcd
  init_buttons();
  init_sensors();
  init_outputs();
  outputs_PORT1 &=~(1<<buzzer); //buzzer OFF
  Delay_ms(100);                     //wait for UART Initialize
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,1,"HWAY SPD CHECKER");
  Lcd_Out(2,1,"Initiati ng.......");
  Delay_ms(1000);
< div style="background:#eeeeee; border:1px solid #cccccc; padding:5px 10px">  while(1){
////////////////////// /////////////ENTRY start///////////////////// //////////////
  unsigned time = 1;
  unsigned int speed = 0;
  if((sensors_PIN1 & (1<< sensor1_1)))
     {   outputs_PORT1 |= (1<<buzzer); //buzzer ON
         Lcd_Out(2,1,"SP D calculating..");
         Delay_ms(10);
         outputs_PORT1 &=~(1<<buzzer); //buzzer OFF
         while(1) {
              time++;
              if((sensors_PIN1 & (1<< sensor1_0))) {
                   break;
              }
              Delay_ms(10);
         }
        speed = (1000/time);
        FloatToStr(speed, str);
        Lcd_Cmd(_LCD_CLEAR);               // Clear display
        Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
        Lcd_Out(1,1,"HWAY SPD CHECKER");
        Lcd_Out(2,1,"SPEED=&q uot;);
        Lcd_Out(2,7,"          ");
        Lcd_Out(2,7,str);
        Delay_ms(2000);
        
        
        if(!(button_PIN1 & (1<< button1_1))) {
          if(speed < 41) {
             Lcd_Cmd(_LCD_CLEAR);               // Clear display
             Lcd_Cmd(_LCD_CURSOR_ OFF);          // Cursor off
             Lcd_Out(1,1,"HI GHWAY SPD CHECKER");
             Lcd_Out(2,1,"SP EED =");
             Lcd_Out(2,7,"          ");
             Lcd_Out(2,7,str);
             Lcd_Out(2,13,"L OW ");
             outputs_PORT1 |= (1<<buzzer); //buzzer ON
             Delay_ms(5000);
             Delay_ms(5000);
             Delay_ms(5000);
             Delay_ms(5000);
             outputs_PORT1 &=~(1<<buzzer); //buzzer OFF
             goto start;
          }
        }
        else {
             if(speed > 60) {
             Lcd_Cmd(_LCD_CLEAR);               // Clear display
             Lcd_Cmd(_LCD_CURSOR_ OFF);          // Cursor off
             Lcd_Out(1,1,"HI GHWAY SPD CHECKER");
             Lcd_Out(2,1,"SP EED =");
             Lcd_Out(2,7,"          ");
             Lcd_Out(2,7,str);
             Lcd_Out(2,13,"H IGH");
             outputs_PORT1 |= (1<<buzzer); //buzzer ON
             Delay_ms(5000);
             Delay_ms(5000);
             Delay_ms(5000);
             Delay_ms(5000);
             outputs_PORT1 &=~(1<<buzzer); //buzzer OFF
             goto start;
          }
       }
     }
     start:
     Lcd_Out(2,1,"NO VEHICLE detected");
  }
}
/********************* ************************** ************************** ******
* End of File
********************** ************************** ************************** *****/

Posted By :
Mr. Unique

2016-08-09/20:52:41

Share this Page

Comments...

Please, Login to comment or reply

More :programming

programming
Arduino UNO tachometer coding with variable resistor and DC motor speed control

p

programming
Here is the code to interface 2 serial devices with AVR

p

programming
Software Uart for AVR microcontroller tested on 1200 baud rate

p

programming
ATMEL STUDIO-While loop conditioning issues

p

programming
ATMEL STUDIO-While loop is not working using interrupt incremented conditioning

p

programming
Copy and paste code for facebook share button in your websites
programming
How to program atmel 8051 family microcontroller? (step by step)
programming
Embedded program code in C language for Digital Voltmeter for AVR microcontroller
programming
Assemby program code for Automatic Door Opening System (8051 family microcontroller)
programming
Very simple and accurate Seven Segment Display program Code in Embedded C language

p

programming
Highway vehicle speed detector or checker Embedded C language code in MikroC AVR Framework also applicable for 8051 Microcontroller

p

programming
Assembly program for accurate 1 second delay function
programming
What is Embedded system programming?

Latest Updates

programming
Arduino UNO tachometer coding with variable resistor and DC motor speed control
views :167

p

programming
Here is the code to interface 2 serial devices with AVR
views :145

p

programming
Software Uart for AVR microcontroller tested on 1200 baud rate
views :724

p

programming
ATMEL STUDIO-While loop conditioning issues
views :181

p

programming
ATMEL STUDIO-While loop is not working using interrupt incremented conditioning
views :278

p

programming
Copy and paste code for facebook share button in your websites
views :284
programming
How to program atmel 8051 family microcontroller? (step by step)
views :289
programming
Embedded program code in C language for Digital Voltmeter for AVR microcontroller
views :231
programming
Assemby program code for Automatic Door Opening System (8051 family microcontroller)
views :171
programming
Very simple and accurate Seven Segment Display program Code in Embedded C language
views :180

p

programming
Highway vehicle speed detector or checker Embedded C language code in MikroC AVR Framework also applicable for 8051 Microcontroller
views :101

p

programming
Assembly program for accurate 1 second delay function
views :149
programming
What is Embedded system programming?
views :180

Reach Us From Google Map

DO MORE WITH US

PRODUCT CATEGORY