Monday, May 31, 2010

Winning it never mind whether it is graceful or disgraceful

                         Who is bill gates first thing that comes to a common man is one of the richest , a technical person can remember him as founder of microsoft. What else hmmm yes there are many achievements which make him great . Since morning i have been reading his life history , Till now he was one among who i really adore a lot but as of now he is not . But still i do love  him because not just he is a computer geek , but he is a good business men . In fact more that a computer engineer he is business man . Firstly he was born in a rich family , in his biography unlike other biographies his mother was given a major role . More over bill loved his mother a lot .
                        Directly entering into  the matter i cant narrate his story but i would like to share something regarding him . Well got to confess he is hard worker ,stoic . He was never garrulous by nature. But still he enjoyed technical conversations .  He was good at mathematics and almost all the academic subjects , but he was actually amazed of the computer right from his early age . As his parents are rich he could join into nice big college and guess what  

Wednesday, May 5, 2010

Final project final code

 #include

//------------LCD INITALIZATION-------------------
sbit rs=P0^2;
sbit rw=P0^1;
sbit en=P0^0;
sfr ldata=0x0A0;

void lcdcmd(unsigned char);
void lcdwrt(unsigned int);
void lcddisp(unsigned char *); // for lcd

//--------------------------------------

//-------------ADC0848 DECLARATION-------------------------------------
sbit cs=P3^2;
sbit wr=P3^3;
sbit rd=P3^5;
sbit intr=P3^4;
void convert(unsigned int);
void adc();
unsigned int value; // for adc0848 ic.

//---------------------------------------------------------------------

void delay(unsigned int);
void delay20ms();

// ---------------------------RF DECLARATION---------------------------
sbit rf1=P0^4;
sbit rf2=P0^5;
sbit rf3=P0^6;
sbit rf4=P0^7; // for rf using only 3 swithches

//----------------------------------------------------------------------

//------------------------GSM INITIALIZATION----------------------------
void gsminit();
void sendtoCOM(char *str);
void send_SMS();
void makecall();
unsigned char message[16],in_num[15]={"9908573677"};
unsigned int tmp;
code char *at={"at\r"};
code char *atcmgs={"at+cmgs=\""};
code char *atd={"atd9908573677"};
code char ctrlz[2]={0x1A,0x0};

//----------------------------------------------------------------------

void crazyangle();

void main()
{

    P3=0xFF;
    lcdcmd(0x38);
    delay(10);
    lcdcmd(0x0E);
    delay(10);
    lcdcmd(0x01);
    delay(10);
    lcdcmd(0x06);
    delay(10);
    lcdcmd(0x80);
    delay(10);
    lcdcmd(0xC0);
    delay(10);

    lcddisp("ACCELEROMANIA ");
     delay(50);  
    lcdcmd(0xC0);
    delay(10);
    lcddisp("1:RUNNING MODE");
    delay(50);
    lcddisp("2:PARKING MODE");
    delay(50);
    lcddisp("3:IDLE MODE");
    delay(50);
    lcddisp("4:ANGLE MEASURING");
    delay(50);

       gsminit();              // LCD general initialization
    adc();                    // calling adc funtion;

}


void adc()
{
    int check=0;
    intr=1;
    cs=1;
    wr=1;
    rd=1;
   
    while(1)
    {
        P1=0x08;                        // Initiating the channel in among control lines
        cs=0;
        wr=0;
        delay(50);
        wr=1;
        cs=1;
        P1=0xFF;
        while(intr==1);
        cs=0;
        rd=0;
        delay(50);
        rd=1;
        value=P1;
        cs=1;
        convert(value);
       
        if(rf1==1&&rf2==0&&rf3==1&&rf4==1)
            {
                check=20;               // switch to switch off parking mode
            }
   
        if(rf1==0&&rf2==1&&rf3==1&&rf4==1)
            {

                check=30;             // switch to switch on parking mode
            }

        if(rf1==1&&rf2==1&&rf3==0&&rf4==1)
            {
                check=40;            // switch to switch on IDLE mode i.e, nothing works
            }
        if(rf1==1&&rf2==1&&rf3==1&&rf4==0)
            {
                check=50;            // switch to switch on IDLE mode i.e, nothing works
            }


        if(check==20)
            {
                if(value>120)
                    {
                        lcdcmd(0xC0);
                        delay(10);
                        lcddisp("BIKE STOLEN  ");
                        delay(10);
                        makecall();
                        delay(50);
                        send_SMS();
                    }
                else if(value<109)
                    {
                        lcdcmd(0xC0);
                        delay(10);
                        lcddisp("BIKE FELL DOWN ");
                        delay(10);
                    }
                else
                    {
                        lcdcmd(0xC0);
                        delay(10);
                        lcddisp("SECURE  ");
                        delay(10);
                    }
            }
         if(check==30)
            {
                if(value>155)
                    {
                   
                        lcdcmd(0xC0);
                        delay(10);
                        lcddisp("FALLEN RIGHT    ");
                        delay(10);
                        delay(500);
                        if(value>155)
                         send_SMS();
                    }
                else if(value<115)
                    {
                   
                        lcdcmd(0xC0);
                        delay(10);
                        lcddisp("FALLEN LEFT   ");
                        delay(10);
                        delay(500);
                        if(value<115)
                         send_SMS();
                    }
                else
                    {
                        lcdcmd(0xC0);
                        delay(10);
                        lcddisp("NORMAL POSITION ");
                        delay(10);
                    }
        }

    if(check==40)
        {
            lcdcmd(0xC0);
            delay(10);
            lcddisp("IDLE MODE  ");
            delay(10);
        }
    if(check==50)
        {
           crazyangle();
        }


    }
}


    void convert(unsigned int temp)
        {
            int x,y,j;
            unsigned int arr[10],i=0;
            while(temp!=0)
                {
                    x=temp/10;
                    y=temp%10;
                    arr[i++]=y;
                    temp=x;
                }
            lcdcmd(0x80);
            delay(10);
            for(j=i-1;j>=0;j--)
                {
                    lcdwrt(arr[j]);
                    delay(10);
                }

         }


void lcdcmd(unsigned char val)
{
    ldata=val;
    rs=0;
    rw=0;
    en=1;
    delay(1);
    en=0;
}

void lcdwrt(unsigned int m)
{
    ldata=0x30+m;
    rs=1;
    rw=0;
    en=1;
    delay(1);
    en=0;
}

void delay(unsigned int x)
{
    int i,j;
    for(i=0;i<=x;i++)
    for(j=0;j<=1275;j++);
}

void lcddisp(unsigned char *value)
{
    while(*value!='\0')
        {
            ldata=*value;
            rs=1;
            rw=0;
            en=1;
            delay(1);
            en=0;
            value++;
        }
}


void gsminit()
{
   
   
    TMOD=0X20;                               // Timer 1-8-bit auto reload
    TH0=0X4C;
    TL0=0X1E;                               // Timer 0 - 50ms delay;


    TH1=0XFD;                                //9600 baud rate

    SCON=0X50;                             // serial transmission
    TR1=1;                                  // timer 1 start,i.e enable serial transmission
    TR0=1;                                   // Timer 0 start;


    sendtoCOM(at);

    for(tmp=0;tmp<50;tmp++)
        delay20ms();

     //---------FOR THEFT MANAGEMENT---------------------------------
   
        message[0]='B';
           
        message[1]='I';
           
        message[2]='K';
           
        message[3]='E';
       
        message[4]=' ';
       
        message[5]='S';   
           
        message[6]='T';   
           
        message[7]='O';
           
        message[8]='L';
           
        message[9]='E';
           
        message[10]='N';

        message[11]='\0';

 }

 void sendtoCOM(char *str)
{
    while(*str!='\0')
    {
        SBUF=*str++;
        while(!TI);
        TI=0;
        for(tmp=0;tmp<50;tmp++)
        delay20ms();
    }
}

void send_SMS()
{



    sendtoCOM(atcmgs);

    for(tmp=0;tmp<50;tmp++)
        delay20ms();

   
    sendtoCOM(in_num);

    for(tmp=0;tmp<50;tmp++)
        delay20ms();

    sendtoCOM("\"\r");

    for(tmp=0;tmp<50;tmp++)
        delay20ms();

        sendtoCOM(message);
      
    for(tmp=0;tmp<50;tmp++)
        delay20ms();

    sendtoCOM(ctrlz);

    for(tmp=0;tmp<50;tmp++)
        delay20ms();
       
}
void makecall()
 {
  
   sendtoCOM(atd);
       for(tmp=0;tmp<50;tmp++)
        delay20ms();
 }

void delay20ms()
{
unsigned int i;
for(i=1;i<5117;i++);
}

void crazyangle()
{
  int x;
  x=(value-115)+3;
  lcdcmd(0x80);
  delay(10);
  convert(x);
 
}



      This code is now capable of detecting accident and for security and for one crazy extra activity of measuring the angle with respect to ground when we are travelling ..