Saturday, January 23, 2021

RFID based In/Out system using 8051 with Keil c51 and Proteus simulator

    

Free online courses with Free Certificate

Keil c51:

DevC++ compiler(or IDE)

Download link: Click here

step-1: right click on "Keil uvision" and click on "run as administrator"


step-2: now go to project >> new project >> "project_name.uvproj"



step-3: select "at89c51" as shown below



step-3: now file >> new file



step-4: click on save as then save with "file_name.c" i.e. with ".c" extension



step-5: now copy code given below and paste and save it, as shown below






step-6: to the left side of window right click on "Source group 1" and then click on "add existing file to source group 1"



step-7: now click on project  >>  build target to compile this code i.e. to check if any error in code



step-8: to generate "hex file" of this code right click on "target 1" tab to the left side of your window and then click on "options for target 'target 1'... " as shown below



step-9: now change frequency to "11.0592MHz" and tick to "use on-chip ROM" as shown below



step-10: now in same window options click on output >> tick to "create hex file" as shown below



step-11: click again on "build target" to create "hex file" as shown below







Embedded C code :


Code with comments for understanding

#include<reg51.h>


//for in-out car

sbit doorp=P2^0; //clockwise rotation

sbit doorn=P2^1; //anticlockwise rotation


//for display

sbit rs=P2^5; //reg select fun of lcd

sbit rw=P2^6; //read write fun of lcd

sbit en=P2^7; //enable fun of lcd


//lcd functions

void lcddat(unsigned char); //dat fun of lcd

void lcdcmd(unsigned char); //command fun of lcd

void lcddis(unsigned char *); //display fun of lcd

void lcd_init(); //iniialization of lcd

void serial_init(); //write serial comm steps betwn rfid and uc

void check(); //to compare person in existing dat or outside dat

void delay(); //for lcd

void mdelay(); //for motor

unsigned char rfid[12],v1; //rfid 12 byte siz tag


void main()

{

doorp=doorn=0; //motor stop

serial_init();

lcd_init();

lcddis("RFID BASED CAR");

lcdcmd(0xc0); //cursor shit on second line

lcddis("PARKING SYSTEM");

mdelay();

lcdcmd(0x01);

while(1)

{

lcdcmd(0x01);

lcddis("SWIPE YOUR CARD");

for(v1=0;v1<12;v1++) //this loop is to read 12 digits of rfid card

{

while(RI==0); //if RI=1 dat is ready in sbuf

rfid[v1]=SBUF;

RI=0;

SBUF=rfid[v1]; //next 3 lines are for re-tx of chr to simulate on proteus

while(TI==0);

TI=0;

}

check(); //to compare person in existing dat or outside dat

}

}

void check()

{

//RFID TAG OF BARAK OBAMA-35858VUET8G8 

if(rfid[0]=='3'&&rfid[1]=='5'&&rfid[2]=='8'&&rfid[3]=='5'&&rfid[4]=='8'&&rfid[5]=='V'&&rfid[6]=='U'&&rfid[7]=='E'&&rfid[8]=='T'&&rfid[9]=='8'&&rfid[10]=='G'&&rfid[11]=='8') 

//if loop for comparing rfid tag positions from 0 to 7 with respective number as given above

{

lcdcmd(0x01);

lcddis("TEAM MEMBER");

lcdcmd(0xc0);

lcddis("OBAMA-SLOT 1");

mdelay();

lcdcmd(0x01);

doorp=1;

doorn=0;

lcddis("OPENING DOOR");

lcdcmd(0xc0);

lcddis("PLEASE GO INSIDE");

mdelay();

doorp=0;

doorn=0;

lcdcmd(0x01);

doorp=0;

doorn=1;

lcddis("CLOSING DOOR");

mdelay();

doorp=0;

doorn=0;

}

//RFID TAG OF JOE BIDEN-4WRF723RF24F

else if(rfid[0]=='4'&&rfid[1]=='W'&&rfid[2]=='R'&&rfid[3]=='F'&&rfid[4]=='7'&&rfid[5]=='2'&&rfid[6]=='3'&&rfid[7]=='R'&&rfid[8]=='F'&&rfid[9]=='2'&&rfid[10]=='4'&&rfid[11]=='F') 

//if loop for comparing rfid tag positions from 0 to 7 with respective number as given above

{

lcdcmd(0x01);

lcddis("TEAM MEMBER");

lcdcmd(0xc0);

lcddis("BIDEN-SLOT 2");

mdelay();

lcdcmd(0x01);

doorp=1;

doorn=0;

lcddis("OPENING DOOR");

lcdcmd(0xc0);

lcddis("PLEASE GO INSIDE");

mdelay();

doorp=0;

doorn=0;

lcdcmd(0x01);

doorp=0;

doorn=1;

lcddis("CLOSING DOOR");

mdelay();

doorp=0;

doorn=0;

}

//RFID TAG OF GEORGE BUSH JR-5F8344FN9229 

else if(rfid[0]=='5'&&rfid[1]=='F'&&rfid[2]=='8'&&rfid[3]=='3'&&rfid[4]=='4'&&rfid[5]=='4'&&rfid[6]=='F'&&rfid[7]=='N'&&rfid[8]=='9'&&rfid[9]=='2'&&rfid[10]=='2'&&rfid[11]=='9')

//if loop for comparing rfid tag positions from 0 to 7 with respective number as given above

{

lcdcmd(0x01);

lcddis("TEAM MEMBER");

lcdcmd(0xc0);

lcddis("BUSH JR-SLOT 3");

mdelay();

lcdcmd(0x01);

doorp=1;

doorn=0;

lcddis("OPENING DOOR");

lcdcmd(0xc0);

lcddis("PLEASE GO INSIDE");

mdelay();

doorp=0;

doorn=0;

lcdcmd(0x01);

doorp=0;

doorn=1;

lcddis("CLOSING DOOR");

mdelay();

doorp=0;

doorn=0;

}

//RFID TAG OF BILL CLINTON-D58END83MS9E

else if(rfid[0]=='D'&&rfid[1]=='5'&&rfid[2]=='8'&&rfid[3]=='E'&&rfid[4]=='N'&&rfid[5]=='D'&&rfid[6]=='8'&&rfid[7]=='3'&&rfid[8]=='M'&&rfid[9]=='S'&&rfid[10]=='9'&&rfid[11]=='E')

//if loop for comparing rfid tag positions from 0 to 7 with respective number as given above

{

lcdcmd(0x01);

lcddis("TEAM MEMBER");

lcdcmd(0xc0);

lcddis("CLINTON-SLOT 4");

mdelay();

lcdcmd(0x01);

doorp=1;

doorn=0;

lcddis("OPENING DOOR");

lcdcmd(0xc0);

lcddis("PLEASE GO INSIDE");

mdelay();

doorp=0;

doorn=0;

lcdcmd(0x01);

doorp=0;

doorn=1;

lcddis("CLOSING DOOR");

mdelay();

doorp=0;

doorn=0;

}

else

{

lcdcmd(0x01);

lcddis("DONALD TRUMP");

lcdcmd(0xc0);

lcddis("GET OUT !!!");

mdelay();

}

}


void serial_init()

{

SCON=0X50; //serial comm with recieve enable mode

TMOD=0X20; //timer mode 2

TH1=-3; //baud rate 9600

TR1=1; //start timer

}

void lcd_init()

{

lcdcmd(0x38); //initialize 5x7 matrix lcd

lcdcmd(0x01); //clear screen

lcdcmd(0x10); //shift cursor to right

lcdcmd(0x0c); //display on cursor off

lcdcmd(0x80); //start display from first line first position

}

void lcdcmd(unsigned char val)

{

P1=val;

rs=0;

rw=0;

en=1; //high

delay(); //to

en=0; //low

}

void lcddat(unsigned char val)

{

P1=val;

rs=1;

rw=0;

en=1; //without going en from high to low, it wont allow to display next chr

delay();

en=0;

}

void lcddis(unsigned char *s) //unsigned chr equated with s

{

unsigned char w; //w is tem var

for(w=0;s[w]!='\0';w++) //to pass strng of words, chr by chr. comapre s[w] with null chr \n,

//loop continues untill unless it wont get s[w] equal to null chr

{

lcddat(s[w]);

}

}

void delay()

{

unsigned int v5;

for(v5=0;v5<6000;v5++);

}

void mdelay()

{

unsigned int v6,v7;

for(v6=0;v6<2;v6++)

{

for(v7=0;v7<60000;v7++);

}

}

Free online courses with Free Certificate

Free online courses with Free Certificate

Free online courses with Free Certificate


Proteus:

Download linkClick here !


step: right click on "Proteus 8 professional"(whichever version available) and "run as administrator"

step: now go to project >> new project >> "New Project.pdsprj"


step: click on "P" and open window for "pick devices" as shown below


step: now type "at89c51" and select microcontroller then press ok


step: now add other components as shown below:

1. Motor driver as L293D :




2. 20X2 LCD Display as LM032L:



3. Motor :



4. click on Instruments >> virtual terminal as shown in below figure

when "swipe card" appears on display, enter "12 digit RFID card number" as stored in program



step: now final circuit as shown below




step: now double click on microcontroller symbol then "edit component" window will open. then click on "folder symbol" to select ".hex" file and change frequency to 11.0592MHz as shown below

Note- make sure you know path of ".hex" file generated through Keil c51 as shown below

e.g. - ..\..\..\Keil_v5\C51\Examples\my project\Objects\7segment 8051.hex


step: click on "play button" and check output as shown below




Enter 12 digit RFID card number in Virtual terminal




Note - you can change delay in code >> save .c file >> rebuilt then play simulation in proteus

Check actual simulation in GIF format as shown below



If you found any difficulty or any suggestions please comment below or contact me on "pangfreelearner@gmail.com".

And also visit my YouTube channel for "Free online courses with Free certificate" on below link.

Free online courses with Free Certificate

Join Facebook group for Free online courses with Free certificate

Join Facebook group


Thank you.

PANG.




Wednesday, January 20, 2021

Password protection system prototype using 8051, Keypad, Display and DC Motor with Keil c51 and Proteus simulator

   

Free online courses with Free Certificate

Keil c51:

DevC++ compiler(or IDE)

Download link: Click here

step-1: right click on "Keil uvision" and click on "run as administrator"


step-2: now go to project >> new project >> "project_name.uvproj"



step-3: select "at89c51" as shown below



step-3: now file >> new file



step-4: click on save as then save with "file_name.c" i.e. with ".c" extension



step-5: now copy code given below and paste and save it, as shown below




step-6: to the left side of window right click on "Source group 1" and then click on "add existing file to source group 1"



step-7: now click on project  >>  build target to compile this code i.e. to check if any error in code



step-8: to generate "hex file" of this code right click on "target 1" tab to the left side of your window and then click on "options for target 'target 1'... " as shown below



step-9: now change frequency to "11.0592MHz" and tick to "use on-chip ROM" as shown below



step-10: now in same window options click on output >> tick to "create hex file" as shown below



step-11: click again on "build target" to create "hex file" as shown below





Embedded C code :


Code without comments (for simplicity)

#include<reg51.h>


sbit r1=P1^0;

sbit r2=P1^1;

sbit r3=P3^2;

sbit r4=P1^3;

sbit c1=P1^4;

sbit c2=P1^5;

sbit c3=P1^6;

//4x3 keypad declaration


sbit rs=P3^0;

sbit rw=P3^1;

sbit en=P3^2;

sfr lcd=0xa0;

//5x7 matrix lcd display


sbit motp=P3^3;

sbit motn=P3^4;

//door control motor


void lcdcmd(unsigned char);

void lcddat(unsigned char);

void lcddis(unsigned char *s,unsigned char r); //for passing strings on lcd, for pointer var and other for size

void delay();

void check(); //to check password


unsigned char pwd[10],x; //declaration to store password i.e. 10 chr size


void main()

{

lcdcmd(0x38); //select lcd

lcdcmd(0x01); //clear screen

lcdcmd(0x10); //cursor blinking

lcdcmd(0x0e); //shift cursor position

lcdcmd(0x80);

lcddis("PASSWORD PROTECTION",19);

lcdcmd(0xc0);

lcddis("SYSTEM",6);

lcdcmd(0x01);

lcddis("ENTER PASSWORD",14);

lcdcmd(0xc0); //to write pw on 2nd/next line


while(1)

{

r1=0;

if(c1==0)

{

pwd[x]='1';

delay();delay();delay();delay();delay();delay();delay();delay();

lcddat('*');

x=x+1;

}

if(c2==0)

{

pwd[x]='2';

delay();delay();delay();delay();delay();delay();delay();delay();

lcddat('*');

x=x+1;

}

if(c3==0)

{

pwd[x]='3';

delay();delay();delay();delay();delay();delay();delay();delay();

lcddat('*');

x=x+1;

}

r1=1; //row-1 scan complete

r2=0;

if(c1==0)

{

pwd[x]='4';

delay();delay();delay();delay();delay();delay();delay();delay();

lcddat('*');

x=x+1;

}

if(c2==0)

{

pwd[x]='5';

delay();delay();delay();delay();delay();delay();delay();delay();

lcddat('*');

x=x+1;

}

if(c3==0)

{

pwd[x]='6';

delay();delay();delay();delay();delay();delay();delay();delay();

lcddat('*');

x=x+1;

}

r2=1; //row-2 scan complete

r3=0;

if(c1==0)

{

pwd[x]='7';

delay();delay();delay();delay();delay();delay();delay();delay();

lcddat('*');

x=x+1;

}

if(c2==0)

{

pwd[x]='8';

delay();delay();delay();delay();delay();delay();delay();delay();

lcddat('*');

x=x+1;

}

if(c3==0)

{

pwd[x]='9';

delay();delay();delay();delay();delay();delay();delay();delay();

lcddat('*');

x=x+1;

}

r3=1; //row-3 scan complete

r4=0;

if(c1==0)

{

pwd[x]='*';

delay();delay();delay();delay();delay();delay();delay();delay();

lcddat('*');

x=x+1;

}

if(c2==0)

{

pwd[x]='0';

delay();delay();delay();delay();delay();delay();delay();delay();

lcddat('*');

x=x+1;

}

if(c3==0)

{

check();

delay();delay();delay();delay();delay();delay();delay();delay();

delay();

}

r4=1; //row-4 scan complete

}

}


void check()

{

if(pwd[0]=='7'&&pwd[1]=='2'&&pwd[2]=='0'&&pwd[3]=='8'&&pwd[4]=='5'&&pwd[5]=='9'&&pwd[6]=='9'&&pwd[7]=='1'&&pwd[8]=='0'&&pwd[9]=='4')

{

motp=1;

motn=0;

lcdcmd(0x01);

lcddis("PASSWORD MATCHED",16);

delay();

}

else

{

lcdcmd(0x01);

lcddis("PASSOWRD INCORRECT",18);

delay();

}

}


void lcdcmd(unsigned char val)

{

P2=val;

rs=0;

rw=0;

en=1;

delay();

en=0;

}


void lcddat(unsigned char dat)

{

P2=dat;

rs=1;

rw=0;

en=1;

delay();

en=0;

}


void lcddis(unsigned char *s, unsigned char r)

{

unsigned char w;

for(w=0;w<r;w++)

{

lcddat(s[w]);

delay();

}

}


void delay()

{

unsigned int i,j;

for(i=0;i<4000;i++);

for(j=0;j<100;j++);

}

Free online courses with Free Certificate

Free online courses with Free Certificate

Free online courses with Free Certificate


Proteus:

Download linkClick here !


step: right click on "Proteus 8 professional"(whichever version available) and "run as administrator"

step: now go to project >> new project >> "New Project.pdsprj"


step: click on "P" and open window for "pick devices" as shown below


step: now type "at89c51" and select microcontroller then press ok


step: now add other components as shown below:

1. Keypad :




2. DC motor:



3. 16x2 LCD display :



step: now final circuit as shown below



step: now double click on microcontroller symbol then "edit component" window will open. then click on "folder symbol" to select ".hex" file and change frequency to 11.0592MHz as shown below

Note- make sure you know path of ".hex" file generated through Keil c51 as shown below

e.g. - ..\..\..\Keil_v5\C51\Examples\my project\Objects\7segment 8051.hex


step: click on "play button" and check output as shown below






Note - you can change delay in code >> save .c file >> rebuilt then play simulation in proteus

Check actual simulation in GIF format as shown below






If you found any difficulty or any suggestions please comment below or contact me on "pangfreelearner@gmail.com".

And also visit my YouTube channel for "Free online courses with Free certificate" on below link.

Free online courses with Free Certificate

Join Facebook group for Free online courses with Free certificate

Join Facebook group


Thank you.

PANG.