cdude311
Newbie level 2
- Joined
- Apr 13, 2014
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 63
i have upload the image of connections i have made..and the code is as below
please help as soon as possible.. tommorow is my project submittion day..
//CODING
//Program for RFID based Secured access system using 8051 microcontroller (AT89C51)
#include<reg51.h>
sfr lcd_data_pin=0xA0; //P2 port
sbit rs=P3^4;
sbit en=P3^2;
sbit new_user=P3^0;
unsigned char card_id[12],index=0,key1=0,flag0=0,flag1=0,flag2=0,flag3=0;
unsigned char card_mem[3][12]; //={/*'2','6','0','0','9','3','6','C','B','2','6','B',*/'2','6','0','0','9','1','1','D','D','B','7','1','2','6','0','0','9','3','6','F','7','2','A','8','0','F','0','0','2','D','D','7','D','0','2','5'};
unsigned char card_pswd[3][3];
unsigned char current_byte = 0;
unsigned char R,C,ch;
//unsigned int i=0;
unsigned char Key[3][3] = {'1','2','3',
'4','5','6',
'7','8','9',
};
void display();
void memory();
void DelayMs(int k)
{
unsigned int a;
for(a=0;a<=k;a++);
}
void Key_Scan(void)
{
unsigned int i = 0;
//Scanning for Row Value
P2 = 0x07; //Initialize Port2 to 0Fh
while(P2 == 0x07); //00001111
if(P2 == 0x06) //Checking for Row0 00001110
R = 0;
else if(P2 == 0x05) //Checking for Row1 00001101
R = 1;
else if(P2 == 0x03) //Checking for Row2 00001011
R = 2;
//else if(P2 == 0x07) //Checking for Row3 00000111
//R = 3;
//Scanning for Column Value
P2 = 0x38; //Initialize Port2 to F0h 11110000 00111000
while(P2 == 0x38);
if(P2 == 0x30) //Checking for Column0 11100000 00110000
C = 0;
else if(P2 == 0x28) //Checking for Column1
C = 1;
else if(P2 == 0x18) //Checking for Column2
C = 2;
//else if(P2 == 0x70) //Checking for Column3
//C = 3;
DelayMs(50);
}
void delay(unsigned int count) //Function to provide time delay
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<1275;j++);
}
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 function
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
lcd_string(unsigned char *disp) //Lcd string function
{
int x;
for(x=0;disp[x]!=0;x++)
{
lcd_data(disp[x]);
}
}
void lcd_ini() //Function to initialize the LCD
{
lcd_command(0x38);
delay(5);
lcd_command(0x0F);
delay(5);
lcd_command(0x80);
delay(5);
}
void display() // Function to display the unique ID
{
unsigned char count,i,k,key,flag=0,val;
lcd_command(0x01);
lcd_command(0x80); //Place cursor to second position of second line
val=index;
for(i=0;i<index;i++)
{
key=0;
for(count=0;count<12;count++)
{
if(card_id[count]==card_mem[count])
{
key++;
}
}
if(key==12)
{
key=0;
flag=1;
lcd_command(0x80);
lcd_string("enter ur pswd: ");
lcd_data(49+i);
lcd_command(0xC2);
for(k=0;k<3;k++)
{ // ch=card_pswd[k];
Key_Scan();
ch = Key[C][R]; //Assign Key value to ch;
DelayMs(35); //and Row Value of Keypad
lcd_data(ch);
delay(200);
if(ch==card_pswd[k])
key++;
}
if(key==3)
{lcd_command(0x01);
lcd_command(0x80);
lcd_string("Access granted");
lcd_command(0xC4);
lcd_string("USER ");
lcd_command(0xC9);
lcd_data(49+i);
delay(100);
break;}
else
{lcd_command(0x01);
lcd_command(0x84);
lcd_string("Wrong PSWD");
delay(200);}
}
}
if(flag==0)
{
lcd_command(0x84);
lcd_string("Wrong ID");
delay(200);
}
lcd_command(0x01);
lcd_command(0x80);
lcd_string("Pls scan your ID");
current_byte=0;
}
void recieve() interrupt 4 //Function to recieve data serialy from RS232
{
card_id[current_byte]=SBUF;
RI=0; // Reset the serial interrupt after recievingthe byte
current_byte++;
}
void memory()
{
unsigned char i,key=0,count,try=0,head=0,select=0,mod=0,size,k;
unsigned int in,j;
lcd_command(0x01);
lcd_string("scan your ID");
current_byte=0;
while(current_byte!=12);
current_byte=0;
for(i=0;i<6;i++)
{
key=0;
for(count=0;count<12;count++)
{
if(card_id[count]==card_mem[count])
{
key++;
}
}
if(key==12)
{
size=i;
lcd_command(0x01);
lcd_string("Like to delete");
lcd_command(0xC0);
lcd_string("If yes scan ID");
for(in=0;in<500;in++)
{
for(j=0;j<1275;j++)
{
if(current_byte==12)
{
break;
}
}
if(current_byte==12)
{
break;
}
}
if(current_byte==12)
{
for(in=0;in<12;in++)
{
if(card_id[in]==card_mem[size][in])
{
mod++;
}
}
if(mod==12)
{
for(in=0;in<12;in++)
{
card_mem[size][in]=5;
}
lcd_command(0x01);
lcd_string("congratulation!");
lcd_command(0xC0);
lcd_string("You are deleted");
delay(200);
lcd_command(0x01);
lcd_string("Pls scan your ID");
key=0;
try=1;
break;
}
if(mod!=12)
{
lcd_command(0x01);
lcd_string("You have shown");
lcd_command(0xC0);
lcd_string("different ID");
delay(200);
lcd_command(0x01);
lcd_string("Pls scan your ID");
key=0;
try=1;
break;
}
}
if(current_byte!=12)
{
lcd_command(0x01);
lcd_string("Sorry ! You are");
lcd_command(0xC0);
lcd_string("already an user");
delay(200);
lcd_command(0x01);
lcd_string("Pls scan your ID");
key=0;
try=1;
break;
}
}
}
current_byte=0;
if(key<12 && try==0)
{
key=0;
for(i=0;i<12;i++)
{
card_mem[index]=card_id;
}
current_byte=0;
lcd_command(0x01);
lcd_string("Pls scan again");
while(current_byte!=12);
for(i=0;i<12;i++)
{
if(card_mem[index]==card_id)
{
key++;
}
}
current_byte=0;
if(key==12)
{
lcd_command(0x01);
lcd_string("Pls varify again ");
while(current_byte!=12);
key=0;
for(i=0;i<12;i++)
{
if(card_mem[index]==card_id)
{
key++;
}
}
current_byte=0;
}
else
{
lcd_command(0x01);
lcd_string("ERROR");
delay(200);
for(i=0;i<12;i++)
{
card_mem[index]=0;
}
lcd_command(0x01);
lcd_string("Pls scan your ID");
}
if(key==12)
{
lcd_command(0x01);
lcd_string("enter ur pswd: ");
lcd_command(0xC0);
for(k=0;k<3;k++)
{
Key_Scan();
ch = Key[C][R]; //Assign Key value to ch;
DelayMs(35); //and Row Value of Keypad
lcd_data(ch);
delay(200);
card_pswd[index][k]=ch;
}
/* lcd_command(0x01);
lcd_command(0x80);
delay(200);
for(k=0;k<3;k++)
{ch=card_pswd[k];
lcd_data(ch);}
delay(200);*/
lcd_command(0x01);
lcd_command(0x80);
lcd_string("Congratulation !");
lcd_command(0xC0);
lcd_string("You are User");
lcd_command(0xCC);
lcd_data(index+49);
delay(250);
lcd_command(0x01);
lcd_string("Pls scan your ID");
}
else
{
lcd_command(0x01);
lcd_string("ERROR");
delay(200);
for(i=0;i<12;i++)
{
card_mem[index]=0;
}
lcd_command(0x01);
lcd_string("Pls scan your ID");
}
if(key==12)
index++;
}
}
void main()
{
new_user=1;
TMOD=0x20; //Enable Timer 1
TH1=0XFD;
SCON=0x50;
TR1=1;
IE=0x94;
new_user=0; // Trigger Timer 1
lcd_ini();
memory();
lcd_command(0x80);//Place cursor to second position of first line
lcd_string("Pls scan your ID");
delay(200);
memory();
while(1)
{
//if(new_user==1)
//{
//memory();
//}
if(current_byte==12)
{
display();
}
}
}
please help as soon as possible.. tommorow is my project submittion day..
//CODING
//Program for RFID based Secured access system using 8051 microcontroller (AT89C51)
#include<reg51.h>
sfr lcd_data_pin=0xA0; //P2 port
sbit rs=P3^4;
sbit en=P3^2;
sbit new_user=P3^0;
unsigned char card_id[12],index=0,key1=0,flag0=0,flag1=0,flag2=0,flag3=0;
unsigned char card_mem[3][12]; //={/*'2','6','0','0','9','3','6','C','B','2','6','B',*/'2','6','0','0','9','1','1','D','D','B','7','1','2','6','0','0','9','3','6','F','7','2','A','8','0','F','0','0','2','D','D','7','D','0','2','5'};
unsigned char card_pswd[3][3];
unsigned char current_byte = 0;
unsigned char R,C,ch;
//unsigned int i=0;
unsigned char Key[3][3] = {'1','2','3',
'4','5','6',
'7','8','9',
};
void display();
void memory();
void DelayMs(int k)
{
unsigned int a;
for(a=0;a<=k;a++);
}
void Key_Scan(void)
{
unsigned int i = 0;
//Scanning for Row Value
P2 = 0x07; //Initialize Port2 to 0Fh
while(P2 == 0x07); //00001111
if(P2 == 0x06) //Checking for Row0 00001110
R = 0;
else if(P2 == 0x05) //Checking for Row1 00001101
R = 1;
else if(P2 == 0x03) //Checking for Row2 00001011
R = 2;
//else if(P2 == 0x07) //Checking for Row3 00000111
//R = 3;
//Scanning for Column Value
P2 = 0x38; //Initialize Port2 to F0h 11110000 00111000
while(P2 == 0x38);
if(P2 == 0x30) //Checking for Column0 11100000 00110000
C = 0;
else if(P2 == 0x28) //Checking for Column1
C = 1;
else if(P2 == 0x18) //Checking for Column2
C = 2;
//else if(P2 == 0x70) //Checking for Column3
//C = 3;
DelayMs(50);
}
void delay(unsigned int count) //Function to provide time delay
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<1275;j++);
}
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 function
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
lcd_string(unsigned char *disp) //Lcd string function
{
int x;
for(x=0;disp[x]!=0;x++)
{
lcd_data(disp[x]);
}
}
void lcd_ini() //Function to initialize the LCD
{
lcd_command(0x38);
delay(5);
lcd_command(0x0F);
delay(5);
lcd_command(0x80);
delay(5);
}
void display() // Function to display the unique ID
{
unsigned char count,i,k,key,flag=0,val;
lcd_command(0x01);
lcd_command(0x80); //Place cursor to second position of second line
val=index;
for(i=0;i<index;i++)
{
key=0;
for(count=0;count<12;count++)
{
if(card_id[count]==card_mem[count])
{
key++;
}
}
if(key==12)
{
key=0;
flag=1;
lcd_command(0x80);
lcd_string("enter ur pswd: ");
lcd_data(49+i);
lcd_command(0xC2);
for(k=0;k<3;k++)
{ // ch=card_pswd[k];
Key_Scan();
ch = Key[C][R]; //Assign Key value to ch;
DelayMs(35); //and Row Value of Keypad
lcd_data(ch);
delay(200);
if(ch==card_pswd[k])
key++;
}
if(key==3)
{lcd_command(0x01);
lcd_command(0x80);
lcd_string("Access granted");
lcd_command(0xC4);
lcd_string("USER ");
lcd_command(0xC9);
lcd_data(49+i);
delay(100);
break;}
else
{lcd_command(0x01);
lcd_command(0x84);
lcd_string("Wrong PSWD");
delay(200);}
}
}
if(flag==0)
{
lcd_command(0x84);
lcd_string("Wrong ID");
delay(200);
}
lcd_command(0x01);
lcd_command(0x80);
lcd_string("Pls scan your ID");
current_byte=0;
}
void recieve() interrupt 4 //Function to recieve data serialy from RS232
{
card_id[current_byte]=SBUF;
RI=0; // Reset the serial interrupt after recievingthe byte
current_byte++;
}
void memory()
{
unsigned char i,key=0,count,try=0,head=0,select=0,mod=0,size,k;
unsigned int in,j;
lcd_command(0x01);
lcd_string("scan your ID");
current_byte=0;
while(current_byte!=12);
current_byte=0;
for(i=0;i<6;i++)
{
key=0;
for(count=0;count<12;count++)
{
if(card_id[count]==card_mem[count])
{
key++;
}
}
if(key==12)
{
size=i;
lcd_command(0x01);
lcd_string("Like to delete");
lcd_command(0xC0);
lcd_string("If yes scan ID");
for(in=0;in<500;in++)
{
for(j=0;j<1275;j++)
{
if(current_byte==12)
{
break;
}
}
if(current_byte==12)
{
break;
}
}
if(current_byte==12)
{
for(in=0;in<12;in++)
{
if(card_id[in]==card_mem[size][in])
{
mod++;
}
}
if(mod==12)
{
for(in=0;in<12;in++)
{
card_mem[size][in]=5;
}
lcd_command(0x01);
lcd_string("congratulation!");
lcd_command(0xC0);
lcd_string("You are deleted");
delay(200);
lcd_command(0x01);
lcd_string("Pls scan your ID");
key=0;
try=1;
break;
}
if(mod!=12)
{
lcd_command(0x01);
lcd_string("You have shown");
lcd_command(0xC0);
lcd_string("different ID");
delay(200);
lcd_command(0x01);
lcd_string("Pls scan your ID");
key=0;
try=1;
break;
}
}
if(current_byte!=12)
{
lcd_command(0x01);
lcd_string("Sorry ! You are");
lcd_command(0xC0);
lcd_string("already an user");
delay(200);
lcd_command(0x01);
lcd_string("Pls scan your ID");
key=0;
try=1;
break;
}
}
}
current_byte=0;
if(key<12 && try==0)
{
key=0;
for(i=0;i<12;i++)
{
card_mem[index]=card_id;
}
current_byte=0;
lcd_command(0x01);
lcd_string("Pls scan again");
while(current_byte!=12);
for(i=0;i<12;i++)
{
if(card_mem[index]==card_id)
{
key++;
}
}
current_byte=0;
if(key==12)
{
lcd_command(0x01);
lcd_string("Pls varify again ");
while(current_byte!=12);
key=0;
for(i=0;i<12;i++)
{
if(card_mem[index]==card_id)
{
key++;
}
}
current_byte=0;
}
else
{
lcd_command(0x01);
lcd_string("ERROR");
delay(200);
for(i=0;i<12;i++)
{
card_mem[index]=0;
}
lcd_command(0x01);
lcd_string("Pls scan your ID");
}
if(key==12)
{
lcd_command(0x01);
lcd_string("enter ur pswd: ");
lcd_command(0xC0);
for(k=0;k<3;k++)
{
Key_Scan();
ch = Key[C][R]; //Assign Key value to ch;
DelayMs(35); //and Row Value of Keypad
lcd_data(ch);
delay(200);
card_pswd[index][k]=ch;
}
/* lcd_command(0x01);
lcd_command(0x80);
delay(200);
for(k=0;k<3;k++)
{ch=card_pswd[k];
lcd_data(ch);}
delay(200);*/
lcd_command(0x01);
lcd_command(0x80);
lcd_string("Congratulation !");
lcd_command(0xC0);
lcd_string("You are User");
lcd_command(0xCC);
lcd_data(index+49);
delay(250);
lcd_command(0x01);
lcd_string("Pls scan your ID");
}
else
{
lcd_command(0x01);
lcd_string("ERROR");
delay(200);
for(i=0;i<12;i++)
{
card_mem[index]=0;
}
lcd_command(0x01);
lcd_string("Pls scan your ID");
}
if(key==12)
index++;
}
}
void main()
{
new_user=1;
TMOD=0x20; //Enable Timer 1
TH1=0XFD;
SCON=0x50;
TR1=1;
IE=0x94;
new_user=0; // Trigger Timer 1
lcd_ini();
memory();
lcd_command(0x80);//Place cursor to second position of first line
lcd_string("Pls scan your ID");
delay(200);
memory();
while(1)
{
//if(new_user==1)
//{
//memory();
//}
if(current_byte==12)
{
display();
}
}
}