Tuesday, June 9, 2015

Black box for car project

Black box for bike/car project is used for vehicle tracking and accident monitoring. This project uses 128x64 Graphical LCD, GSM module, GPS module to track the vehicle and displays real time data on LCD also keeps log of the data. It is having VB6 Software to to display log data.

All required data to develop this project is provided here.

Features:
   1. Keeps log of various activities such as break, indicator, fuel status.
   2. Displays Fuel Level, Time, Position, Speed, Temperature.
   3. Uses Large Graphical Display.
   4. Isolated Inputs.


Microcontroller based vehicle tracking and accident detection system circuit


Step 1: Major Components Required

1. Atmega32 Microcontroller
2. Relays, Switches
3. LM35 Temperature Sensor
4. LM7805
5. PC817
6. 128x64 GLCD Display
7. Buy Components from our Store www.circuits4you.com

Step 2: Circuit Design and PCB Manufacturing
Download Requires Files
1. Download pdf Circuit Diagram
Microcontroller based vehicle tracking and accident detection system PCB Layout
3. Assemble components using above files.

Step 3: Programming the controller
Download Complete Project Code .zip
At some places in code You have to enter your mobile number

AVR Studio Code
/****************************************************************
blog.circuits4you.com
www.circuits4you.com
Black Box For Bike-2012
*****************************************************************/

#include <avr/io.h>
#include <string.h>
#include <avr/pgmspace.h> 
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include "GraphicLCD.h"

//Switch Inputs
//#define Key1         PB2 
//#define Key2        PB4

void Delay100ms();
void Delay();
void Wait();
void USART_Init();
void ProcessFifo();
void USART_Transmit( unsigned char data );
void senddata(char string[16]);

void Command(unsigned char y);
void GPS();
void GSM();
void com();
void SendSMS();
void SendSMS2();

void delay1(unsigned int de);

void DigitOne(char one,char x);
void DisplaySpeed(char speed);

void DisplayAll();
void StoreLog();
void SendLog();

uint32_t WordOfData; 
char MenuCnt,MyStr[8],mystr[3];
unsigned char Fifo[405],RollOut,RMCcnt,RMCflg,Time[8],LAT[10],LON[14],SPEED[6],VTGflg,VTGcnt;

unsigned int Baud,FifoCnt,FiCnt;
unsigned char GraphX, py, pGraphX, u8_data, AsciiX, Value1[65];//Value1[20],Value2[45];
char AsciiZ,once,HexmodeZ,once1, DecimalZ, once2;
unsigned char AsciiY, HexmodeX, HexmodeY, DecimalX,DecimalY;
/*********************************************************************************/
/*                                                                        MAIN PROGRAM                                 */
/*********************************************************************************/
int main(void)
{
//        unsigned char i,j;
         DDRA = 0x30; //PA4 and PA5 as output for selection of rs232
         DDRC = 0b00010000;
        DDRB = 0xFF;
        DDRD = 0b01111110;

        PORTA=0x00;
        PORTA &=~(1<<PA4);   //GPS selection
                delay1(100);
        PORTA &=~(1<<PA5);   //GSM selection



        Delay();

        FifoCnt=0;
        FiCnt=0;
        RollOut=0x00;

        RMCcnt=0;
        RMCflg=0;

        VTGcnt=0;
        VTGflg=0;

        USART_Init();
        SREG=0x80;

        Wait();
        Wait();
        Wait();
        
        com();
        senddata("This is test");

        InitLCD();        
        LCD_Clear();        
        MenuCnt=0;        
        FifoCnt=0;

        GraphX=0;
        AsciiX=0;
        AsciiY=0;
        AsciiZ=0;
        HexmodeX=0;
        HexmodeY=0;
        HexmodeZ=0;
        DecimalX=0;
        DecimalY=0;
        DecimalZ=0;
        once=0;
        once1=0;
        once2=0;

        GPS();
        while(1)
        {
                ProcessFifo();
        }

}

/*********************************************************************************/
/*                                                100 mSec Delay                                                                                   */
/*********************************************************************************/
void DisplayAll()
{
//--------------PICK THIS BLOCK AND PUT IT IN SUBROUTINE------------
                        
                                //USE SERIAL PORT FOR VERIFICATION OF GPS MODULE DATA
unsigned char q;
char j,HH,MM;
        DisplayText(63,19,"Km/Hr");
        DisplayText(1,30,"FUEL:");

        rect(32,30,92,37,1);

        ADMUX=0xE3;
        ADCSRA=0xC7;
        while (!(ADCSRA & (1<<ADIF)));
        q=ADCH;
        if(q>240)
        {q=240;}
        ADCSRA |= 1<<4;
        rect(33,32,91,35,0);        //60= fuel quantity
        rect(33,33,91,34,0);

        rect(32,32,(q/4)+32,35,1);        //60= fuel quantity
        rect(32,33,(q/4)+32,34,1);



        DisplayText(1,45,"LAT N:");//0000000000");
        DisplayText(37,45,LAT);
        DisplayText(1,56,"LON E:");//0000000000");
        DisplayText(37,56,LON);

        if((PINC & 0x08) == 0x08)
        {
                DisplayText(96,21,"     ");
        }
        else
        {
                DisplayText(96,21,"STAND");
        }

        ADMUX=0xE2;
        ADCSRA=0xC7;
        while (!(ADCSRA & (1<<ADIF)));
        q=0;
        q=ADCH;        
        ADCSRA |= 1<<4;
        sprintf(mystr, "%03d", q);

        DisplayText(96,31,mystr);
        DisplayText(118,31,"C");
        rect(114,31,116,33,1);

        
        HH=((Time[0] & 0x0F) *10) + (Time[1] & 0x0F);
        MM=((Time[2] & 0x0F) *10) + (Time[3] & 0x0F);
        
        HH=HH+5;
        MM=MM+30;
        if(MM>59)
        {
                MM=MM-60;
                HH=HH+1;
        }
        sprintf(mystr, "%02d", HH);
        DisplayChar(91,5,mystr[0]);
        DisplayChar(97,5,mystr[1]);
        DisplayChar(103,5,':');
        sprintf(mystr, "%02d", MM);
        DisplayChar(109,5,mystr[0]);
        DisplayChar(115,5,mystr[1]);

//        DisplayText(85,5,"12:00");

        if((PINC & 0x04)==0x04)
        {
                line(100,55,109,48,0);        //Left35 15
                line(100,55,109,61,0);
                line(109,48,109,61,0);
        }
        else
        {
                line(100,55,109,48,1);        //Left35 15
                line(100,55,109,61,1);
                line(109,48,109,61,1);
                StoreLog();
        }

        if((PINC & 0x02)==0x02)
        {
                line(113,48,122,55,0);        //Right   
                line(113,61,122,55,0);                  
                line(113,48,113,61,0);        
        }
        else
        {
                line(113,48,122,55,1);        //Right   
                line(113,61,122,55,1);                  
                line(113,48,113,61,1);                
                StoreLog();
        }

        if((PINC & 0x01) == 0x00) //Break
        {
                StoreLog();
                SendSMS2();
        }
        if((PIND & 0x80)==0x80)        
        {
                //Send SMS Accident
                SREG=0x00;
                GSM();
                        SendSMS();
                GPS();
                SREG=0x80;
        }


                j=0;
                j=(SPEED[2] & 0x0F) | (((SPEED[1] & 0x0F)<<4) & 0xF0);
                DisplaySpeed(j);
}

/*********************************************************************************/
/*                                                100 mSec Delay                                                                                   */
/*********************************************************************************/
void Delay100ms()
{
int k;
        for(k=-29000;k<29000;k++)
        {
                asm("nop");
        }
}
/*********************************************************************************/
/*                                                                        DELAY 100mSec                                */
/*********************************************************************************/
void Delay()
{
        int t;
                for(t=-22500;t<22500;t++)
                {
                        asm("nop");
                }
}
/****************************************************************************************/
/*                                                                          WAIT                                              */
/****************************************************************************************/
void Wait()
{
                Delay100ms();
                Delay100ms();
                Delay100ms();
                Delay100ms();
                Delay100ms();
                Delay100ms();
                Delay100ms();
                Delay100ms();
                Delay100ms();
                Delay100ms();
                Delay100ms();
}

/****************************************************************************************/
/*                                                                          USART INIT                                        */
/****************************************************************************************/
void USART_Init()
{
/* Set baud rate */
//                                            UBRRH=0x00;
//                                                UBRRL=207;        //4800 @ 8MHz
                                            UBRRH=0x00;
                                            UBRRL=103;        //9600 @ 8MHz

//Set double speed
         UCSRA |= (1<<U2X);
/* Enable receiver and transmitter */
        UCSRB = (1<<RXEN) | (1<<RXCIE) | (1<<UCSZ2) | (1<<TXEN);
/* Set frame format: 8data, 1stop bit 1 Parity */
        UCSRC = (1<<URSEL) | (1<<UCSZ0) | (1<<UCSZ1);


//        UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
//Set interrupt on RX
         UCSRB |= (1<<RXCIE);
}
/****************************************************************************************/
/*                                                                          USART Send data                                   */
/****************************************************************************************/
void senddata(char string[16])
{
  int len,count;
  len = strlen(string);

          for (count=0;count<len;count++)
         {
           USART_Transmit(string[count]);
        }
}
/****************************************************************************************/
/*                                                                          USART Transmit                                    */
/****************************************************************************************/

void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) )
;
/* Put data into buffer, sends the data */
UDR = data;
}
/****************************************************************************************/
/*                                                                          USART ISR                                         */
/****************************************************************************************/
SIGNAL(USART_RXC_vect)
{
        u8_data=UDR;

//        USART_Transmit(u8_data);

        Fifo[FifoCnt]=u8_data;
        FifoCnt++;
        if(FifoCnt==400)
        {FifoCnt=0;
         RollOut=0x05;}

        return;        
}
//===================================================================================================
//                                                                           Seial Port 1 - GPS Module
//===================================================================================================
void GPS()
{
/* Set baud rate */
//        UBRRH = 0x00;  //03
//        UBRRL = 207;  //baud rate 4800 at 8MHz 
        UBRRH = 0x00;  //03
        UBRRL = 103;  //baud rate 9600 at 8MHz 

        PORTA &=~(1<<PA5);
        PORTA |=(1<<PA4);
}

//===================================================================================================
//                                                                           Seial Port 2 - GSM Module
//===================================================================================================
void GSM()
{
/* Set baud rate */
        UBRRH = 0x00;  //03
        UBRRL = 103;  //baud rate 9600 at 8MHz 
        
        PORTA &=~(1<<PA4);
        PORTA |=(1<<PA5);
}
//===================================================================================================
//                                                                           Seial Port 2 - GSM Module
//===================================================================================================
void com()
{
/* Set baud rate */
        UBRRH = 0x00;  //03
        UBRRL = 103;  //baud rate 9600 at 8MHz 
        
        PORTA &=~(1<<PA4);
        PORTA &=~(1<<PA5);
}
/****************************************************************************************/
/*                                                                           Fifo process                                     */
/****************************************************************************************/
void ProcessFifo()
{
        //Use circular buffer with fill zero after read to prevent recommand

        if((FifoCnt>FiCnt) || (RollOut==0x05))
        {
                                        Command(Fifo[FiCnt]);
                                        Fifo[FiCnt]=0x00;                                        
                                        FiCnt++;
                                        if(FiCnt==400)
                                        {FiCnt=0;
                                         RollOut=0x00;}
                        
        }
        else
        {
                DisplayAll();
           //************************* MAIN PROCESS COMES HERE *************************************************************
           //***************************************************************************************************************
           //***************************************************************************************************************
        }
}
//===================================================================================================
//                                                                           Process Serial Commands
//===================================================================================================
void Command(unsigned char y)
{
//        int i;
        Value1[43]=Value1[42];
        Value1[42]=Value1[41];
        Value1[41]=Value1[40];
        Value1[40]=Value1[39];
        Value1[39]=Value1[38];
        Value1[38]=Value1[37];
        Value1[37]=Value1[36];
        Value1[36]=Value1[35];
        Value1[35]=Value1[34];
        Value1[34]=Value1[33];
        Value1[33]=Value1[32];
        Value1[32]=Value1[31];
        Value1[31]=Value1[30];
        Value1[30]=Value1[29];
        Value1[29]=Value1[28];
        Value1[28]=Value1[27];
        Value1[27]=Value1[26];
        Value1[26]=Value1[25];
        Value1[25]=Value1[24];
        Value1[24]=Value1[23];
        Value1[23]=Value1[22];
        Value1[22]=Value1[21];
        Value1[21]=Value1[20];
        Value1[20]=Value1[19];
        Value1[19]=Value1[18];
        Value1[18]=Value1[17];
        Value1[17]=Value1[16];

        Value1[16]=Value1[15];
        Value1[15]=Value1[14];
        Value1[14]=Value1[13];
        Value1[13]=Value1[12];
        Value1[12]=Value1[11];

        Value1[11]=Value1[10];
        Value1[10]=Value1[9];
        Value1[9]=Value1[8];
        Value1[8]=Value1[7];
        Value1[7]=Value1[6];
        Value1[6]=Value1[5];
        Value1[5]=Value1[4];
        Value1[4]=Value1[3];
        Value1[3]=Value1[2];
        Value1[2]=Value1[1];
        Value1[1]=Value1[0];
        Value1[0]=y;

//============================================================================================
//                                  GPS Response Decoder
//============================================================================================
//GPS Recived

//$GPRMC,031701.360,A,1950.7141,N,07521.1769,E,000.0,305.2,061210,,,A*69
//       ~~~~~~~      ~~~~~~~~~   ~~~~~~~~~~
//       HHMMSS         LAT          LONG
//     UTC time

        if(Value1[43]=='$' && Value1[42]=='G' && Value1[40]=='R' && Value1[39]=='M' && Value1[38]=='C')
        {
                        Time[0]=Value1[36];  //HH
                        Time[1]=Value1[35];

                        Time[2]=Value1[34];  //MM
                        Time[3]=Value1[33];

                        Time[4]=Value1[32];  //SS
                        Time[5]=Value1[31];

                        LAT[0]=Value1[23];
                        LAT[1]=Value1[22];
                        LAT[2]=Value1[21];
                        LAT[3]=Value1[20];
                        LAT[4]=Value1[19];
                        LAT[5]=Value1[18];
                        LAT[6]=Value1[17];
                        LAT[7]=Value1[16];
                        LAT[8]=Value1[15];

                        LON[0]=Value1[11];
                        LON[1]=Value1[10];
                        LON[2]=Value1[9];
                        LON[3]=Value1[8];
                        LON[4]=Value1[7];
                        LON[5]=Value1[6];
                        LON[6]=Value1[5];
                        LON[7]=Value1[4];
                        LON[8]=Value1[3];
                        LON[9]=Value1[2];

        }

//Get Speed from GPS

//$GPVTG,305.2,T,,M,000.0,N,000.0,K,A*09
//                         ----- speed in km/hr
//$GPVTG,89.68,T,,M,0.00,N,0.0,K,A*5F

        if(Value1[31]=='$' && Value1[30]=='G' && Value1[28]=='V' && Value1[27]=='T' && Value1[26]=='G')
        {
                SPEED[0]=Value1[5];
                SPEED[1]=Value1[4];
                SPEED[2]=Value1[3];
                SPEED[3]=Value1[2];
                SPEED[4]=Value1[1];
        }

// (Get)
        if(Value1[0]==')' && Value1[1]=='t' && Value1[2]=='e' && Value1[3]=='G' && Value1[4]=='(')
        {
                SREG=0x00;
                SendLog();
                SREG=0x80;
        }
}

/****************************************************************************************/
/*                                                                           Display Speed                                    */
/****************************************************************************************/
void DisplaySpeed(char speed)
{
        DigitOne(0,0);
        DigitOne(((speed>>4) & 0x0F),22);
        DigitOne((speed & 0x0F),44);
}

void DigitOne(char one,char x)
{

switch (one){
          case 1:
                line(0+x, 2, 0+x, 11,0);        //Segment F
                line(1+x, 3, 1+x, 10,0);
                line(0+x,14, 0+x, 23,0);        //Segment E
                line(1+x,15, 1+x, 22,0);
                line(1+x,25,15+x, 25,0);        //Segment D
                line(2+x,24,14+x, 24,0);
                line(16+x,2,16+x, 11,1);        //Segment B
                line(15+x,3,15+x, 10,1);
                line(16+x,13,16+x,23,1);        //Segment C
                line(15+x,14,15+x,22,1);
                line(1+x,0, 15+x, 0,0);                //Segment A
                line(2+x,1, 14+x, 1,0);
                line(2+x,12, 14+x, 12,0);                //Segment G
                line(1+x,13, 13+x, 13,0);
          break;
          case 2:
                line(0+x, 2, 0+x, 11,0);        //Segment F
                line(1+x, 3, 1+x, 10,0);
                line(0+x,14, 0+x, 23,1);        //Segment E
                line(1+x,15, 1+x, 22,1);
                line(1+x,25,15+x, 25,1);        //Segment D
                line(2+x,24,14+x, 24,1);
                line(16+x,2,16+x, 11,1);        //Segment B
                line(15+x,3,15+x, 10,1);
                line(16+x,13,16+x,23,0);        //Segment C
                line(15+x,14,15+x,22,0);
                line(1+x,0, 15+x, 0,1);                //Segment A
                line(2+x,1, 14+x, 1,1);
                line(2+x,12, 14+x, 12,1);                //Segment G
                line(1+x,13, 13+x, 13,1);
          break;
          case 3:
                line(0+x, 2, 0+x, 11,0);        //Segment F
                line(1+x, 3, 1+x, 10,0);
                line(0+x,14, 0+x, 23,0);        //Segment E
                line(1+x,15, 1+x, 22,0);
                line(1+x,25,15+x, 25,1);        //Segment D
                line(2+x,24,14+x, 24,1);
                line(16+x,2,16+x, 11,1);        //Segment B
                line(15+x,3,15+x, 10,1);
                line(16+x,13,16+x,23,1);        //Segment C
                line(15+x,14,15+x,22,1);
                line(1+x,0, 15+x, 0,1);                //Segment A
                line(2+x,1, 14+x, 1,1);
                line(2+x,12, 14+x, 12,1);                //Segment G
                line(1+x,13, 13+x, 13,1);
          break;
          case 4:
                line(0+x, 2, 0+x, 11,1);        //Segment F
                line(1+x, 3, 1+x, 10,1);
                line(0+x,14, 0+x, 23,0);        //Segment E
                line(1+x,15, 1+x, 22,0);
                line(1+x,25,15+x, 25,0);        //Segment D
                line(2+x,24,14+x, 24,0);
                line(16+x,2,16+x, 11,1);        //Segment B
                line(15+x,3,15+x, 10,1);
                line(16+x,13,16+x,23,1);        //Segment C
                line(15+x,14,15+x,22,1);
                line(1+x,0, 15+x, 0,0);                //Segment A
                line(2+x,1, 14+x, 1,0);
                line(2+x,12, 14+x, 12,1);                //Segment G
                line(1+x,13, 13+x, 13,1);
          break;
          case 5:
                line(0+x, 2, 0+x, 11,1);        //Segment F
                line(1+x, 3, 1+x, 10,1);
                line(0+x,14, 0+x, 23,0);        //Segment E
                line(1+x,15, 1+x, 22,0);
                line(1+x,25,15+x, 25,1);        //Segment D
                line(2+x,24,14+x, 24,1);
                line(16+x,2,16+x, 11,0);        //Segment B
                line(15+x,3,15+x, 10,0);
                line(16+x,13,16+x,23,1);        //Segment C
                line(15+x,14,15+x,22,1);
                line(1+x,0, 15+x, 0,1);                //Segment A
                line(2+x,1, 14+x, 1,1);
                line(2+x,12, 14+x, 12,1);                //Segment G
                line(1+x,13, 13+x, 13,1);
          break;
          case 6:
                line(0+x, 2, 0+x, 11,1);        //Segment F
                line(1+x, 3, 1+x, 10,1);
                line(0+x,14, 0+x, 23,1);        //Segment E
                line(1+x,15, 1+x, 22,1);
                line(1+x,25,15+x, 25,1);        //Segment D
                line(2+x,24,14+x, 24,1);
                line(16+x,2,16+x, 11,0);        //Segment B
                line(15+x,3,15+x, 10,0);
                line(16+x,13,16+x,23,1);        //Segment C
                line(15+x,14,15+x,22,1);
                line(1+x,0, 15+x, 0,1);                //Segment A
                line(2+x,1, 14+x, 1,1);
                line(2+x,12, 14+x, 12,1);                //Segment G
                line(1+x,13, 13+x, 13,1);
          break;
          case 7:
                line(0+x, 2, 0+x, 11,0);        //Segment F
                line(1+x, 3, 1+x, 10,0);
                line(0+x,14, 0+x, 23,0);        //Segment E
                line(1+x,15, 1+x, 22,0);
                line(1+x,25,15+x, 25,0);        //Segment D
                line(2+x,24,14+x, 24,0);
                line(16+x,2,16+x, 11,1);        //Segment B
                line(15+x,3,15+x, 10,1);
                line(16+x,13,16+x,23,1);        //Segment C
                line(15+x,14,15+x,22,1);
                line(1+x,0, 15+x, 0,1);                //Segment A
                line(2+x,1, 14+x, 1,1);
                line(2+x,12, 14+x, 12,0);                //Segment G
                line(1+x,13, 13+x, 13,0);
          break;
          case 8:
                line(0+x, 2, 0+x, 11,1);        //Segment F
                line(1+x, 3, 1+x, 10,1);
                line(0+x,14, 0+x, 23,1);        //Segment E
                line(1+x,15, 1+x, 22,1);
                line(1+x,25,15+x, 25,1);        //Segment D
                line(2+x,24,14+x, 24,1);
                line(16+x,2,16+x, 11,1);        //Segment B
                line(15+x,3,15+x, 10,1);
                line(16+x,13,16+x,23,1);        //Segment C
                line(15+x,14,15+x,22,1);
                line(1+x,0, 15+x, 0,1);                //Segment A
                line(2+x,1, 14+x, 1,1);
                line(2+x,12, 14+x, 12,1);                //Segment G
                line(1+x,13, 13+x, 13,1);
          break;
          case 9:
                line(0+x, 2, 0+x, 11,1);        //Segment F
                line(1+x, 3, 1+x, 10,1);
                line(0+x,14, 0+x, 23,0);        //Segment E
                line(1+x,15, 1+x, 22,0);
                line(1+x,25,15+x, 25,1);        //Segment D
                line(2+x,24,14+x, 24,1);
                line(16+x,2,16+x, 11,1);        //Segment B
                line(15+x,3,15+x, 10,1);
                line(16+x,13,16+x,23,1);        //Segment C
                line(15+x,14,15+x,22,1);
                line(1+x,0, 15+x, 0,1);                //Segment A
                line(2+x,1, 14+x, 1,1);
                line(2+x,12, 14+x, 12,1);                //Segment G
                line(1+x,13, 13+x, 13,1);
          break;
          default:
                line(0+x, 2, 0+x, 11,1);        //Segment F
                line(1+x, 3, 1+x, 10,1);
                line(0+x,14, 0+x, 23,1);        //Segment E
                line(1+x,15, 1+x, 22,1);
                line(1+x,25,15+x, 25,1);        //Segment D
                line(2+x,24,14+x, 24,1);
                line(16+x,2,16+x, 11,1);        //Segment B
                line(15+x,3,15+x, 10,1);
                line(16+x,13,16+x,23,1);        //Segment C
                line(15+x,14,15+x,22,1);
                line(1+x,0, 15+x, 0,1);                //Segment A
                line(2+x,1, 14+x, 1,1);
                line(2+x,12, 14+x, 12,0);                //Segment G
                line(1+x,13, 13+x, 13,0);
        }

}
/****************************************************************************************/
/*                                                                           Send SMS                                                    */
/****************************************************************************************/
void SendSMS()
{
                                        USART_Transmit(13);
                                        USART_Transmit(10);
                                        senddata("AT+CMGD=1");
                                        USART_Transmit(13);
                                        USART_Transmit(10);
                                        delay1(100);
                                                                                
                                        senddata("AT+CMGF=1");
                                        USART_Transmit(13);
                                        USART_Transmit(10);
                                        delay1(100);
                                        
                                        senddata("AT+CMGW=");
                                        USART_Transmit(34);
                                        
                                        senddata("+910000000000");  //Enter Your Mobile Number Here
                        
                                        USART_Transmit(34);
                                        USART_Transmit(13);
                                        USART_Transmit(10);
                                        delay1(100);
                                        
                                        senddata("Accident ");
                                        USART_Transmit(13);
                                        USART_Transmit(10);
                                        senddata("Location:");
                                        USART_Transmit(13);
                                        USART_Transmit(10);

                                        senddata("LAT N:");
                                        senddata(LAT);

                                        USART_Transmit(13);
                                        USART_Transmit(10);


                                        senddata("LON E:");
                                        senddata(LON);

                                        USART_Transmit(13);
                                        USART_Transmit(10);


                                        delay1(50);
                                        USART_Transmit(26); //Cntrl+Z
                                        delay1(3000);
                                        delay1(300);

                                        senddata("AT+CMSS=1");
                                        USART_Transmit(13);
                                        USART_Transmit(10);
                                        delay1(5000);
}

void delay1(unsigned int de)
{
unsigned int rr,rr1;
   for (rr=0;rr<de;rr++)
   {
                 
                for(rr1=0;rr1<395;rr1++)   //395
                {
                        asm("nop");
                }
                        
   }
}
/****************************************************************************************/
/*                                                                           Store Log                                            */
/****************************************************************************************/
void StoreLog()
{
int Address,counter;
unsigned char HH,MM,Tm,q;
//1. Define Data counter
//2. If Data counter = 30 then counter = 0        
//3. Address = 27 * counter
//4. Write all 27 bytes
//5. counter++

        //eeprom_write_byte((uint8_t*)2,0xFF);

        counter=eeprom_read_byte((uint8_t*)2);
        if(counter>30)
        {
                counter=1;
                eeprom_write_byte((uint8_t*)2,0x01);
        }

        Address=counter * 30;

//                Data format 27 Bytes
//                1. Time        (4 Byte)
//                2. LAN,LOT (20 Bytes)
//                3. Break,Indicator,Stand, Accident (1 Byte)
//                4. Temprature (1 Byte)
//                5. Fuel (1 Byte)

        HH=((Time[0] & 0x0F) *10) + (Time[1] & 0x0F);
        MM=((Time[2] & 0x0F) *10) + (Time[3] & 0x0F);
        
        HH=HH+6;
        MM=MM+30;
        if(MM>59)
        {
                MM=MM-60;
                HH=HH+1;
        }
//Time
        sprintf(mystr, "%02d", HH);
        eeprom_write_byte((uint8_t*)Address,mystr[0]);
        eeprom_write_byte((uint8_t*)(Address+1),mystr[1]);
        
        sprintf(mystr, "%02d", MM);
        eeprom_write_byte((uint8_t*)(Address+2),mystr[0]);
        eeprom_write_byte((uint8_t*)(Address+3),mystr[1]);

//LAT        
        eeprom_write_byte((uint8_t*)(Address+4),LAT[0]);
        eeprom_write_byte((uint8_t*)(Address+5),LAT[1]);
        eeprom_write_byte((uint8_t*)(Address+6),LAT[2]);
        eeprom_write_byte((uint8_t*)(Address+7),LAT[3]);
        eeprom_write_byte((uint8_t*)(Address+8),LAT[4]);
        eeprom_write_byte((uint8_t*)(Address+9),LAT[5]);
        eeprom_write_byte((uint8_t*)(Address+10),LAT[6]);
        eeprom_write_byte((uint8_t*)(Address+11),LAT[7]);
        eeprom_write_byte((uint8_t*)(Address+12),LAT[8]);

//LON
        eeprom_write_byte((uint8_t*)(Address+13),LON[0]);
        eeprom_write_byte((uint8_t*)(Address+14),LON[1]);
        eeprom_write_byte((uint8_t*)(Address+15),LON[2]);
        eeprom_write_byte((uint8_t*)(Address+16),LON[3]);
        eeprom_write_byte((uint8_t*)(Address+17),LON[4]);
        eeprom_write_byte((uint8_t*)(Address+18),LON[5]);
        eeprom_write_byte((uint8_t*)(Address+19),LON[6]);
        eeprom_write_byte((uint8_t*)(Address+20),LON[7]);
        eeprom_write_byte((uint8_t*)(Address+21),LON[8]);
        eeprom_write_byte((uint8_t*)(Address+22),LON[9]);

// Break,Indicator,Stand, Accident (1 Byte)
        Tm=0x00;

        if((PINC & 0x04)==0x00) //Left
        { Tm |= 0x01;        }

        if((PINC & 0x02)==0x00) //Right
        { Tm |= 0x02;        }


        if((PIND & 0x80)==0x80)         //Accident
        { Tm |= 0x04;        }

        if((PINC & 0x08) == 0x00) //Stand
        {Tm |= 0x08;        }
        
        if((PINC & 0x01) == 0x00) //Break
        {Tm |= 0x10;        }


        eeprom_write_byte((uint8_t*)(Address+23),Tm);

//Fuel
        ADMUX=0xE3;
        ADCSRA=0xC7;
        while (!(ADCSRA & (1<<ADIF)));
        q=ADCH;
        if(q>240)
        {q=240;}
        ADCSRA |= 1<<4;
        eeprom_write_byte((uint8_t*)(Address+24),q);

//Temprature
        ADMUX=0xE2;
        ADCSRA=0xC7;
        while (!(ADCSRA & (1<<ADIF)));
        q=ADCH;        
        eeprom_write_byte((uint8_t*)(Address+25),q);
        ADCSRA |= 1<<4;
//Speed

        eeprom_write_byte((uint8_t*)(Address+26),SPEED[0]);
        eeprom_write_byte((uint8_t*)(Address+27),SPEED[1]);
        eeprom_write_byte((uint8_t*)(Address+28),SPEED[2]);
        eeprom_write_byte((uint8_t*)(Address+29),SPEED[3]);
        eeprom_write_byte((uint8_t*)(Address+30),SPEED[4]);

        counter=counter+1;
        eeprom_write_byte((uint8_t*)2,counter);
}

/****************************************************************************************/
/*                                                                           Send Log                                                    */
/****************************************************************************************/
void SendLog()
{
int Address,counter;

        //eeprom_write_byte((uint8_t*)2,0xFF);

for(counter=1;counter<31;counter++)
 {
        Address=counter * 30;

        USART_Transmit('(');

//Time
        USART_Transmit(eeprom_read_byte((uint8_t*)Address));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+1)));
        
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+2)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+3)));

//LAT        
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+4)));                //6
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+5)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+6)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+7)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+8)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+9)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+10)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+11)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+12)));

//LON                        
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+13)));                //15
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+14)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+15)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+16)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+17)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+18)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+19)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+20)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+21)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+22)));

// Break,Indicator,Stand, Accident (1 Byte)

        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+23)));                //25

//Fuel
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+24)));                //26

//Temprature
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+25)));                //27

//Speed

        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+26)));                //28
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+27)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+28)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+29)));
        USART_Transmit(eeprom_read_byte((uint8_t*)(Address+30))); 
        USART_Transmit(')');
        delay1(100);
  }
}
/****************************************************************************************/
/*                                                                           Send Position SMS                                        */
/****************************************************************************************/
void SendSMS2()
{
                                        USART_Transmit(13);
                                        USART_Transmit(10);
                                        senddata("AT+CMGD=1");
                                        USART_Transmit(13);
                                        USART_Transmit(10);
                                        delay1(100);
                                                                                
                                        senddata("AT+CMGF=1");
                                        USART_Transmit(13);
                                        USART_Transmit(10);
                                        delay1(100);
                                        
                                        senddata("AT+CMGW=");
                                        USART_Transmit(34);
                                        
                                        senddata("+910000000000");  //Enter Your Mobile Number Here
                        
                                        USART_Transmit(34);
                                        USART_Transmit(13);
                                        USART_Transmit(10);
                                        delay1(100);
                                        
                                        senddata("Location:");
                                        USART_Transmit(13);
                                        USART_Transmit(10);

                                        senddata("LAT N:");
                                        senddata(LAT);

                                        USART_Transmit(13);
                                        USART_Transmit(10);


                                        senddata("LON E:");
                                        senddata(LON);

                                        USART_Transmit(13);
                                        USART_Transmit(10);


                                        delay1(50);
                                        USART_Transmit(26); //Cntrl+Z
                                        delay1(3000);
                                        delay1(300);

                                        senddata("AT+CMSS=1");
                                        USART_Transmit(13);
                                        USART_Transmit(10);
                                        delay1(5000);
}

Step 5: Download VB6 Software for taking logged data 

Download VB6 PC Code


Step 6: Test the code and Hardware
1. Follow us on Google+
2. You Did it Yourself
3. Refer Tutorials from this site for more understanding of code and Circuits
4. Comment if you find any difficulty.




1 comment: