Question

In: Electrical Engineering

Write a code of digital alarm clock 8051 microcontroller using pin AT89S52

Write a code of digital alarm clock 8051 microcontroller using pin AT89S52

Solutions

Expert Solution

#include<reg51.h>
#include<string.h>
#define lcdport P1

sbit col1=P0^0;
sbit col2=P0^1;
sbit col3=P0^2;
sbit col4=P0^3;
sbit row1=P0^4;
sbit row2=P0^5;
sbit row3=P0^6;
sbit row4=P0^7;

sbit rs=P1^0;
sbit en=P1^2;
sbit buzzer=P2^6;
void main()
{
    buzzer=1;
    lcd_init();
    lcdstring("Electronic Code");
    lcdcmd(0xc0);
    lcdstring("  Lock System  ");
    delay(400);
    lcdcmd(1); 
    lcdstring("Circuit Digest");
    delay(400);
    while(1)
    {
            i=0;
            keypad();
            if(strncmp(pass,"4201",4)==0)
void accept()
{
     lcdcmd(1);
     lcdstring("Welcome");
     lcdcmd(192);
     lcdstring("Password Accept");
     delay(200);
}
void wrong()
{
    buzzer=0;
    lcdcmd(1);
     lcdstring("Wrong Passkey");
    lcdcmd(192);
    lcdstring("PLZ Try Again");
    delay(200);
    buzzer=1;
}

Complete code:

#include<reg51.h>
#include<string.h>
#define lcdport P1

sbit col1=P0^0;
sbit col2=P0^1;
sbit col3=P0^2;
sbit col4=P0^3;
sbit row1=P0^4;
sbit row2=P0^5;
sbit row3=P0^6;
sbit row4=P0^7;

sbit rs=P1^0;
sbit en=P1^2;
sbit buzzer=P2^6;

char pass[4],i=0;

void delay(int itime)
{
   int i,j;
   for(i=0;i<itime;i++)
   for(j=0;j<1275;j++);
}

void daten()
{
   rs=1;
   en=1;
   delay(5);
   en=0;
}

void lcddata(unsigned char ch)
{
   lcdport=ch & 0xf0;
   daten();
   lcdport=(ch<<4) & 0xf0;
   daten();
}

void cmden(void)
{
   rs=0;
   en=1;
   delay(5);
   en=0;
}

void lcdcmd(unsigned char ch)
{
   lcdport=ch & 0xf0;
   cmden();
   lcdport=(ch<<4) & 0xf0;
   cmden();
}

void lcdstring(char *str)
{
   while(*str)
   {
       lcddata(*str);
       str++;
   }
}

void lcd_init(void)
{
   lcdcmd(0x02);
   lcdcmd(0x28);
   lcdcmd(0x0e);
   lcdcmd(0x01);
}

void keypad()
{
   int cursor=192,flag=0;
   lcdcmd(1);
   lcdstring("Enter Ur Passkey");
   lcdcmd(0xc0);
   i=0;
   while(i<4)
   {
   flag=cursor;
   col1=0;
   col2=col3=col4=1;
   if(!row1)
   {
       lcddata('1');
       pass[i++]='1';
       cursor++;
       while(!row1);
    }
     
   else if(!row2)
   {
       lcddata('4');
       pass[i++]='4';
       cursor++;
       while(!row2);
    }
     
   else if(!row3)
   {
       lcddata('7');
       pass[i++]='7';
       cursor++;
       while(!row3);
    }
     
   else if(!row4)
   {
       lcddata('*');
       pass[i++]='*';
       cursor++;
       while(!row4);
    }
     
   col2=0;
   col1=col3=col4=1;
   if(!row1)
   {
       lcddata('2');
       pass[i++]='2';
       cursor++;
       while(!row1);
    }
     
   else if(!row2)
   {
       lcddata('5');
       pass[i++]='5';
       cursor++;
       while(!row2);
    }
     
   else if(!row3)
   {
       lcddata('8');
       pass[i++]='8';
       cursor++;
       while(!row3);
    }
     
   else if(!row4)
   {
       lcddata('0');
       pass[i++]='0';
       cursor++;
       while(!row4);
    }
     
   col3=0;
   col1=col2=col4=1;
   if(!row1)
   {
       lcddata('3');
       pass[i++]='3';
       cursor++;
       while(!row1);
    }
     
   else if(!row2)
   {
       lcddata('6');
       pass[i++]='6';
       cursor++;
       while(!row2);
    }
     
   else if(!row3)
   {
       lcddata('9');
       pass[i++]='9';
       cursor++;
       while(!row3);
    }
     
   else if(!row4)
   {
       lcddata('#');
       pass[i++]='#';
       cursor++;
       while(!row4);
    }
     
   col4=0;
   col1=col3=col2=1;
   if(!row1)
   {
       lcddata('A');
       pass[i++]='A';
       cursor++;
       while(!row1);
    }
     
   else if(!row2)
   {
       lcddata('B');
       pass[i++]='B';
       cursor++;
       while(!row2);
    }
     
   else if(!row3)
   {
       lcddata('C');
       pass[i++]='C';
       cursor++;
       while(!row3);
    }
     
   else if(!row4)
   {
       lcddata('D');
       pass[i++]='D';
       cursor++;
       while(!row4);
    }
   if(i>0)
   {
      if(flag!=cursor)
      delay(100);
      lcdcmd(cursor-1);
      lcddata('*');
   }
}      
}

void accept()
{
   lcdcmd(1);
   lcdstring("Welcome");
   lcdcmd(192);
   lcdstring("Password Accept");
   delay(200);
}

void wrong()
{
   buzzer=0;
   lcdcmd(1);
    lcdstring("Wrong Passkey");
   lcdcmd(192);
   lcdstring("PLZ Try Again");
   delay(200);
   buzzer=1;
}

void main()
{
   buzzer=1;
   lcd_init();
   lcdstring("Electronic Code");
   lcdcmd(0xc0);
   lcdstring(" Lock System ");
   delay(400);
   lcdcmd(1);
   lcdstring("Circuit Digest");
   delay(400);
   while(1)
   {
           i=0;
           keypad();
           if(strncmp(pass,"4201",4)==0)
           {
           accept();
           lcdcmd(1);
           lcdstring("Access Granted ");
           delay(300);
           }
      
       else
       {
       lcdcmd(1);
       lcdstring("Access Denied");
       wrong();
       delay(300);
       }
   }
}


Related Solutions

create a digital alarm clock using multisim software
create a digital alarm clock using multisim software
Write a verilog code for digital clock and display it’s seven segment using fpga?
Write a verilog code for digital clock and display it’s seven segment using fpga?
Write an assembly language program for 8051 microcontroller to find the sum of the following series,...
Write an assembly language program for 8051 microcontroller to find the sum of the following series, 1, -2, +3, -4, +5, -6,..., up to 100 terms. Store lower byte in R0 and higher byte in R1.
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code that transmits a single character and lights the red LED upon receiving that character. The board will "talk" to itself. The green LED should turn on whenever a message is sent and the LCD will display the message being received.
Describe the types and differences in the assembly instructions of 8051 microcontroller
Describe the types and differences in the assembly instructions of 8051 microcontroller
Draw the layout of the PSW register of the 8051 Microcontroller and explain its flags with examples.
Draw the layout of the PSW register of the 8051 Microcontroller and explain its flags with examples.
write a assembly language program to convert GRAY to BCD code in 8051
write a assembly language program to convert GRAY to BCD code in 8051
Write a Pseudo Code to send an Array of 20 elements from 8051 to the computer...
Write a Pseudo Code to send an Array of 20 elements from 8051 to the computer via serial port at maximum baud rate possible with XTAL=11.0592MHz.
design a stepper motor in 8051 microcontroller in which stepper motor moves clockwise for some time...
design a stepper motor in 8051 microcontroller in which stepper motor moves clockwise for some time and stops , then anticlockwise for some times and motor stops. (Code in assembly language needed)
Write the C code required to configure pin 0 on port B to be an input...
Write the C code required to configure pin 0 on port B to be an input with the pullup resistor enabled.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT