8051 Report
8051 Report
Circuit components
AT89s52 microcontroller
LCD display
4*3 keypad
EEPROM AT24c04
7805 voltage regulator
8051 programmer
LEDs,resistors,connection wires
AT89S52 Microcontroller
The AT89S52 is an 8 bit microcontroller and belongs to Atmels 8051
family, it is a low-power, high-performance CMOS 8-bit microcontroller
with 8K bytes of in-system programmable Flash memory and is
compatible with the industrystandard 80C51 instruction set and pinout.The on chip flash memory
allows the chip to be programmed by an in system programmer
LCD display
LCD (Liquid Crystal Display) screen is an electronic display module and
find a wide range of applications. A 16x2 LCD display is very basic
module and is very commonly used in various devices and circuits. These
modules are preferred over seven segments and other multi
segment LEDs. The reasons being: LCDs are economical; easily
programmable; have no limitation of displaying special & even custom
characters (unlike in seven segments), animations and so on.
A 16x2 LCD means it can display 16 characters per line and there are 2
such lines. In this LCD each character is displayed in 5x7 pixel matrix
4*3 Keypad
Keypads are widely used input devices being used in various electronics
and embedded projects. They are used to take inputs in the form
of numbers and alphabets, and feed the same into system for further
processing. To avoid using up too many pins of the microcontroller, the
keyboard is connected using an interfacing technique that connects the
keys in a 4*3 matrix, shorting all the rows and all columns together
EEPROM AT24C04
AT24C04 is a two wire 4Kbits serial EEPROM by Atmel. The memory is
organized in 256 words of single byte each arranged in 32 pages of 16
bytes each. AT24C04 is two-wire serially programmable i.e., for
programming, the data and control signals are provided serially along
with clock signals from the other wire. The read-write operations are
accomplished by sending a set of control signals including the address
and/or data bits. The control signals must be accompanied with proper
clock signals.
8051 programmer
Block schematic
Indicator LEDS
P1_0-P1_6
AT89S52
AT24C04
P0
P2_6,P2_7
P2_0-P2_5
Program Code
// Lcd module connections
sbit LCD_RS at P2_0_bit;
sbit LCD_EN at P2_1_bit;
sbit LCD_D4 at P2_2_bit;
sbit LCD_D5 at P2_3_bit;
sbit LCD_D6 at P2_4_bit;
sbit LCD_D7 at P2_5_bit;
sbit sda at P2_6_bit;
sbit scl at P2_7_bit;
bit ack;
char auth=0,authadmn=0;
TR1_bit=0;
TH1=0xFF;
TL1=0xD1;
//P0=0xFF;
c++;
if(c<=40)
servo=1;
else if(c<=401)
servo=0;
else if(c>=402)
c=0;
EA_bit=1;
TR1_bit=1;
TR0_bit=0;
TH0=0xF0;
TL0=0x00;
//P0=~P0;
c++;
//if(c%2==0)
P0=~P0;
EA_bit=1;
TR0_bit=1;
void ackn()
{
scl=1;
asm nop;
asm nop;
scl=0;
}
void start()
{
sda=1;
scl=1;
asm nop;
asm nop;
sda=0;
asm nop;
scl=0;
}
void stop()
{
sda=0;
scl=1;
asm nop;
asm nop;
sda=1;
asm nop;
scl=0;
}
unsigned int i;
for(i=0;i<8;i++)
{
sda=send/128;
send=send<<1;
scl=1;
asm nop;
asm nop;
scl=0;
asm nop;
ack=sda;
sda=0;
unsigned int i;
sda=1;
read=0;
for(i=0;i<8;i++)
{
read=read<<1;
scl=1;
asm nop;
asm nop;
if(sda==1)
read++;
scl=0;
sda=0;
return read;
void save_pwd()
{
start();
send_byte(0xA0);
ackn();
send_byte(0x00);//word address
ackn();
send_byte(np[0]); //data
ackn();
send_byte(np[1]);
ackn();
send_byte(np[2]);
ackn();
send_byte(np[3]);
ackn();
send_byte(np[4]);
ackn();
send_byte(np[5]);
ackn();
send_byte(np[6]);
ackn();
send_byte(np[7]);
ackn();
stop();
if(ack==0)
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,3,"pwd svd");
// Lcd_Out(1,3,"71325602");
Delay_ms(500);
ackn();
void read_pwd(){
start();
send_byte(0xA0);
ackn();
send_byte(0x00);
ackn();
start();
send_byte(0xA1);
ackn();
d[0]=read_byte();
ackn();
d[1]=read_byte();
ackn();
d[2]=read_byte();
ackn();
d[3]=read_byte();
ackn();
d[4]=read_byte();
ackn();
d[5]=read_byte();
ackn();
d[6]=read_byte();
ackn();
d[7]=read_byte();
ackn();
stop();
Lcd_Cmd(_LCD_CLEAR);
// Lcd_Out(1,3,d);
//Delay_ms(5000);
}
char Read_Keypad()
{
C1=1;
C2=1;
C3=1;
Rw1=0;
Rw2=1;
Rw3=1;
Rw4=1;
if(C1==0){Delay_ms(100);while(C1==0);return '1';}
if(C2==0){Delay_ms(100);while(C2==0);return '2';}
if(C3==0){Delay_ms(100);while(C3==0);return '3';}
Rw1=1;
Rw2=0;
Rw3=1;
Rw4=1;
if(C1==0){Delay_ms(100);while(C1==0);return '4';}
if(C2==0){Delay_ms(100);while(C2==0);return '5';}
if(C3==0){Delay_ms(100);while(C3==0);return '6';}
Rw1=1;
Rw2=1;
Rw3=0;
Rw4=1;
if(C1==0){Delay_ms(100);while(C1==0);return '7';}
if(C2==0){Delay_ms(100);while(C2==0);return '8';}
if(C3==0){Delay_ms(100);while(C3==0);return '9';}
Rw1=1;
Rw2=1;
Rw3=1;
Rw4=0;
if(C1==0){Delay_ms(100);while(C1==0);return '*';}
if(C2==0){Delay_ms(100);while(C2==0);return '0';}
if(C3==0){Delay_ms(100);while(C3==0);return '#';}
return 0;
iter=0;
while(iter<8){
while(!(pkey=Read_Keypad()));
if(iter==0)
Lcd_cmd(_LCD_CLEAR);
Lcd_chr(1,iter+1,'*');
np[iter]=pkey;
iter++;
}
Delay_ms(1000);
save_pwd();
Lcd_cmd(_LCD_CLEAR);
}
Lcd_Out(1,1,"Password reset");
char adminmode()
{
Lcd_cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Enter password");
return 1;
iter=0;
while(iter<8){
while(!(pkey=Read_Keypad()));
if(iter==0)
{
Lcd_cmd(_LCD_CLEAR);
Lcd_chr(1,iter+1,'*');
cdata[iter]=pkey;
iter++;
}
iter=0;
while(iter<=7)
{
if(d[iter]!=cdata[iter])
{
Lcd_cmd(_LCD_CLEAR);
Lcd_Out(1,1,"incorrect");
rled=0;
gled=1;
Delay_ms(1000);
tled=1;
break;
if(iter==7)
{
Lcd_cmd(_LCD_CLEAR);
rled=1;
gled=0;
Delay_ms(100);
tled=0;
break;
iter++;
rled=0;
gled=1;
do
{
tled=0;
read_pwd();
Delay_ms(1000);
Delay_ms(1000);
tled=1;
Lcd_Init();
// Initialize Lcd
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,6,"Digital");
Lcd_Out(2,5,"Door Lock");
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Enter password");
// Clear display
// Cursor off
getpwd();
while(!(pkey=Read_Keypad()));
count++;
}while(count<4);
//Lcd_Cmd(_LCD_CLEAR);
while(1)
{rled=0;
gled=0;
Delay_ms(1000);
rled=1;gled=1;
Delay_ms(1000);
}
References
www.mikroe.com/downloads/get/30/mikroc_pic_pro_manual_v101.p
df
http://www.atmel.com/devices/at89s52.aspx
www.atmel.com/Images/doc0180.pdf
http://www.engineersgarage.com/microcontroller/8051projects/elec
tronic-code-lock-with-password-using-at89c51-circuit