Vous êtes sur la page 1sur 5

#include <reg51.

h>
sfr lcd_data_pin=0xA0; //P2 port
sbit rs=P1^0; //Register select pin
sbit rw=P1^1; //Read/Write pin
sbit en=P1^2; //Enable pin
sbit motor=P1^3; //Motor PWM input pin
//void opendoor();
unsigned char card_id[12];
void no_card_error();
unsigned int lcd;
const unsigned char code database[4][4][12] = {{{'F','E','0','0','3','4','8','2','1','2','5','A'},

{'0','0','0','0','0','0','0','0','0','0','0','0'},

{'0','0','0','0','0','0','0','0','0','0','0','0'},

{'0','0','0','0','0','0','0','0','0','0','0','0'}},

{{'F','E','0','0','3','4','F','5','1','9','2','6'},

{'F','E','0','0','6','D','9','C','1','2','1','D'},

{'F','E','0','0','6','E','1','E','D','D','5','3'},

{'F','E','0','0','5','7','8','A','B','D','9','E'}},

{{'F','E','0','0','3','4','A','2','3','1','5','9'},

{'0','0','0','0','0','0','0','0','0','0','0','0'},

{'0','0','0','0','0','0','0','0','0','0','0','0'},

{'0','0','0','0','0','0','0','0','0','0','0','0'}},

{{'F','E','0','0','6','E','4','B','2','1','F','A'},

{'0','0','0','0','0','0','0','0','0','0','0','0'},

{'0','0','0','0','0','0','0','0','0','0','0','0'},

{'0','0','0','0','0','0','0','0','0','0','0','0'}}};

//Database of all users of all categories saved in the code segment because of limited data
segment.
unsigned int customer_account[6] = {0,0,0,0,0,0};

void delay(unsigned int count) //Function to provide delay
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<1275;j++);
}

void timer(int time) //Function to provide timed delay using timer 1
{
int i;
TR1 = 1;
for(i=0;i<time;i++)
{
while(TF1==0);
TF1=0;
}
TR1 = 0;
}

void lcd_command(unsigned char comm) //Lcd command funtion
{
lcd_data_pin=comm;
en=1;
rs=0;
rw=0;
delay(1);
en=0;
}

void lcd_data(unsigned char disp) //Lcd data write function
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}

void lcd_string(unsigned char *disp) //Function to send string
{
int x;
for(x=0;disp[x]!=0;x++)
{
lcd_data(disp[x]);
}
}

void lcd_display(unsigned int val) //Display command, used to display numerical data
{
unsigned char flg=0;
lcd_command(0xCC);
if(val==0)
lcd_data('0');
while(val>0)
{
lcd=val%10;
val=val/10;
lcd_command(0xCC-flg);
lcd_data(lcd+'0');
flg++;
}
}

void lcd_ini() //Function to initialize the LCD
{
lcd_command(0x38);
delay(5);
lcd_command(0x0F);
delay(5);
lcd_command(0x80);
delay(5);
}

void recieve() //Function to recieve data serialy from the RFID module
{
unsigned char k;
for(k=0;k<12;k++)
{
while(RI==0);
card_id[k]=SBUF;
RI=0;
}
}

void det() //Function to find match with database
{ int h,i,j;
int flag=0;
for(j=0;j<12;j++)
{
if(card_id[j] == database[h][i][j])
{
flag++;
}
}
if(flag==12)
{
lcd_command(0x01);
//lcd_command(0x81);
lcd_string("door opening");
delay(1000);
motor=1;
delay(5000);
lcd_command(0xC0);
lcd_string("Door opened");


}
else
no_card_error() ;
motor=0;

}





void display() //Display the amount tolled to user
{
//lcd_command(0x01);
//lcd_command(0x81);

//lcd_string("ROLL: ");
//lcd_display(customer_account[user_id]);
delay(300);
lcd_command(0x01);
lcd_command(0x80);
lcd_string("Thanks for using");

}




void no_card_error() //Show message if card not found
{
lcd_command(0x01);
lcd_command(0x80);
lcd_string("Error (404 :) )");
lcd_command(0xC0);
lcd_string("Card Not found");
}



void main()
{
int l;
SCON=0x50;
lcd_ini();
while(1)
{ TMOD=0x20; //Timer 1 enabled
TH1=0XFD; //Timer 1 set for baud 9600
TR1=1; //Timer 1 start

lcd_command(0x01);
lcd_command(0x81);
lcd_string("Checkpoint:");
lcd_command(0xC1);
lcd_string("Please use RFID");
recieve(); //Call function to read card
delay(50);
lcd_command(0x01);
lcd_command(0x81);
lcd_string("UNIQUE CARD ID:");
lcd_command(0xC1);
for(l=0;l<12;l++)
{
lcd_data(card_id[l]);
}
delay(200);
det();
delay(5);
TR1=0; //Timer 1 switched off
TMOD=0x20; //Use timer 1
TH1 = -23; //Timer 1 loaded with value to allow for 50us counts
delay(200);


}
}

Vous aimerez peut-être aussi