Toll-Free Customer Support 24/7

8051 Development Board

/*
 * Project name:
    8051 Development Board
 * Copyright
     (c) Researchdesignlab.com
 * Description:
    
 * Test configuration:
     MCU:             AT89S52
     Dev.Board:       8051
     Oscillator:      11.0592 MHz
     Software:        Keil uVision3

*/
#include<reg51.h>

#define KeyPort P1
#define LCD_PORT P2

sbit rs=P3^5;
sbit en=P3^7;
sbit D7=P2^7;
sbit rw=P3^6; 

void busy();
void CMD_WRT(unsigned char);
void LCD_WRT(unsigned char *);
void DATA_WRT(unsigned char);
void DELAY();
void delay12(unsigned int time);
unsigned char check();

void main()
{
 	unsigned char CMD[]={0x38,0x01,0x0f,0x06,0x80},TEMP1,i,j;
 	unsigned char pass1[15];

 	for(i=0;i<5;i++)
   {
    TEMP1=CMD[i];
	CMD_WRT(TEMP1);
   }
	DELAY();
	CMD_WRT(0X01);
 	CMD_WRT(0X80);
	LCD_WRT("4X4 KEYPAD");
	DELAY();

	while(1)
	{
	CMD_WRT(0X01);
	CMD_WRT(0X80);
	LCD_WRT("Enter the Key");
	DELAY();
	CMD_WRT(0XC0);
	for(j=0;j<15;j++)
	{
	pass1[j]=check();
	DATA_WRT(pass1[j]);
	DELAY();
	}
  }
}
	void DELAY()
  	{
	unsigned int X=6000000;
	while(X--);
	}
	void busy()
	{
	D7=1;
	rs=0;
	rw=1;
	while(D7!=0)
	{
		en=0;
		en=1;
	}
	} 



	void CMD_WRT(unsigned char val)
	{
	busy();
	LCD_PORT=val;
	rs=0;
	rw=0;
	en=1;
	en=0;
	}

	void LCD_WRT(unsigned char *string)
	{
	while(*string)
	DATA_WRT(*string++);
	}
	void DATA_WRT(unsigned char ch)
	{
	busy();
	LCD_PORT = ch;
	rs=1;
	rw=0;
	en=1;
	en=0;
	}

	unsigned char check()
	{
	unsigned char colloc=0,rowloc=0, colloc1,rowloc1;
	unsigned char keypad[4][4]={'F','E','D','C',
                            'B','A','9','8',
                            '7','6','5','4',
                            '3','2','1','0'};



  {
   
    do
    {
     KeyPort = 0X0f;
     do
      {
        colloc1 = KeyPort;
         colloc1 &= 0x0F;
       }while(colloc1 != 0x0F);

       delay12(20);

    do
    {
       colloc1=KeyPort;
        colloc1 &= 0x0F;
        }while(colloc1==0x0F);


         delay12(20);

         KeyPort = 0x0f;
          colloc1=KeyPort;
           colloc1 &= 0x0F;
           if(colloc1==0x0E)
            {
               colloc=0;
             }
            else if(colloc1==0x0D)
            {
             colloc=1;
             }
             else if(colloc1==0x0B)
				{
				colloc=2;
				}
				else if(colloc1==0x07)
				{
				colloc=3;
				}
				KeyPort = 0xf0;
				rowloc1 = KeyPort;
				rowloc1 &= 0xf0;
				if(rowloc1 == 0xE0)
				{
				rowloc=0;
				}

				else if(rowloc1==0xD0)
				{
				rowloc=1;
				}
				else if(rowloc1==0xB0)
				{
				rowloc=2;
				}
				else if(rowloc1==0x70)
				{
				rowloc=3;
				}
			//	CMD_WRT(0XC0);
			//	DATA_WRT(keypad[rowloc][colloc]);
			
				return(keypad[rowloc][colloc]);
				
					}while(1);
					}
					}

	void delay12(unsigned int time)
	{
	unsigned int i;
	for(i=0;i<time;i++);
	for(i=0;i<10000;i++);
	}

Back to top