Sunday, August 11, 2013

• RFID BASED TOLL COLLECTION SYSTEM




ETC system consists of an RFID reader that continuously receiving RF signal and detecting  the envelope of modulated signal. A Serial RS-232 output which makes it easy to interface it to any microcontroller or computer. The reader senses any RFID tag within a range of 50mm to 150mm and outputs the tag data through both serial RS-232 connection and through TTL pins. The demodulated serial data is compared to existing tag number and if there any number matching with the received number then identifies presence of that object/vehicle, and deducts the ticket amount from their account.
DESIGN

#include <16F877A.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_C6,rcv=PIN_C7,bits=8)

#include <string.h>

void keyboard();
unsigned char get_key();
unsigned char colloc, rowloc, vehicle[3][3][10],a[], str1[12]="VEHICLE ID", STR2[7]="TAG N0", STR3[7] = "AMOUNT", str_1[15] = "ENTER DATA", data1[9] = "ENTER No", str_2[5]="EXIT", veh1[] = "VEHICLE1",veh2[] = "VEHICLE2",veh3[] = "VEHICLE3";
unsigned int i,j,k;
unsigned char keypad[4][4] =  {'0','1','2','3',
                                                  '4','5','6','7',
                                                  '8','9','A','B',
                                                  'K','L','X','E'
                                                  };
//////////////////////////////time out getc() ////////////////////////////////
char timed_getc()
  {
   long timeout;
   timeout=0;  
   while(!kbhit()&&(++timeout<10000))
   delay_us(10);
   if(kbhit())
      return(getc());
   else
      return(0xff);
  }

////////////////////////////////////////LCD   //////////////////////////////////
                         
 void command()
{
output_low(pin_e0);     //RS = 0
output_high(pin_e2);
delay_ms(3);
output_low(pin_e2);
                         //E = 0
}

void data()
{
output_high(pin_e0);    //RS = 1   
output_high(pin_e2);
delay_ms(3);
output_low(pin_e2);
                        //E = 0
}

void lcd_init()
  {
   output_d(0x38);
   command();
   output_d(0x0C);
   command();
   output_d(0x01);
   command();
   output_d(0x80);
   command();
   output_d(0x0E);
   command();
  }
                       
///////////////////////////////GET KEY ///////////////////////////////////
unsigned char get_key()
  {
unsigned char x;
     do
       {
        output_b(0xFF);
        colloc = input_c();      
        colloc &= 0x0F;
       }while(colloc!=0x00);
        
          do
          {
          colloc = input_c();
          colloc &= 0x0F;
          }while(colloc==0x00);
 
   while(1)
       {
        output_b(0x08);
        colloc = input_c();
        colloc &= 0x0F;

      if(colloc != 0x00)
          {
          rowloc = 0;
          break;
          }
         
       output_b(0x04);
        colloc = input_c();
        colloc &= 0x0F;

      if(colloc != 0x00)
          {
          rowloc = 1;
          break;
          }
         
         output_b(0x02);
        colloc = input_c();
        colloc &= 0x0F;

      if(colloc != 0x00)
          {
          rowloc = 2;
          break;
          }
         
       output_b(0x01);
        colloc = input_c();
        colloc &= 0x0F;

      if(colloc != 0x00)
          {
          rowloc = 3;
          break;
          }  
        }  
       
       if(colloc == 0x01)
         x = keypad[0][rowloc];          
       else if(colloc == 0x02)
         x = keypad[1][rowloc];   
       else if(colloc == 0x04)
         x = keypad[2][rowloc];      
       else
         x = keypad[3][rowloc];      
       return(x);
  }
///////////////////////////////   lcd           ////////////////////////////////

void string(char str[])
     {
int i=0;
 lcd_init();
     while(str[i]!='\0')
      {
      output_d(str[i]);
      data();
      delay_ms(3);
      i++;
      }
      delay_ms(20);
   output_d(0x01);
   command(); }

///////////////////////////////////////////////////        READ     ////////////////////////////////////////////////
void read()
       {
unsigned char c;      
      
          for(i=0;i<3;i++)
           {        
           i = 0;        
           for(j=0;j<3;j++)
              {
              for(k=0;k!='\0';k++)
                {
                 c = vehicle[i][j][k];
                 c =
                 output_d(c);
                 data();
              
                }
              }
             
           }      
       }

///////////////////////////       DEDUCT           ////////////////////////////

int deduct(char str[])
   {
   int x,a,b;
   x = str[0]*100;
   i++;
   x = x + str[1]*10;
   i++;
   x = x + str[2]*1;
   return(x);
   x = x-10;
  
   a = x/100;
   str[0] = a;
   a = x%100;
   b = a/10;
   str[1] = b;
   b  = a%10;
   str[2] = b;
   }
/////////////////////////     CHECK     //////////////////////////////////////
check(char str[])    
   {
   if(strcmp(str,vehicle[0][1])==0)
         deduct(vehicle[0][2]);
   else if(strcmp(str,vehicle[1][1])==0)
         deduct(vehicle[1][2]);
   else if(strcmp(str,vehicle[2][1])==0)
         deduct(vehicle[2][2]);
   }

//////////////////////////////////////////////////////////////////////////////
void keyboard()
   {
unsigned char c;
 int i,j,k;
         string(str_1);
          for(i=0;i<3;i++)
           {
            if(i==0)
                string(veh1);
                else if(i==1)
                string(veh2);
                else if(i==2)
                string(veh3);
         
          
           for(j=0;j<3;j++)
              {
                if(j==0)
                string(str1);
                else if(j==1)
                string(str2);
                else if(j==2)
                string(str3);
              for(k=0;k<10;k++)
                {
                           c = get_key();
              
               if((c=='E')||(c=='X'))
                 break;                
                 vehicle[i][j][k]= c;
                 output_d(c);
                 data();
                }
                if(c=='X')
                break;
              }
             if(c=='X')
             {
             string(str_2);
             break;}
           }  
  }

void main()
   {     
    int x;
    lcd_init();
     while(!input(PIN_A0));
      keyboard();
    while(1)
      {


      if(input(PIN_A1))
      read();


     for(i=0;i<10;i++)
      {
      a[i]=getc();
      }
     a[i]='\0';   
  x = check(a);        
     }
   }


-----------------------------