RFID SECURITY SYSTEM C CODE
#include
#include
#include
sbit BUZZER=P2^0;
char a[4][3]={'1','2','3','4','5','6','7','8','9','*','0','#'};
char b[4][3]={'*','*','*','*','*','*','*','*','*','*','*','*'};
char pass9[] = {'1','2','3','4','\0'};
char r=0,e=0,l;
char msg[]="ENTERPASS:",password[6];
char i,j,k,c=0;
int z=0,s,f=0;
xdata char *ptr_cmd = (xdata char *)0x0FFF8; //LCD command mode control
xdata char *ptr_en = (xdata char *)0x0FFF9; //LCD Enable
char mybyte;
void busy_check();
void out();
void pass_word();
void baud_init();
void release_key();
void key_press();
void debounce();
void column();
void init_lcd1();
void display1(char *name);
void clear_lcddisplay();
void card_match();
void second_line();
void card_mismatch();
void serial_buzz_command();
void baud_init()
{
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
}
void delay1()
{
int y = 100;
while(y--);
}
void serial_tx()
{
SBUF = 0x42;
while(TI == 0);
TI = 0;
delay1();
SBUF = 0x01;
while(TI == 0);
TI = 0;
delay1();
SBUF = 0x59;
while(TI == 0);
TI = 0;
delay1();
}
char serial_rx()
{
int x;
while(RI == 0);
{
x++;
if(x==1000)
serial_tx();
}
mybyte = SBUF;
RI = 0;
return (mybyte);
}
void busy_check()
{
*ptr_cmd = 0x02;
while((*ptr_en & 0x80) != 0x00){}
}
void delaysec()
{
unsigned long int i=10000;
while(i--);
}
void lcd_comm()
{
*(ptr_cmd) = 0x00;
}
void init_lcd()
{
lcd_comm();
*(ptr_en) = 0x38;
busy_check();
lcd_comm();
*(ptr_en) = 0x0E;
busy_check();
lcd_comm();
*(ptr_en) = 0x80;
busy_check();
lcd_comm();
*(ptr_en) = 0x01;
busy_check();
}
void second_line()
{
lcd_comm();
*(ptr_en) = 0xc0;
busy_check();
}
void display(char *name)
{
int l = strlen(name);
int i;
for(i = 0; i < l ;i++)
{
*(ptr_cmd) = 0x01;
*(ptr_en) = name[i];
busy_check();
}
}
void delay2()
{
unsigned int i = 10000;
while ( i-- );
}
void delay()
{
unsigned int i = 50000;
while ( i-- );
}
void display2()
{
*(ptr_cmd) = 0x01;
*(ptr_en) = b[r][c];
busy_check();
}
void column()
{
if ((P3 & 0x30) == 0x30)
{
c=0;
display2();
password[z] = a[r][c];
z++;
delay();
}
else if((P3 & 0x28) == 0x28)
{
c=1;
display2();
password[z] = a[r][c];
z++;
delay();
}
else if((P3 & 0x18) == 0x18)
{
c=2;
display2();
password[z] = a[r][c];
z++;
delay();
}
}
void clear_lcddisplay()
{
lcd_comm();
*( ptr_en ) = 0x01;
busy_check();
lcd_comm();
*( ptr_en ) = 0x01;
busy_check();
}
void init_lcd1()
{
lcd_comm();
*( ptr_en ) = 0x38;
busy_check();
lcd_comm();
*(ptr_en) = 0x0e;
busy_check();
lcd_comm();
*(ptr_en) = 0x80;
busy_check();
lcd_comm();
*(ptr_en) = 0x01;
busy_check();
for(i=0;i<10;i++)
{
*(ptr_cmd) = 0x01;
*(ptr_en) = msg[i];
busy_check();
}
}
void debounce()
{
P1 = 0xfe; //ground row 0 only
while((P3 & 0x38) != 0x38)
{
r=0;
column();
}
P1 = 0xfd; //ground row 1 only
while((P3 & 0x38) != 0x38)
{
r=1;
column();
}
P1 = 0xfb; //ground row 2 only
while((P3 & 0x38) != 0x38)
{
r=2;
column();
}
P1 = 0xf7; //ground row 3 only
while((P3 & 0x38) != 0x38)
{
r=3;
column();
}
}
void release_key()
{
P1 = 0xf0;
while((P3 & 0x38) == 0x38)
{delay2();}
P3 = 0x0ff;
debounce();
delay ();
}
void first_line()
{
lcd_comm();
*(ptr_en) = 0x80;
busy_check();
}
void buzzer()
{
char del=0;
BUZZER=1;
for(del=0;del<=10;del++)
{
delay();
}
P2=0x00;
}
//***************************************************************************************************
//MAIN PROGRAM STARTS HERE//
//***************************************************************************************************
void main()
{
P2=0x00;
while(1)
{
char i=0;
char serial_no[21];
char temp1[]={'1','D','0','0','E','4','F','7','\0'};
baud_init();
init_lcd();
display("DIP CARD NEAR ME");
serial_tx();
while(i<=8)
{
baud_init();
serial_no[i]=serial_rx();
i++;
}
if(*serial_no==*temp1)
{
card_match();
}
else
{
card_mismatch();
}
// while(1);
}
}
void card_match()
{
char f,o=4;
second_line();
display("CARD ACCEPT");
for(f=0;f<6;f++)
{
delay();
}
f=0;
init_lcd1();
while(o--)
{
release_key();
}
password[z] = '\0';
f = strcmp(pass9,password);
if (f == 0 )
{
second_line();
display("PASSWORD VALID");
delay();
delay();
second_line();
display("NAME:XY EMP NO:5");
delay();
delay();
delay();
clear_lcddisplay();
}
else if ((f >= 1 ) || (f <= -1))
{
second_line();
display("PASSWORD INVALID");
clear_lcddisplay();
delay();
delay();
second_line();
display("NOT AN EMPLOYEE");
buzzer();
delay();
delay();
delay();
clear_lcddisplay();
}
}
void card_mismatch()
{
second_line();
display("RONG CARD CALLSE");
buzzer();
delay();
delay();
clear_lcddisplay();
}
RFID SECURITY SYSTEM C CODE
RAJESHS, Monday, October 26, 2009
Labels:
RFID SECURITY SYSTEM C CODE
Subscribe to:
Post Comments (Atom)
Comments :
Post a Comment