Pages

Subscribe:
Showing posts with label embedded systems. Show all posts
Showing posts with label embedded systems. Show all posts

Saturday, 23 July 2011

Password(code) Based Digital Locking System Using Microcontroller 89C52/89S52

If you are a beginner in making micro controller projects then this mini project
might just work for you. It's very simple and anybody can make it. The aim
of the project is quite predictable from the title itself-you enter a wrong password
the application wont work(in this case led is used as the application) and on correct
entering of the password, the application as in this case "led" will glow.In this Digital locking system project you will learn more about interfacing keypad and 16x2 LCD to your micro controller along with the code.




components required

For this project you will need the following components:
  • 1 microcontroller 89C52(89S52 will also do)
  • 1 potentiometer-10k
  • 2 ceramic capacitors-22pF
  • 1 switch(button for reset purpose)
  • 1 electrolytic capacitor-10uF,25V
  • 1 crystal oscillator-11.0592MHz
  • 16x2 LCD display
  • 1 resistor-10k
  • 1keypad(here, i have used a calculator keypad.In proteus you can find it by typing keypad-smallcalc)
  • 1 led
  • 1 330 ohm resistor

Schematic diagram



Since this project has been made in proteus software you must have a prior knowledge of it. If you are unaware of the software here is a tutorial which i recommended in one of my previous articles.



The connection of the circuit is explained below:

  • Port 1 of the microcontroller is used as the output port
  • Port 2 of the microcontroller is used as the output port
  • Port 3 of the microcontroller is used as the input port.
  • The LCD is connected to port 2 since output is displayed on LCD
  • The led is connected to port 1 which is our application in this project
  • The keypad is connected to port 3
  • Other components like the crystal and switch are connected for the working of the microcontroller ( minimum circuitry required for proper working of the microcontroller).

working:

As soon as the power supply is provided to the microcontroller "password based" will be shown on the screen.This will remain for a second and after that "enter password" will be displayed as shown below.



The "ENTER PASSWORD " statement will remain for a second and then it will vanish.At this point you will have to enter password which will be shown in terms asterisk " **** ". 





The coding of the micro-controller is done such that only four numbers can be used to enter password. If you want to increase the length of the password you can do that by adding loops in the coding which will be dealt later. Here, in this project the password is set as 1234. when this password is entered the LCD will display "correct password" as shown below and the LED will turn on which is connected at port 1. you can set your own password by changing the password in the code.

If you want to set your password using the operators like " + ", " -" etc you can do it by setting the password in the code as follows:




  • for " ON/C " =16
  • for " + " =10
  • for " - " =14
  • for " = " =15
  • for " x " =11
  • for " ÷ " =13

programming:

The programming of the microcontroller is done using keil compiler.The codings for this project is explained below:



#include "REGX51.H"
#include "delay.h" /*the header file of delay is added*/
#include "lcd.h" /*the header file of LCD is added*/
#include "keypad.h" /*the header file of keypad is added*/
#define relay P1_7;
void main()
{
int first_key,second_key,third_key,fourth_key;
P1=0X00; /*port 1 is defined as the output port*/
P2=0x00; /*port 2 is defined as the output port*/
P3=0xff; /*port 3 is defined as the input port*/
LCD_INIT();/* the LCD display is initialized */
LCD_STRING("PASSWORD BASED");/*displays PASSWORD BASED on the lcd*/
delay_sec(1); /* provides a delay of 1 second */
LCD_CMD(PUTLINE2);
LCD_STRING("LOCKING SYSTEM");
LCD_CLEAR(); /*clears the LCD display*/
LCD_STRING("ENTER PASSWORD:");
delay_sec(1);
LCD_CLEAR();
while(key_get()==NOKEY);
first_key=key;
LCD_STRING("*"); /*when any key is pressed display it as " * " */
while(key_get()==NOKEY);
second_key=key;
LCD_STRING("*");
while(key_get()==NOKEY);
third_key=key;
LCD_STRING("*");
while(key_get()==NOKEY);
fourth_key=key;
LCD_STRING("*"); /* by adding another while loop you can further increase the length of your password */
while(1)
{
if((first_key==1)&&(second_key==2)&&(third_key==3)&&(fourth_key==4))/*here, the password set is 1234. you can change the password over here.if you have increased your password length see that you also make changes in the If loop over here i.e by adding further &&fifth_key=....&& sixth_.. and so on */
{
LCD_CLEAR();
LCD_STRING("Correct Password");
P1_2=1; /* if correct password is entered make P1_2 high which will turn on the led */
delay_sec(2);
}
else
{
LCD_CLEAR();
LCD_STRING("Incorrect Password");
delay_sec(2);
}
} }














































download files

You can download all the hex file, schematic diagram and codes over here:


schematic diagram


codes


the .hex file

Instead of LED you can use any other application like motor which works using a relay or a buzzer and you can go on with many other application. If you have any questions with regards to the project or would like to improve this project further please feel free to comment.

Friday, 22 July 2011

Chasing LED's Using Microcontroller 89C52/89S52



This mini-project is especially meant for a newbie in Embedded Systems. This project will give you a clear idea of how to think and implement your code in practical life. In this article, we will cover the programming details for LED blinking and how you can code your microcontroller to show different patterns of LED blinking. After learning the logic for LED blinking you can code any microcontroller with the same logic.


Components

  • 1 microcontroller 89C52(89S52 will also do)
  • 1 potentiometer-10k
  • 2 ceramic capacitors-22pF
  • 1 switch(button for reset purpose)
  • 1 electrolytic capacitor-10uF,25V
  • 1 crystal oscillator-11.0592MHz
  • 1 resistor-10k
  • 8 LED's
  • 8 330 ohm resistor
  • 2 switches (SPST) 

 Schematic Diagram


 










Softwares Used: 

This project is made with the help of Proteus software. If you are unaware of the software you can learn the basics by watching the video tutorial that I recommended in one of my articles.


The connection of the circuit is explained below:

  • Port 1 of the microcontroller is used as the input Port
  • Port 2 of the microcontroller is used as the output Port
  • The LED's are connected to the output of Port 2
  • Two switches are connected to the input of Port 1
    one switch is connected to the 5th pin of the Port 1 whereas the other switch is connected to the 8th pin of the Port 1
  • Other components like the crystal and switch are used for the working of the microcontroller


Working:

The programming is done using Keil compiler. The circuit is configured for two modes namely (1) The LED Blinking mode and the (2) Chasing LEd mode.when the switch connected to the 8th pin of the Port 1 is closed , the microcontroller works in the Blinking mode wherein all the LED's glow simultaneously for one second and remain switched off for the other one second and this process continues as long as the microcontroller is receiving the power supply .The blinking LED's are shown below:


 

When the switch connected to the 5th pin of the micro controller is closed and the switch connected to the 8th pin is open, the micro controller works in the Chasing LED mode i.e. the LED's glow one after the another for a second and looks something like this:


Programming:

The detail explanation of the coding is done below



#include <REGX52.H>
# include"delay.h" /* header file of the delay is added */
void main()
{ P1=0xFF; /*Port 1 is defined as input*/
P2=0x00; /* Port 2 is defined as output*/
while(1)
{/* code for the chasing LED's */
if(P1_4==0)/* if switch connected to P1_4 is closed*/
{ P2=0X01; /*glow the LED connected to P2_0 for 1 sec*/
delay_sec(1);
P2=0x02; /*glow the LED connected to P2_1 for 1 sec*/
delay_sec(1);
P2=0x04;
delay_sec(1);
P2=0x08;
delay_sec(1);
P2=0x10;
delay_sec(1);
P2=0x20;
delay_sec(1);
P2=0x40;
delay_sec(1);
P2=0x80;
delay_sec(1);/* code for chasing LED's complete*/
}/* codes for chasing LED's */
if(P1_7==0) /* if switch connected to P1_7 is closed*/
{ P2=0xFF; /*glow all the LED's connected to port P2 for 1 sec*/
delay_sec(1);
P2=0x00; /*switch off all the LED's connected to port P2 for 1 sec*/
delay_sec(1);
}
}
}












































Some things that you can try      

You can play around with the code to get your own LED pattern. Try using P2=0xAA, then provide a delay of 1 second and put the value of P2 as P2=0X55 and again provide a delay of 1 second. Similarly you can try other patterns and have fun. This way you will be able to develop your skill in programming.

Download files     

Please comment if you further want to improve the project or if you have doubts in the above code.