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.


No comments:

Post a Comment