Sunday, July 14, 2013

PROJECT 1. INTELLIGENT GSM NOTICE BOARD


The projects interfacing with GSM (Global system for mobile communication ) always having access of a system with accessibility all over the world i.e we can control the a device through the mobile phone from anywhere in the world. These advantage is the result of digital communication technique. In this project the short message service(SMS) is utilized to send an information and displaying on notice board. This project will be helpful in developing a real time application. Moreover, the aim of this project, is to gain the knowledge about PIC16F876A Microcontroller, GSM modem and the way in which these can be used to receive messages and display on notice board. PIC16F876A is a popular microcontroller. We are using CCS compiler. Project code is given below.
ELECTRONIC TOLL COLLECTION SYSTEM RFID
CODE
#include <16F876A.h>
#device adc=8
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Crystal osc <= 4mhz
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES WRT_50%                  //Lower half of Program Memory is Write Protected
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C4,rcv=PIN_C5,bits=8,stream=gsm)

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// INTELLIGENT GSM NOTICE BOARD /////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int i,j,f=0,flag1=0;
char name[29] = "INTELLIGENT GSM NOTICE BOARD",emr[20]="Emergency message",a;
char str[70];
char x;
const char m0[4]  = "AT\r";
const char m1[11] = "AT+CMGF=1\r";
const char m2[22] = "AT+CMGS=\"9496084923\"\r";
const char m3[11] = "AT+CMGR=1\r";
const char m4[11] = "AT+CMGD=1\r";
void receive();
void sent();
void msg1();
void msg2();

////////////////////////////////LCD FUNCTIONS////////////////////////////////////////////

void command()
{
output_low(pin_c0);     //RS = 0
output_high(pin_c2);
delay_ms(100);
output_low(pin_c2);
                     //E = 0
}
void data()
{
output_high(pin_c0);    //RS = 1   
output_high(pin_c2);
delay_ms(100);
output_low(pin_c2);
                     //E = 0
}
void lcd_init()
  {
   output_b(0x38);
   command();
   output_b(0x0C);
   command();
   output_b(0x01);
   command();
   output_b(0x80);
   command();
  }

////////////////////////////////////////////////////////////////////////////////////////
short timeout_error;
char timed_getc()
 {
   long timeout;
   timeout_error = FALSE;
   timeout = 0;
   while(!kbhit()&&(++timeout<5000))
   delay_us(10);
   if(kbhit(gsm))
   return(fgetc(gsm));
   else
    {
     timeout_error = TRUE;
     return(0);
    }
 }
 ////////////////////////////////////////////////////////////////////////////////////////////////



 void display1(char *a)
 {
 i=0,j=0;
       
        while(j!=16)
        {
        output_b(*a);
        data();
        delay_ms(200);
        a++;
        j++;
        }
        output_b(0xC0);
        command();
        while(*a!='\0')
        {
        output_b(*a);
        data();
        delay_ms(200);
        a++;
        j++;
        }
      
 }


 void display2(char *a)
 {
 i=0,j=0;
       
        while(*a!='\0')
        {
        output_b(*a);
        data();
        delay_ms(200);
        a++;
        j++;
        }
    delay_ms(100); 
    output_b(0x01);
    command();  
 }


 void shift(int n)
     {
  i=0;    
  while(i!=n)
   {
   output_b(0x18);
   command();
   delay_ms(400);
   i++;
   }
   output_b(0x01);
   command();  
   }
////////////////////////////////////////////////////////////////////////
void sent()
{
for(i=0;i<3;i++)
   {
   fputc(m0[i],gsm);
   a=timed_getc();
   }
   a=timed_getc();
   a=timed_getc();
delay_ms(500);
for(i=0;i<10;i++)
   {
   fputc(m1[i],gsm);
   a=timed_getc();
   }
   a=timed_getc();
   a=timed_getc();
delay_ms(500);
for(i=0;i<21;i++)
   {
   fputc(m2[i],gsm);
   a=timed_getc();
   }
   a=timed_getc();
   a=timed_getc();
output_bit(PIN_a0,1);  
delay_ms(500);
output_bit(PIN_a0,0);
delay_ms(500);
}

void msg2()                                                  //optional - testing
 {
for(i=0;str[i]!='\0';i++)
   {
   fputc(str[i],gsm);
   a=timed_getc();
   }
   a=timed_getc();
   a=timed_getc();
   delay_ms(2000);
   fputc(0X1A,gsm);
   a=timed_getc();
  output_bit(PIN_a1,1);  
delay_ms(500);
output_bit(PIN_a1,0);
delay_ms(500);
 }


 void del()
   {
     i=0;
     while(i!=13)
     {
     x = timed_getc();
     i++;
     }
     x = timed_getc();
    
     if(x=='1')
     {
     flag1 = 1;
    
     output_bit(PIN_a0,1);  
delay_ms(1000);
output_bit(PIN_a0,0);
delay_ms(1000);
     }
    
   }

//////////////////////////////// SMS receiving function /////////////////////////
void receive()
   {
   for(i=0;i<3;i++)
   {
   fputc(m0[i],gsm);
   a=timed_getc();
   }
   a=timed_getc();
   a=timed_getc();
  
output_bit(PIN_a0,1);  
delay_ms(300);
output_bit(PIN_a0,0);
  
for(i=0;i<10;i++)
   {
   fputc(m1[i],gsm);
   a=timed_getc();
   }
   a=timed_getc();
   a=timed_getc();
output_bit(PIN_a1,1);  
delay_ms(300);
output_bit(PIN_a1,0);

for(i=0;i<10;i++)
   {
   fputc(m3[i],gsm);
   a=timed_getc();
   }
   a=timed_getc();
   a=timed_getc();
   
while(a!='*')
   {
   a=timed_getc();
  
   }
    
for(i=0;str[i-1]!='#';i++)
   {
   a=fgetc(gsm);
   str[i]=a;
   }
str[i-1] = '\0';
a=timed_getc();
if(a=='*')
f=1;
a=timed_getc();
a=timed_getc(); 
output_bit(PIN_a4,1);  
delay_ms(300);
output_bit(PIN_a4,0);

for(i=0;i<10;i++)
   {
   fputc(m4[i],gsm);
   a=timed_getc();
   }
   a=timed_getc();
   a=timed_getc();

output_bit(PIN_a5,1);  
delay_ms(300);
output_bit(PIN_a5,0);
  
   }
   
#int_RDA                
void  RDA_isr(void)
{

output_bit(PIN_a2,1);  
delay_ms(1000);
output_bit(PIN_a2,0);
delay_ms(1000);

del();

output_bit(PIN_a3,1);
delay_ms(1000);
output_bit(PIN_a5,0);
delay_ms(1000);
}


  
void main()
        {
        enable_interrupts(GLOBAL);
        enable_interrupts(INT_RDA);
       
        delay_ms(300);
        lcd_init();
        display1(name);
        shift(17);
      
        
                                                        //msg sending ckeck
       receive();    
       if(f==1)
         {
         display1(emr);
         shift(17);
         f=0;
         }
         sent();
         msg2();
      
      
   ///////////////////sending to LCD/////////////////////////
            
         i=0;
         delay_ms(10);
         output_b(0X80);
         command();
        while(str[i]!='\0')
        {
        output_b(str[i]);
        data();
        delay_ms(200);
        i++;
         }
    delay_ms(100);
    i=0 ;
     do
     {
      output_b(0X18);
      command();
      i++;
      delay_ms(400);
      if(flag1==1)
      {
      flag1=0;
      receive();
     
      }
     
     }while(1);
    
    
    
    
    }