0% found this document useful (0 votes)
23 views7 pages

Exp9 WORD

Uploaded by

parthsaini818
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views7 pages

Exp9 WORD

Uploaded by

parthsaini818
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

/

*************************************************************************
*****
* FileName: Main.c
* Processor: AT89C52
* Complier: Keil
* Keil IDE
* Company: Nvis Technologies Pvt. Ltd.
*
*************************************************************************
*********************
* File Description: (MC01) - Keypad Interface with Nvis 5001A
*
* Steps for Operation
* Step 1:-
* Swith ON Nvis 5001A
* Selsct PC mode and put toggle switch in PC mode
* Burn Program "Keypad Interface.hex" file in 8051/52
Microcontroller using Nvis 5001A
*
* Step 2:-
* Connections :
* Connect 20 Pin FRC cable in following manner:
* Nvis 5001A Port P1 with "Keypad" Connector of MC01.
*
* Step 3:-
* Put toggle switch in Run
* Press Run button in software
* OutPut:
* Initially On LCD "Key Pressed" is showing. But whenever you
will press any key
* the same character will display on LCD second row.
*
*************************************************************************
********************/
#include <REGx52.H>
#include <type.h>

#define LCDPORT P0
#define RS P0_2
#define E P0_3
bit status=0;
void LCD_Cmd(unsigned char a);
/
*************************************************************************
*****/
/* Global function and Variable Declearation
*************************************************************************
*****/
unsigned char Scan_Keypad(void);
unsigned char KeyVal;
unsigned char KeyPad[4][4]={'7','5','3','D',
'8','2','6','C',
'1','0','9','A',
'4','C','B','A'};
/
*************************************************************************
*****/
/* Delay routine*
*************************************************************************
*****/
void delay(unsigned int rTime) //Function to provide time delay.
{
unsigned int i,j;

for(i=0;i<rTime;i++)
for(j=0;j<775;j++);
}
/********** Initialize LCD Routine *****************/
void lcd_init_write(unsigned char a)
{
delay(1);
RS=0;
LCDPORT=a;
E=1;
delay(15);
E=0;
}
/
*************************************************************************
*****/
/* LCD Init function
*************************************************************************
*****/
void LCD_Init(void)
{
status = 0;
delay(3);
lcd_init_write(0x30);
delay(3);
lcd_init_write(0x30);
delay(3);
lcd_init_write(0x30);
delay(3);
lcd_init_write(0x20);
delay(3);
LCD_Cmd(0x28);
delay(3);
LCD_Cmd(0x04);
delay(3);
LCD_Cmd(0x85);
delay(3);
LCD_Cmd(0x06);
delay(3);
LCD_Cmd(0x0C);
delay(3);
LCD_Cmd(1);
delay(3);
}
/
*************************************************************************
*****/
/* LCD Command function
*************************************************************************
*****/
void LCD_Cmd(unsigned char a)
{
unsigned char temp;

if(status)
{
status=0;
goto a;
}
RS=0;
a:
temp=a;
temp&=0xF0;
LCDPORT&=0x0F;
LCDPORT|=temp;
E=1;
delay(5);
E=0;
temp=a<<4;
temp&=0xF0;
LCDPORT&=0x0F;
LCDPORT|=temp;
E=1;
delay(5);
E=0;
}
/
*************************************************************************
*****/
/* LCD Data write function
*************************************************************************
*****/
void LCD_Data(unsigned char a)
{
status = 1;
RS = 1;
delay(2);
LCD_Cmd(a);
}

/
*************************************************************************
*****/
/* Write Srting to LCD
*************************************************************************
*****/
void LCD_Disp(unsigned char Loc,unsigned char *String)
{
LCD_Cmd(Loc);
delay(5);
while(*String)
{
LCD_Data(*String++); /* write data to LCD */
}
}

/
*************************************************************************
*****/
/* main function
*************************************************************************
*****/
void main (void)
{
LCD_Init(); /* Initialize
LCD */
LCD_Cmd(0x01); /* Clear Display
*/
LCD_Disp(0x80," Nvis "); /* Display Company Name
*/
LCD_Disp(0xC0," Technologies ");
delay(1000);
LCD_Cmd(0x01);
LCD_Disp(0x80," Key Pressed ");
while(1)
{
Scan_Keypad(); /* Keypad Sence
*/
LCD_Cmd(0xC8); /* if key is pressed select LCD
Location */
LCD_Data(KeyVal); /* Display the Key value
*/
}
}
/
*************************************************************************
*****/
/* Keypad subroutine
*************************************************************************
*****/
unsigned char Scan_Keypad(void)
{
P1 = 0xFF; /* All rows & columns are high */
while(1)
{

// Row0 Scan
ROW0 = 0;
if(!COL0)
{
delay(250);
if(!COL0)
KeyVal=KeyPad[0][0]; //1
return KeyVal;
}
if(!COL1)
{
delay(250);
if(!COL1)
KeyVal=KeyPad[0][1]; //2
return KeyVal;
}
if(!COL2)
{
delay(250);
if(!COL2)
KeyVal=KeyPad[0][2]; //3
return KeyVal;
}
if(!COL3)
{
delay(250);
if(!COL3)
KeyVal=KeyPad[0][3]; //F
return KeyVal;
}
ROW0 = 1;
// Row1 Scan
ROW1 = 0;
if(!COL0)
{
delay(250);
if(!COL0)
KeyVal=KeyPad[1][0]; //4
return KeyVal;
}
if(!COL1)
{
delay(250);
if(!COL1)
KeyVal=KeyPad[1][1]; //5
return KeyVal;
}
if(!COL2)
{
delay(250);
if(!COL2)
KeyVal=KeyPad[1][2]; //6
return KeyVal;
}
if(!COL3)
{
delay(250);
if(!COL3)
KeyVal=KeyPad[1][3]; //E
return KeyVal;
}
ROW1 = 1;
// Row2 Scan
ROW2 = 0;
if(!COL0)
{
delay(250);
if(!COL0)
KeyVal=KeyPad[2][0]; //7
return KeyVal;
}
if(!COL1)
{
delay(250);
if(!COL1)
KeyVal=KeyPad[2][1]; //8
return KeyVal;
}
if(!COL2)
{
delay(250);
if(!COL2)
KeyVal=KeyPad[2][2]; //9
return KeyVal;
}
if(!COL3)
{
delay(250);
if(!COL3)
KeyVal=KeyPad[2][3]; //D
return KeyVal;
}
ROW2 = 1;
// Row3 Scan
ROW3 = 0;
if(!COL0)
{
delay(250);
if(!COL0)
KeyVal=KeyPad[3][0]; //0
return KeyVal;
}
if(!COL1)
{
delay(250);
if(!COL1)
KeyVal=KeyPad[3][1]; //A
return KeyVal;
}
if(!COL2)
{
delay(250);
if(!COL2)
KeyVal=KeyPad[3][2]; //B
return KeyVal;
}
if(!COL3)
{
delay(250);
if(!COL3)
KeyVal=KeyPad[3][3]; //C
return KeyVal;
}
ROW3 = 1;
}
return KeyVal;
}

You might also like