SlideShare ist ein Scribd-Unternehmen logo
1 von 13
KEYPAD INTERFACING 8051
Keypad is a widely used input device with lots of application in our everyday life. From a simpletelephone to keyboard of
a computer, ATM, electronic lock, etc., keypad is used to take input from the user for further processing. In this article we
are interfacing keypad with the MCU AT89C51 and displaying the corresponding number on LCD. This module can be
further used in a number of systems to interfaced keypad with microcontroller and other processors to get desired
output. The program to interface keypad with controller is written in C language which is very easy to understand.
The above figure explains how a keypad can be interfaced with 8051.
DESCRIPTION:
Keypad is organized as a matrix of switches in rows and column. The article uses a 4X3 matrix keypad and a 16x2 LCD for
displaying the output of keypad. The circuit diagram shows the connection of keypad with the controller. PortP2 of the
microcontroller is used to send the data for displaying on the LCD. P1^1, P1^2, P1^3 pins of microcontroller is connected
to RS, RW, EN pins of LCD respectively. PortP0 is used to scan input fromthe keypad (refer circuit diagram for
connection).The concept of interfacing keypad with the MCU is simple. Every number is assigned two unique parameters,
i.e., row and column number (n(R, C) for example 6 (2, 3)). Hence every time a key is pressed the number is identified by
detecting the row and column number of the key pressed. Initially all the rows are set to zero by the controller and the
columns are scanned to check if any key is pressed. In caseno key is pressed the output of all the columns will be high.
Diagramatically it can be represented as follows:
Whenever a key is pressed the row and column corresponding to the key will get short, resulting in the output of the
corresponding column goes to go low (since we have made all the rows zero). This gives the column number of the
pressed key.
Once the column number is detected, the controller set’s all the rows to high. Now one by one each row is set to zero by
controller and the earlier detected column is checked if it becomes zero. The row corresponding to which the column gets
zero is the row number of the digit.
The above process is very fast and even if the switch is pressed for a very small duration of time the controller can detect
the key which is pressed. The controller displays the number corresponding to the row and column on the LCD.
CIRCUIT DIAGRAM:
The above circuit diagram explains how a keypad which is nothing but a seven segment display can be interfaced with
AT89S51 microcontroller.
COMPONENTS:
PRESET: A preset is a three legged electronic componentwhich can be made to Offer varying resistancein a circuit. The
resistanceis varied by adjusting the rotary control over it. The adjustmentcan be done by using a small screw driver or a
similar tool. The resistancedoes not vary linearly but rather varies in exponential or logarithmic manner. Such variable
resistors arecommonly used for adjusting sensitivity along a sensor.
The variable resistanceis obtained across the single terminal at frontand one of the two other terminals. The two legs at
back offer fixed resistancewhich is divided by the front leg. So, whenever only the back terminals are used, a presetacts
as a fixed resistor. Presets arefixed by their fixed value resistance.
AT89C51: AT89S51is an 8-bit microcontroller and belongs to Atmel’s 8051 family. AT89C51 has 4KBFlash programmable
and erasableread only memory (PROM) and128 bytes of RAM. Itcan be erased and programto a maximum of 1000 times.
In 40-pin AT89C51 thereare four ports designated as P0, P1, P2 and P3. All these ports are 8-pin bidirectional ports i.e.,
they can be used as both input ports and output ports. Except P0 which needs external pull-ups, restof the ports have
internal pull-ups. When 1’s are written to these port pins, they are pulled high by the internal pull-ups and can be used as
inputs. These ports are also bit addressableand so there can also be accessed individually.
Port0 and Port2 are also used to providelow byte and high byte addresses respectively, when connected to an external
memory. Port3 has multiplexed pins for special functions like serial communication, hardwareinterrupts, timer inputs,
and read/writeoperation from external memory. AT89C51 has an inbuilt UART for serialcommunication. Itcan be
programmed to operate at differentbaud rates. Including two timers and hardwareinterrupts it has a total of 6 interrupts.
Pin diagramfor AT89C51 can be given as follows:
PIN DIAGRAM:
PIN DESCRIPTION:
Pin
No
Function Name
1
8 bit input/output port (P1) pins
P1.0
2 P1.1
3 P1.2
4 P1.3
5 P1.4
6 P1.5
7 P1.6
8 P1.7
9 Reset pin; Active high Reset
10
Input (receiver) for serial
communication
RxD
8 bit
input/output
port (P3)
pins
P3.0
11
Output (transmitter) for serial
communication
TxD P3.1
12 External interrupt 1 Int0 P3.2
13 External interrupt 2 Int1 P3.3
14 Timer1 external input T0 P3.4
15 Timer2 external input T1 P3.5
16
Write to external data
memory
Write P3.6
17
Read from external data
memory
Read P3.7
18
Quartz crystal oscillator (up to 24 MHz)
Crystal 2
19 Crystal 1
20 Ground (0V) Ground
21
8 bit input/output port (P2) pins
/
High-order address bits when interfacing with external
memory
P2.0/ A8
22 P2.1/ A9
23 P2.2/ A10
24 P2.3/ A11
25 P2.4/ A12
26 P2.5/ A13
27 P2.6/ A14
28 P2.7/ A15
29
Program store enable; Read from external program
memory
PSEN
30
Address Latch Enable ALE
Program pulse input during Flash programming Prog
31
External Access Enable; Vcc for internal program
executions
EA
Programming enable voltage; 12V (during Flash
programming)
Vpp
32
8 bit input/output port (P0) pins
Low-order address bits when interfacing with external
memory
P0.7/ AD7
33 P0.6/ AD6
34 P0.5/ AD5
35 P0.4/ AD4
36 P0.3/ AD3
37 P0.2/ AD2
38 P0.1/ AD1
39 P0.0/ AD0
40 Supply voltage; 5V (up to 6.6V) Vcc
LCD:
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 and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of
displaying special.
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. This LCD has two registers, namely, Command and Data. The command register stores the command
instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing
its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD.
The data is the ASCII value of the character to be displayed on the LCD.
The above figure represents a LCD.
PIN DIAGRAM:
The above figure represents a LCD.
PIN DESCRIPTION:
Pin No Function Name
1 Ground (0V) Ground
2 Supply voltage; 5V (4.7V – 5.3V) Vcc
3 Contrastadjustment; through a variable resistor VEE
4 Selects command register when low; and data register when high Register Select
5 Low to write to the register; High to read from the register Read/write
6 Sends data to data pins when a high to low pulseis given Enable
7
8-bit data pins
DB0
8 DB1
9 DB2
10 DB3
11 DB4
12 DB5
13 DB6
14 DB7
15 Backlight VCC (5V) Led+
16 Backlight Ground (0V) Led-
Interface keypadwith8051 microcontroller inC language:
How to detect pressedkey value?
When key 1 is pressed then RowC wire is shorted with C1 wire inside the keypad. Similarly, when key 9 is pressed then
RowA wire is shorted with C3 wire. This behavior is true for all the keys. How to detect this behavior in the microcontroller
code?
We can detect pressed key value in the microcontroller using the “Scanning algorithm code”. This algorithm is written with
the name of ‘Read_Switches ()’ function in the code. The function is shown below
char READ_SWITCHES(void)
{
RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row A
RowA = 0;
if (C1 == 0) { delay(10000); while(C1==0); return ’7′; }
if (C2 == 0) { delay(10000); while(C2==0); return ’8′; }
if (C3 == 0) { delay(10000); while(C3==0); return ’9′; }
if (C4 == 0) { delay(10000); while(C4==0); return ‘/’; }
RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row B
RowB = 0;
if (C1 == 0) { delay(10000); while(C1==0); return ’4′; }
if (C2 == 0) { delay(10000); while(C2==0); return ’5′; }
if (C3 == 0) { delay(10000); while(C3==0); return ’6′; }
if (C4 == 0) { delay(10000); while(C4==0); return ‘x’; }
RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row C
RowC = 0;
if (C1 == 0) { delay(10000); while (C1==0); return ’1′; }
if (C2 == 0) { delay(10000); while(C2==0); return ’2′; }
if (C3 == 0) { delay(10000); while(C3==0); return ’3′; }
if (C4 == 0) { delay(10000); while(C4==0); return ‘-’; }
RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row D
RowD = 0;
if (C1 == 0) { delay(10000); while(C1==0); return ‘C’; }
if (C2 == 0) { delay(10000); while(C2==0); return ’0′; }
if (C3 == 0) { delay(10000); while(C3==0); return ‘=’; }
if (C4 == 0) { delay(10000); while(C4==0); return ‘+’; }
return ‘n’; // Means no key has been pressed
}
Interface lcdand keypad with8051 microcontroller inC language
Complete Program:
#include
#include
//Function declarations
void cct_init(void);
void delay(unsigned int);
void lcdinit(void);
void writecmd(int);
void writedata(char);
void Return(void);
char READ_SWITCHES(void);
char get_key(void);
void check_pwd(int);
void lcd_data(unsigned char *s);
void Home(void);
void ip_pwd(void);
void pass_code(void);
//*******************
//Pin description
sbit RowA = P1^0; //RowA
sbit RowB = P1^1; //RowB
sbit RowC = P1^2; //RowC
sbit RowD = P1^3; //RowD
sbit C1 = P1^4; //Column1
sbit C2 = P1^5; //Column2
sbit C3 = P1^6; //Column3
sbit C4 = P1^7; //Column4
sbit E = P3^6; //E pin for LCD
sbit RS = P3^7; //RS pin for LCD
void main()
{
cct_init(); // Make input and output pins as required
lcdinit(); // Initilize LCD
writecmd(0×01); //Clear LCD screen
writecmd(0×81); //move cursor on line 1 position 1
lcd_data(“Interfacelcd”);
writecmd(0xc2); //GO line 2 position 2
lcd_data(“with 8051″);
}
void lcd_data(unsigned char *s)
{
unsigned char l,i;
l = strlen(s); // get the length of string
for(i=0;i<l;i++)
{
writedata(*s);
s++;
}
}</l;i++)
void Home(void)
{
writecmd(0x02);
delay(2500);
}
void cct_init(void)
{
P0 = 0x00; //not used
P1 = 0xf0; //used for generating outputs and taking inputs from Keypad
P2 = 0x00; //used as data port for LCD
P3 = 0x00; //used for RS and E
}
void delay(unsigned int a)
{
int i;
for(i=0;i
}
void writedata(char t)
{
RS = 1; // This is data
P2 = t; //Data transfer
E = 1;
delay(150);
E = 0;
delay(150);
}
void writecmd(intz)
{
RS = 0; // This is command
P2 = z; //Data transfer
E = 1;
delay(150);
E = 0;
delay(150);
}
void lcdinit(void)
{
delay(15000);
writecmd(0x30);
delay(4500);
writecmd(0x30);
delay(300);
writecmd(0x30);
delay(650);
writecmd(0x38); //function set
writecmd(0x0f); //display on,cursor off,blink on
writecmd(0x01); //clear display
writecmd(0x06); //entry mode, set increment
}
char READ_SWITCHES(void)
{
RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row A
RowA = 0;
if (C1 == 0) { delay(10000); while(C1==0); return '7'; }
if (C2 == 0) { delay(10000); while(C2==0); return '8'; }
if (C3 == 0) { delay(10000); while(C3==0); return '9'; }
if (C4 == 0) { delay(10000); while(C4==0); return '/'; }
RowA = 1; RowB = 1; RowC = 1; RowD = 1; //Test Row B
RowB = 0;
if (C1 == 0) { delay(10000); while(C1==0); return '4'; }
if (C2 == 0) { delay(10000); while(C2==0); return '5'; }
if (C3 == 0) { delay(10000); while(C3==0); return '6'; }
if (C4 == 0) { delay(10000); while(C4==0); return 'x'; }
RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row C
RowC = 0;
if (C1 == 0) { delay(10000); while(C1==0); return '1'; }
if (C2 == 0) { delay(10000); while(C2==0); return '2'; }
if (C3 == 0) { delay(10000); while(C3==0); return '3'; }
if (C4 == 0) { delay(10000); while(C4==0); return '-'; }
RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row D
RowD = 0;
if (C1 == 0) { delay(10000); while(C1==0); return 'C'; }
if (C2 == 0) { delay(10000); while(C2==0); return '0'; }
if (C3 == 0) { delay(10000); while(C3==0); return '='; }
if (C4 == 0) { delay(10000); while(C4==0); return '+'; }
return 'n'; // Means no key has been pressed
}
Char get_key(void) //get key fromuser
{
char key = 'n'; //assumeno key pressed
while(key == 'n') //wait untill a key is pressed
key = READ_SWITCHES(); //scan the keys again and again
return key; //when key pressed then return its value
}

Weitere ähnliche Inhalte

Was ist angesagt?

MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration AKHIL MADANKAR
 
Unit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller pptsUnit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller pptsSreenivas Hanumandla
 
Lecture SOHIL LUHAR
Lecture SOHIL LUHARLecture SOHIL LUHAR
Lecture SOHIL LUHARSOHIL LUHAR
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Ganesh Ram
 
Magnetic door lock using arduino
Magnetic door lock using arduinoMagnetic door lock using arduino
Magnetic door lock using arduinoSravanthi Sinha
 
8051 microcontroller introduction
8051 microcontroller introduction8051 microcontroller introduction
8051 microcontroller introductionANJUSHA R
 
8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti 8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti VenkatraoRamisetti
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingAnkur Mahajan
 
Subroutine in 8051 microcontroller
Subroutine in 8051 microcontrollerSubroutine in 8051 microcontroller
Subroutine in 8051 microcontrollerbhadresh savani
 

Was ist angesagt? (19)

8051 i/o port circuit
8051 i/o port circuit8051 i/o port circuit
8051 i/o port circuit
 
MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration
 
Interfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 MicrocontrollerInterfacing LCD with 8051 Microcontroller
Interfacing LCD with 8051 Microcontroller
 
Unit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller pptsUnit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller ppts
 
Lecture SOHIL LUHAR
Lecture SOHIL LUHARLecture SOHIL LUHAR
Lecture SOHIL LUHAR
 
231456 006
231456 006231456 006
231456 006
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))
 
8051 full ppt
8051 full ppt8051 full ppt
8051 full ppt
 
I/O Ports
I/O Ports I/O Ports
I/O Ports
 
Magnetic door lock using arduino
Magnetic door lock using arduinoMagnetic door lock using arduino
Magnetic door lock using arduino
 
I o ports.ppt
I o ports.pptI o ports.ppt
I o ports.ppt
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 Microcontroller
 
8051 microcontroller introduction
8051 microcontroller introduction8051 microcontroller introduction
8051 microcontroller introduction
 
8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti 8051 Microcontroller Overview by Venkatrao Ramisetti
8051 Microcontroller Overview by Venkatrao Ramisetti
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacing
 
Subroutine in 8051 microcontroller
Subroutine in 8051 microcontrollerSubroutine in 8051 microcontroller
Subroutine in 8051 microcontroller
 
dspAt89 s52
dspAt89 s52dspAt89 s52
dspAt89 s52
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 

Ähnlich wie Keypad interfacing 8051 -NANOCDAC

Microcontroller 8051 By Mitesh kumar
Microcontroller 8051 By Mitesh kumarMicrocontroller 8051 By Mitesh kumar
Microcontroller 8051 By Mitesh kumarMitesh Kumar
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051Sadiq Rahim
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller Gaurav Verma
 
Microprocessorlabmanual ee0310
Microprocessorlabmanual ee0310Microprocessorlabmanual ee0310
Microprocessorlabmanual ee0310DHEERAJ DHAKAR
 
I Ointerface in mp
I Ointerface in mpI Ointerface in mp
I Ointerface in mpAisu
 
8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.pptnotagain0712
 
m.tech esd lab manual for record
m.tech esd lab manual for recordm.tech esd lab manual for record
m.tech esd lab manual for recordG Lemuel George
 
Analog To Digital Conversion (ADC) Programming in LPC2148
Analog To Digital Conversion (ADC) Programming in LPC2148Analog To Digital Conversion (ADC) Programming in LPC2148
Analog To Digital Conversion (ADC) Programming in LPC2148Omkar Rane
 
EMBEDDED SYSTEMS 2&3
EMBEDDED SYSTEMS 2&3EMBEDDED SYSTEMS 2&3
EMBEDDED SYSTEMS 2&3PRADEEP
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051Moeez Shem
 
Pin Description and Register Organization of 8086 Microprocessor
Pin Description and Register Organization of 8086 MicroprocessorPin Description and Register Organization of 8086 Microprocessor
Pin Description and Register Organization of 8086 MicroprocessorMuthusamy Arumugam
 
digitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdfdigitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdfsatyamsinha37
 
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLERDIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLERChirag Lakhani
 

Ähnlich wie Keypad interfacing 8051 -NANOCDAC (20)

Microcontroller 8051 By Mitesh kumar
Microcontroller 8051 By Mitesh kumarMicrocontroller 8051 By Mitesh kumar
Microcontroller 8051 By Mitesh kumar
 
AT89C52 Data sheet
AT89C52 Data sheetAT89C52 Data sheet
AT89C52 Data sheet
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Final Presentation
Final PresentationFinal Presentation
Final Presentation
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
 
Microprocessorlabmanual ee0310
Microprocessorlabmanual ee0310Microprocessorlabmanual ee0310
Microprocessorlabmanual ee0310
 
I Ointerface in mp
I Ointerface in mpI Ointerface in mp
I Ointerface in mp
 
8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt
 
m.tech esd lab manual for record
m.tech esd lab manual for recordm.tech esd lab manual for record
m.tech esd lab manual for record
 
Analog To Digital Conversion (ADC) Programming in LPC2148
Analog To Digital Conversion (ADC) Programming in LPC2148Analog To Digital Conversion (ADC) Programming in LPC2148
Analog To Digital Conversion (ADC) Programming in LPC2148
 
EMBEDDED SYSTEMS 2&3
EMBEDDED SYSTEMS 2&3EMBEDDED SYSTEMS 2&3
EMBEDDED SYSTEMS 2&3
 
Chapter5 dek3133
Chapter5 dek3133Chapter5 dek3133
Chapter5 dek3133
 
knowledge in daily life.ppt
knowledge in daily life.pptknowledge in daily life.ppt
knowledge in daily life.ppt
 
8155 GPPI
8155 GPPI8155 GPPI
8155 GPPI
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Pin Description and Register Organization of 8086 Microprocessor
Pin Description and Register Organization of 8086 MicroprocessorPin Description and Register Organization of 8086 Microprocessor
Pin Description and Register Organization of 8086 Microprocessor
 
digital clock atmega16
digital clock atmega16digital clock atmega16
digital clock atmega16
 
Em s7 plc
Em s7 plcEm s7 plc
Em s7 plc
 
digitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdfdigitalvoltmeterusing805112b2-170214173216 (1).pdf
digitalvoltmeterusing805112b2-170214173216 (1).pdf
 
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLERDIGITAL VOLTMETER USING 8051 MICROCONTROLLER
DIGITAL VOLTMETER USING 8051 MICROCONTROLLER
 

Kürzlich hochgeladen

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Kürzlich hochgeladen (20)

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

Keypad interfacing 8051 -NANOCDAC

  • 1. KEYPAD INTERFACING 8051 Keypad is a widely used input device with lots of application in our everyday life. From a simpletelephone to keyboard of a computer, ATM, electronic lock, etc., keypad is used to take input from the user for further processing. In this article we are interfacing keypad with the MCU AT89C51 and displaying the corresponding number on LCD. This module can be further used in a number of systems to interfaced keypad with microcontroller and other processors to get desired output. The program to interface keypad with controller is written in C language which is very easy to understand. The above figure explains how a keypad can be interfaced with 8051. DESCRIPTION: Keypad is organized as a matrix of switches in rows and column. The article uses a 4X3 matrix keypad and a 16x2 LCD for displaying the output of keypad. The circuit diagram shows the connection of keypad with the controller. PortP2 of the microcontroller is used to send the data for displaying on the LCD. P1^1, P1^2, P1^3 pins of microcontroller is connected to RS, RW, EN pins of LCD respectively. PortP0 is used to scan input fromthe keypad (refer circuit diagram for connection).The concept of interfacing keypad with the MCU is simple. Every number is assigned two unique parameters, i.e., row and column number (n(R, C) for example 6 (2, 3)). Hence every time a key is pressed the number is identified by detecting the row and column number of the key pressed. Initially all the rows are set to zero by the controller and the columns are scanned to check if any key is pressed. In caseno key is pressed the output of all the columns will be high.
  • 2. Diagramatically it can be represented as follows: Whenever a key is pressed the row and column corresponding to the key will get short, resulting in the output of the corresponding column goes to go low (since we have made all the rows zero). This gives the column number of the pressed key. Once the column number is detected, the controller set’s all the rows to high. Now one by one each row is set to zero by controller and the earlier detected column is checked if it becomes zero. The row corresponding to which the column gets zero is the row number of the digit.
  • 3. The above process is very fast and even if the switch is pressed for a very small duration of time the controller can detect the key which is pressed. The controller displays the number corresponding to the row and column on the LCD.
  • 4. CIRCUIT DIAGRAM: The above circuit diagram explains how a keypad which is nothing but a seven segment display can be interfaced with AT89S51 microcontroller. COMPONENTS: PRESET: A preset is a three legged electronic componentwhich can be made to Offer varying resistancein a circuit. The resistanceis varied by adjusting the rotary control over it. The adjustmentcan be done by using a small screw driver or a similar tool. The resistancedoes not vary linearly but rather varies in exponential or logarithmic manner. Such variable resistors arecommonly used for adjusting sensitivity along a sensor. The variable resistanceis obtained across the single terminal at frontand one of the two other terminals. The two legs at back offer fixed resistancewhich is divided by the front leg. So, whenever only the back terminals are used, a presetacts as a fixed resistor. Presets arefixed by their fixed value resistance.
  • 5. AT89C51: AT89S51is an 8-bit microcontroller and belongs to Atmel’s 8051 family. AT89C51 has 4KBFlash programmable and erasableread only memory (PROM) and128 bytes of RAM. Itcan be erased and programto a maximum of 1000 times. In 40-pin AT89C51 thereare four ports designated as P0, P1, P2 and P3. All these ports are 8-pin bidirectional ports i.e., they can be used as both input ports and output ports. Except P0 which needs external pull-ups, restof the ports have internal pull-ups. When 1’s are written to these port pins, they are pulled high by the internal pull-ups and can be used as inputs. These ports are also bit addressableand so there can also be accessed individually. Port0 and Port2 are also used to providelow byte and high byte addresses respectively, when connected to an external memory. Port3 has multiplexed pins for special functions like serial communication, hardwareinterrupts, timer inputs, and read/writeoperation from external memory. AT89C51 has an inbuilt UART for serialcommunication. Itcan be programmed to operate at differentbaud rates. Including two timers and hardwareinterrupts it has a total of 6 interrupts. Pin diagramfor AT89C51 can be given as follows:
  • 7. PIN DESCRIPTION: Pin No Function Name 1 8 bit input/output port (P1) pins P1.0 2 P1.1 3 P1.2 4 P1.3 5 P1.4 6 P1.5 7 P1.6 8 P1.7 9 Reset pin; Active high Reset 10 Input (receiver) for serial communication RxD 8 bit input/output port (P3) pins P3.0 11 Output (transmitter) for serial communication TxD P3.1 12 External interrupt 1 Int0 P3.2 13 External interrupt 2 Int1 P3.3 14 Timer1 external input T0 P3.4 15 Timer2 external input T1 P3.5 16 Write to external data memory Write P3.6 17 Read from external data memory Read P3.7 18 Quartz crystal oscillator (up to 24 MHz) Crystal 2 19 Crystal 1 20 Ground (0V) Ground 21 8 bit input/output port (P2) pins / High-order address bits when interfacing with external memory P2.0/ A8 22 P2.1/ A9 23 P2.2/ A10 24 P2.3/ A11 25 P2.4/ A12 26 P2.5/ A13 27 P2.6/ A14 28 P2.7/ A15 29 Program store enable; Read from external program memory PSEN 30 Address Latch Enable ALE Program pulse input during Flash programming Prog 31 External Access Enable; Vcc for internal program executions EA Programming enable voltage; 12V (during Flash programming) Vpp 32 8 bit input/output port (P0) pins Low-order address bits when interfacing with external memory P0.7/ AD7 33 P0.6/ AD6 34 P0.5/ AD5 35 P0.4/ AD4 36 P0.3/ AD3 37 P0.2/ AD2 38 P0.1/ AD1 39 P0.0/ AD0 40 Supply voltage; 5V (up to 6.6V) Vcc
  • 8. LCD: 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 and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special. 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. This LCD has two registers, namely, Command and Data. The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD. The above figure represents a LCD.
  • 9. PIN DIAGRAM: The above figure represents a LCD. PIN DESCRIPTION: Pin No Function Name 1 Ground (0V) Ground 2 Supply voltage; 5V (4.7V – 5.3V) Vcc 3 Contrastadjustment; through a variable resistor VEE 4 Selects command register when low; and data register when high Register Select 5 Low to write to the register; High to read from the register Read/write 6 Sends data to data pins when a high to low pulseis given Enable 7 8-bit data pins DB0 8 DB1 9 DB2 10 DB3 11 DB4 12 DB5 13 DB6 14 DB7 15 Backlight VCC (5V) Led+ 16 Backlight Ground (0V) Led-
  • 10. Interface keypadwith8051 microcontroller inC language: How to detect pressedkey value? When key 1 is pressed then RowC wire is shorted with C1 wire inside the keypad. Similarly, when key 9 is pressed then RowA wire is shorted with C3 wire. This behavior is true for all the keys. How to detect this behavior in the microcontroller code? We can detect pressed key value in the microcontroller using the “Scanning algorithm code”. This algorithm is written with the name of ‘Read_Switches ()’ function in the code. The function is shown below char READ_SWITCHES(void) { RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row A RowA = 0; if (C1 == 0) { delay(10000); while(C1==0); return ’7′; } if (C2 == 0) { delay(10000); while(C2==0); return ’8′; } if (C3 == 0) { delay(10000); while(C3==0); return ’9′; } if (C4 == 0) { delay(10000); while(C4==0); return ‘/’; } RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row B RowB = 0; if (C1 == 0) { delay(10000); while(C1==0); return ’4′; } if (C2 == 0) { delay(10000); while(C2==0); return ’5′; } if (C3 == 0) { delay(10000); while(C3==0); return ’6′; } if (C4 == 0) { delay(10000); while(C4==0); return ‘x’; } RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row C RowC = 0; if (C1 == 0) { delay(10000); while (C1==0); return ’1′; } if (C2 == 0) { delay(10000); while(C2==0); return ’2′; } if (C3 == 0) { delay(10000); while(C3==0); return ’3′; } if (C4 == 0) { delay(10000); while(C4==0); return ‘-’; } RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row D RowD = 0; if (C1 == 0) { delay(10000); while(C1==0); return ‘C’; } if (C2 == 0) { delay(10000); while(C2==0); return ’0′; } if (C3 == 0) { delay(10000); while(C3==0); return ‘=’; } if (C4 == 0) { delay(10000); while(C4==0); return ‘+’; } return ‘n’; // Means no key has been pressed } Interface lcdand keypad with8051 microcontroller inC language Complete Program: #include #include //Function declarations void cct_init(void); void delay(unsigned int); void lcdinit(void); void writecmd(int); void writedata(char); void Return(void); char READ_SWITCHES(void);
  • 11. char get_key(void); void check_pwd(int); void lcd_data(unsigned char *s); void Home(void); void ip_pwd(void); void pass_code(void); //******************* //Pin description sbit RowA = P1^0; //RowA sbit RowB = P1^1; //RowB sbit RowC = P1^2; //RowC sbit RowD = P1^3; //RowD sbit C1 = P1^4; //Column1 sbit C2 = P1^5; //Column2 sbit C3 = P1^6; //Column3 sbit C4 = P1^7; //Column4 sbit E = P3^6; //E pin for LCD sbit RS = P3^7; //RS pin for LCD void main() { cct_init(); // Make input and output pins as required lcdinit(); // Initilize LCD writecmd(0×01); //Clear LCD screen writecmd(0×81); //move cursor on line 1 position 1 lcd_data(“Interfacelcd”); writecmd(0xc2); //GO line 2 position 2 lcd_data(“with 8051″); } void lcd_data(unsigned char *s) { unsigned char l,i; l = strlen(s); // get the length of string for(i=0;i<l;i++) { writedata(*s); s++; } }</l;i++) void Home(void) { writecmd(0x02); delay(2500); } void cct_init(void) { P0 = 0x00; //not used P1 = 0xf0; //used for generating outputs and taking inputs from Keypad P2 = 0x00; //used as data port for LCD P3 = 0x00; //used for RS and E }
  • 12. void delay(unsigned int a) { int i; for(i=0;i } void writedata(char t) { RS = 1; // This is data P2 = t; //Data transfer E = 1; delay(150); E = 0; delay(150); } void writecmd(intz) { RS = 0; // This is command P2 = z; //Data transfer E = 1; delay(150); E = 0; delay(150); } void lcdinit(void) { delay(15000); writecmd(0x30); delay(4500); writecmd(0x30); delay(300); writecmd(0x30); delay(650); writecmd(0x38); //function set writecmd(0x0f); //display on,cursor off,blink on writecmd(0x01); //clear display writecmd(0x06); //entry mode, set increment } char READ_SWITCHES(void) { RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row A RowA = 0; if (C1 == 0) { delay(10000); while(C1==0); return '7'; } if (C2 == 0) { delay(10000); while(C2==0); return '8'; } if (C3 == 0) { delay(10000); while(C3==0); return '9'; } if (C4 == 0) { delay(10000); while(C4==0); return '/'; } RowA = 1; RowB = 1; RowC = 1; RowD = 1; //Test Row B RowB = 0; if (C1 == 0) { delay(10000); while(C1==0); return '4'; } if (C2 == 0) { delay(10000); while(C2==0); return '5'; } if (C3 == 0) { delay(10000); while(C3==0); return '6'; } if (C4 == 0) { delay(10000); while(C4==0); return 'x'; }
  • 13. RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row C RowC = 0; if (C1 == 0) { delay(10000); while(C1==0); return '1'; } if (C2 == 0) { delay(10000); while(C2==0); return '2'; } if (C3 == 0) { delay(10000); while(C3==0); return '3'; } if (C4 == 0) { delay(10000); while(C4==0); return '-'; } RowA = 1; RowB= 1; RowC = 1; RowD = 1; //Test Row D RowD = 0; if (C1 == 0) { delay(10000); while(C1==0); return 'C'; } if (C2 == 0) { delay(10000); while(C2==0); return '0'; } if (C3 == 0) { delay(10000); while(C3==0); return '='; } if (C4 == 0) { delay(10000); while(C4==0); return '+'; } return 'n'; // Means no key has been pressed } Char get_key(void) //get key fromuser { char key = 'n'; //assumeno key pressed while(key == 'n') //wait untill a key is pressed key = READ_SWITCHES(); //scan the keys again and again return key; //when key pressed then return its value }