Programming: heading views : 0

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
********************** ************************** ************************** *****/
Read More


0 views Write Comment
Share this page with your friends
share via Whatsapp

Posted By :
Mahesh Nigam
(Scientist)
2019-09-27 17:13
See Author's other Published Topics

Airtel cheating ther customers by incomplete description of recharge pack of Big companies like Airtel, also cheating their customers by providing incomplete or confusing description of their recharge plans
Big companies like Airtel, also cheating their customers by providing incomplete or confusing description of their recharge plans
साहस और धैर्य का प्रतिक कारगिल विजय दिवस  of साहस और धैर्य का प्रतिक कारगिल विजय दिवस
साहस और धैर्य का प्रतिक कारगिल विजय दिवस
Vaisakhi  of Vaisakhi
Vaisakhi
3 मार्च - विश्व वन्यजीव दिवस of 3 मार्च - विश्व वन्यजीव दिवस
3 मार्च - विश्व वन्यजीव दिवस
1 मार्च- विश्व प्रशंसा दिवस of 1 मार्च- विश्व प्रशंसा दिवस
1 मार्च- विश्व प्रशंसा दिवस
1 मार्च- विश्व नागरिक सुरक्षा दिवस of 1 मार्च- विश्व नागरिक सुरक्षा दिवस
1 मार्च- विश्व नागरिक सुरक्षा दिवस
1 मार्च - शून्य भेदभाव दिवस of 1 march शून्य भेदभाव दिवस
1 march शून्य भेदभाव दिवस
करती रही of पूरा नही बस थोड़ा सा ही समझा होता ....
पूरा नही बस थोड़ा सा ही समझा होता ....
वैलेंटाइन of वैलेंटाइन डे मनाने के पीछे एक रोचक तथ्य व 7 से 14 तक वैलेंटाइन सेलिब्रेट करने की सूची
वैलेंटाइन डे मनाने के पीछे एक रोचक तथ्य व 7 से 14 तक वैलेंटाइन सेलिब्रेट करने की सूची
National Test Agency of UGC NET December 2023 results and download its subject wise cut-off
UGC NET December 2023 results and download its subject wise cut-off
परीक्षा पे चर्चा  of परीक्षा पे चर्चा युवाओं के लिए तनाव मुक्त माहौल बनाने के लिए प्रधान मंत्री नरेंद्र मोदी के नेतृत्व में बड़े आंदोलन - 'एग्जाम वॉरियर्स' का हिस्सा है।
परीक्षा पे चर्चा युवाओं के लिए तनाव मुक्त माहौल बनाने के लिए प्रधान मंत्री नरेंद्र मोदी के नेतृत्व में बड़े आंदोलन - 'एग्जाम वॉरियर्स' का हिस्सा है।

Peoples