SlideShare a Scribd company logo
Interfacing the Keyboard to 8051 microcontroller

The key board here we are interfacing is a matrix keyboard. This key board
is designed with a particular rows and columns. These rows and columns
are connected to the microcontroller through its ports of the micro
controller 8051. We normally use 8*8 matrix key board. So only two ports of
8051 can be easily connected to the rows and columns of the key board.

      When ever a key is pressed, a row and a column gets shorted
through that pressed key and all the other keys are left open. When a key
is pressed only a bit in the port goes high. Which indicates
microcontroller that the key is pressed. By this high on the bit key in the
corresponding column is identified.

      Once we are sure that one of key in the key board is pressed next our
aim is to identify that key. To do this we firstly check for particular row and
then we check the corresponding column the key board.

      To check the row of the pressed key in the keyboard, one of the row
is made high by making one of bit in the output port of 8051 high. This is
done until the row is found out. Once we get the row next out job is to find
out the column of the pressed key. The column is detected by contents in
the input ports with the help of a counter. The content of the input port is
rotated with carry until the carry bit is set.

      The contents of the counter is then compared and displayed in the
display. This display is designed using a seven segment display and a BCD
to seven segment decoder IC 7447.

      The BCD equivalent number of counter is sent through output part of
8051 displays the number of pressed key.
Circuit diagram of INTERFACING KEY BOARD TO 8051.

The programming algorithm, program and the circuit diagram is as follows.
Here program is explained with comments.




          Circuit diagram of INTERFACING KEY BOARD TO 8051.

Keyboard is organized in a matrix of rows and columns as shown in the
figure. The microcontroller accesses both rows and columns through the
port.

         1. The 8051 has 4 I/O ports P0 to P3 each with 8 I/O pins, P0.0 to
            P0.7, P1.0 to P1.7, P2.0 to P2.7, P3.0 to P3.7. The one of the
            port P1 (it understood that P1 means P1.0 to P1.7) as an I/P
            port for microcontroller 8051, port P0 as an O/P port of
            microcontroller 8051 and port P2 is used for displaying the
            number of pressed key.
         2. Make all rows of port P0 high so that it gives high signal when
            key is pressed.

         3.   See if any key is pressed by scanning the port P1 by checking
              all columns for non zero condition.

         4.   If any key is pressed, to identify which key is pressed make
              one row high at a time.

         5.   Initiate a counter to hold the count so that each key is
              counted.
6.    Check port P1 for nonzero condition. If any nonzero number is
                  there in [accumulator], start column scanning by following
                  step 9.

             7.   Otherwise make next row high in port P1.

             8.    Add a count of 08h to the counter to move to the next row by
                  repeating steps from step 6.

        9.    If any key pressed is found, the [accumulator] content is rotated
             right through the carry until carry bit sets, while doing this
             increment the count in the counter till carry is found.

        10. Move the content in the counter to display in data field or to
           memory location

        11. To repeat the procedures go to step 2.

Program to interface matrix keyboard to microcontroller 8051

Start of main program:
to check that whether any key is pressed

                    start: mov a,#00h
                           mov p1,a         ;making all rows of port p1 zero
                           mov a,#0fh
                           mov p1,a         ;making all rows of port p1 high
                    press: mov a,p2
                           jz press         ;check until any key is pressed

after making sure that any key is pressed

                          mov a,#01h        ;make one row high at a time
                          mov r4,a
                          mov r3,#00h        ;initiating counter
                    next: mov a,r4
                          mov p1,a          ;making one row high at a time
                          mov a,p2          ;taking input from port A
                          jnz colscan       ;after getting the row jump to
check
                                              column
                           mov a,r4
rl a             ;rotate left to check next row
                      mov r4,a
                      mov a,r3
                      add a,#08h       ;increment counter by 08 count
                      mov r3,a
                      sjmp next       ;jump to check next row

after identifying the row to check the colomn following steps are followed

           colscan: mov r5,#00h
                in: rrc a       ;rotate right with carry until get the
carry
                      jc out       ;jump on getting carry
                      inc r3       ;increment one count
                      jmp in
               out:   mov a,r3
                      da a          ;decimal adjust the contents of
counter
                                       before display
                      mov p2,a

                      jmp start    ;repeat for check next key.

More Related Content

What's hot

Semiconductor diodes
Semiconductor diodesSemiconductor diodes
Semiconductor diodes
Sirat Mahmood
 
Stepper motor-interfacing
Stepper motor-interfacingStepper motor-interfacing
Stepper motor-interfacing
Lecturer
 
Interfacing Bluetooth Modules with 8051 Microcontroller
Interfacing Bluetooth Modules with 8051 MicrocontrollerInterfacing Bluetooth Modules with 8051 Microcontroller
Interfacing Bluetooth Modules with 8051 Microcontroller
Pantech ProLabs India Pvt Ltd
 
Interfacing external memory in 8051
Interfacing external memory in 8051Interfacing external memory in 8051
Interfacing external memory in 8051
ssuser3a47cb
 
Interrupt Handling with LPC2148
Interrupt Handling with LPC2148Interrupt Handling with LPC2148
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
Ankit Bhatnagar
 
Ec8791 lpc2148 timer unit
Ec8791 lpc2148 timer unitEc8791 lpc2148 timer unit
Ec8791 lpc2148 timer unit
RajalakshmiSermadurai
 
8086
80868086
Adc interfacing
Adc interfacingAdc interfacing
Adc interfacing
Monica Gunjal
 
Instrumentation Lab. Experiment #4 Report: Op-Amps: Integrator, Differentiato...
Instrumentation Lab. Experiment #4 Report: Op-Amps: Integrator, Differentiato...Instrumentation Lab. Experiment #4 Report: Op-Amps: Integrator, Differentiato...
Instrumentation Lab. Experiment #4 Report: Op-Amps: Integrator, Differentiato...
mohammad zeyad
 
Coin based mobile phone charger
Coin based mobile phone chargerCoin based mobile phone charger
Coin based mobile phone charger
Saylee joshi
 
Carrier transport processes
Carrier transport processesCarrier transport processes
Carrier transport processes
RCC Institute of Information Technology
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.
parthi_arjun
 
ARM Fundamentals
ARM FundamentalsARM Fundamentals
ARM Fundamentals
guest56d1b781
 
Addressing modes of 8086 - Binu Joy
Addressing modes of 8086 - Binu JoyAddressing modes of 8086 - Binu Joy
Addressing modes of 8086 - Binu Joy
Binu Joy
 
I o ports and timers of 8051
I o ports and timers of 8051I o ports and timers of 8051
I o ports and timers of 8051
SARITHA REDDY
 
Delay routine
Delay routineDelay routine
Delay routine
Yash Gandhi
 
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.k
Vijay Kumar
 
8251 communication interface
8251 communication interface8251 communication interface
8251 communication interface
LingalaSowjanya
 
8051 full ppt
8051 full ppt8051 full ppt

What's hot (20)

Semiconductor diodes
Semiconductor diodesSemiconductor diodes
Semiconductor diodes
 
Stepper motor-interfacing
Stepper motor-interfacingStepper motor-interfacing
Stepper motor-interfacing
 
Interfacing Bluetooth Modules with 8051 Microcontroller
Interfacing Bluetooth Modules with 8051 MicrocontrollerInterfacing Bluetooth Modules with 8051 Microcontroller
Interfacing Bluetooth Modules with 8051 Microcontroller
 
Interfacing external memory in 8051
Interfacing external memory in 8051Interfacing external memory in 8051
Interfacing external memory in 8051
 
Interrupt Handling with LPC2148
Interrupt Handling with LPC2148Interrupt Handling with LPC2148
Interrupt Handling with LPC2148
 
Interrupt programming with 8051 microcontroller
Interrupt programming with 8051  microcontrollerInterrupt programming with 8051  microcontroller
Interrupt programming with 8051 microcontroller
 
Ec8791 lpc2148 timer unit
Ec8791 lpc2148 timer unitEc8791 lpc2148 timer unit
Ec8791 lpc2148 timer unit
 
8086
80868086
8086
 
Adc interfacing
Adc interfacingAdc interfacing
Adc interfacing
 
Instrumentation Lab. Experiment #4 Report: Op-Amps: Integrator, Differentiato...
Instrumentation Lab. Experiment #4 Report: Op-Amps: Integrator, Differentiato...Instrumentation Lab. Experiment #4 Report: Op-Amps: Integrator, Differentiato...
Instrumentation Lab. Experiment #4 Report: Op-Amps: Integrator, Differentiato...
 
Coin based mobile phone charger
Coin based mobile phone chargerCoin based mobile phone charger
Coin based mobile phone charger
 
Carrier transport processes
Carrier transport processesCarrier transport processes
Carrier transport processes
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.
 
ARM Fundamentals
ARM FundamentalsARM Fundamentals
ARM Fundamentals
 
Addressing modes of 8086 - Binu Joy
Addressing modes of 8086 - Binu JoyAddressing modes of 8086 - Binu Joy
Addressing modes of 8086 - Binu Joy
 
I o ports and timers of 8051
I o ports and timers of 8051I o ports and timers of 8051
I o ports and timers of 8051
 
Delay routine
Delay routineDelay routine
Delay routine
 
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.k
 
8251 communication interface
8251 communication interface8251 communication interface
8251 communication interface
 
8051 full ppt
8051 full ppt8051 full ppt
8051 full ppt
 

Viewers also liked

An Introduction to Mechanical Keyboards
An Introduction to Mechanical KeyboardsAn Introduction to Mechanical Keyboards
An Introduction to Mechanical Keyboards
Marco Enrico
 
Peripheral devices
Peripheral devicesPeripheral devices
BASIC COMPUTER PERIPHERALS/DEVICES/SYSTEMS
BASIC COMPUTER PERIPHERALS/DEVICES/SYSTEMSBASIC COMPUTER PERIPHERALS/DEVICES/SYSTEMS
BASIC COMPUTER PERIPHERALS/DEVICES/SYSTEMS
Neve Deschanel
 
Video display device
Video display deviceVideo display device
Video display device
missagrata
 
Keyboard and its types
Keyboard and its typesKeyboard and its types
Keyboard and its types
Anshuraj Gautam
 
Peripheral devices
Peripheral     devicesPeripheral     devices
Peripheral devices
Annie Farooq
 

Viewers also liked (7)

An Introduction to Mechanical Keyboards
An Introduction to Mechanical KeyboardsAn Introduction to Mechanical Keyboards
An Introduction to Mechanical Keyboards
 
Peripheral devices
Peripheral devicesPeripheral devices
Peripheral devices
 
BASIC COMPUTER PERIPHERALS/DEVICES/SYSTEMS
BASIC COMPUTER PERIPHERALS/DEVICES/SYSTEMSBASIC COMPUTER PERIPHERALS/DEVICES/SYSTEMS
BASIC COMPUTER PERIPHERALS/DEVICES/SYSTEMS
 
Video display device
Video display deviceVideo display device
Video display device
 
Keyboard and its types
Keyboard and its typesKeyboard and its types
Keyboard and its types
 
Keyboard
KeyboardKeyboard
Keyboard
 
Peripheral devices
Peripheral     devicesPeripheral     devices
Peripheral devices
 

Similar to 86409 interfacing the keyboard to 8051 microcontroller

Microcontroladores: El microcontrolador 8051 con LCD 16x2
Microcontroladores: El microcontrolador 8051 con LCD 16x2Microcontroladores: El microcontrolador 8051 con LCD 16x2
Microcontroladores: El microcontrolador 8051 con LCD 16x2
SANTIAGO PABLO ALBERTO
 
Keypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerKeypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 Microcontroller
Sudhanshu Janwadkar
 
WINSEM2023-24_BECE204L_TH_VL2023240505625_2024-01-29_Reference-Material-I.pptx
WINSEM2023-24_BECE204L_TH_VL2023240505625_2024-01-29_Reference-Material-I.pptxWINSEM2023-24_BECE204L_TH_VL2023240505625_2024-01-29_Reference-Material-I.pptx
WINSEM2023-24_BECE204L_TH_VL2023240505625_2024-01-29_Reference-Material-I.pptx
SrinivasanUma1
 
Keypad and dc motor
Keypad and dc motor Keypad and dc motor
Keypad and dc motor
vijaydeepakg
 
B sc cs i bo-de u-iii counters & registers
B sc cs i bo-de u-iii counters & registersB sc cs i bo-de u-iii counters & registers
B sc cs i bo-de u-iii counters & registers
Rai University
 
G. ripple counter
G. ripple counterG. ripple counter
G. ripple counter
john lexter emberador
 
pic-prog-assembly.pdf
pic-prog-assembly.pdfpic-prog-assembly.pdf
pic-prog-assembly.pdf
MulugetaTesema
 
counters and resister presentations.pptx
counters and resister presentations.pptxcounters and resister presentations.pptx
counters and resister presentations.pptx
arushika2211
 
Steppert Motor Interfacing With Specific Angle Entered Through Keypad
Steppert Motor Interfacing With Specific Angle Entered Through KeypadSteppert Motor Interfacing With Specific Angle Entered Through Keypad
Steppert Motor Interfacing With Specific Angle Entered Through Keypad
Abrar Amin
 
Microcontroller- An overview
Microcontroller- An overviewMicrocontroller- An overview
Microcontroller- An overview
PANIMALAR ENGINEERING COLLEGE
 
Lab manual mp
Lab manual mpLab manual mp
Lab manual mp
HarshitParkar6677
 
Serial.ppt and it contains all information
Serial.ppt and it contains all informationSerial.ppt and it contains all information
Serial.ppt and it contains all information
shwetasonkar638
 
Lab 9 D-Flip Flops: Shift Register and Sequence Counter
Lab 9 D-Flip Flops: Shift Register and Sequence CounterLab 9 D-Flip Flops: Shift Register and Sequence Counter
Lab 9 D-Flip Flops: Shift Register and Sequence Counter
Katrina Little
 
Ring counter
Ring counterRing counter
Ring counter
Ghufran Hasan
 
Synchronous down counter
Synchronous down counterSynchronous down counter
Synchronous down counter
RONAK SUTARIYA
 
Interfacing ics for microprocessor
Interfacing ics for microprocessorInterfacing ics for microprocessor
Interfacing ics for microprocessor
THANDAIAH PRABU
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
BASKARS53
 
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
KanchanPatil34
 
Micro c lab4(keypad)
Micro c lab4(keypad)Micro c lab4(keypad)
Micro c lab4(keypad)
Mashood
 
Ch2
Ch2Ch2

Similar to 86409 interfacing the keyboard to 8051 microcontroller (20)

Microcontroladores: El microcontrolador 8051 con LCD 16x2
Microcontroladores: El microcontrolador 8051 con LCD 16x2Microcontroladores: El microcontrolador 8051 con LCD 16x2
Microcontroladores: El microcontrolador 8051 con LCD 16x2
 
Keypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 MicrocontrollerKeypad Interfacing with 8051 Microcontroller
Keypad Interfacing with 8051 Microcontroller
 
WINSEM2023-24_BECE204L_TH_VL2023240505625_2024-01-29_Reference-Material-I.pptx
WINSEM2023-24_BECE204L_TH_VL2023240505625_2024-01-29_Reference-Material-I.pptxWINSEM2023-24_BECE204L_TH_VL2023240505625_2024-01-29_Reference-Material-I.pptx
WINSEM2023-24_BECE204L_TH_VL2023240505625_2024-01-29_Reference-Material-I.pptx
 
Keypad and dc motor
Keypad and dc motor Keypad and dc motor
Keypad and dc motor
 
B sc cs i bo-de u-iii counters & registers
B sc cs i bo-de u-iii counters & registersB sc cs i bo-de u-iii counters & registers
B sc cs i bo-de u-iii counters & registers
 
G. ripple counter
G. ripple counterG. ripple counter
G. ripple counter
 
pic-prog-assembly.pdf
pic-prog-assembly.pdfpic-prog-assembly.pdf
pic-prog-assembly.pdf
 
counters and resister presentations.pptx
counters and resister presentations.pptxcounters and resister presentations.pptx
counters and resister presentations.pptx
 
Steppert Motor Interfacing With Specific Angle Entered Through Keypad
Steppert Motor Interfacing With Specific Angle Entered Through KeypadSteppert Motor Interfacing With Specific Angle Entered Through Keypad
Steppert Motor Interfacing With Specific Angle Entered Through Keypad
 
Microcontroller- An overview
Microcontroller- An overviewMicrocontroller- An overview
Microcontroller- An overview
 
Lab manual mp
Lab manual mpLab manual mp
Lab manual mp
 
Serial.ppt and it contains all information
Serial.ppt and it contains all informationSerial.ppt and it contains all information
Serial.ppt and it contains all information
 
Lab 9 D-Flip Flops: Shift Register and Sequence Counter
Lab 9 D-Flip Flops: Shift Register and Sequence CounterLab 9 D-Flip Flops: Shift Register and Sequence Counter
Lab 9 D-Flip Flops: Shift Register and Sequence Counter
 
Ring counter
Ring counterRing counter
Ring counter
 
Synchronous down counter
Synchronous down counterSynchronous down counter
Synchronous down counter
 
Interfacing ics for microprocessor
Interfacing ics for microprocessorInterfacing ics for microprocessor
Interfacing ics for microprocessor
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
 
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
 
Micro c lab4(keypad)
Micro c lab4(keypad)Micro c lab4(keypad)
Micro c lab4(keypad)
 
Ch2
Ch2Ch2
Ch2
 

More from bheemsain

Wierless networks ch3 (1)
Wierless networks ch3 (1)Wierless networks ch3 (1)
Wierless networks ch3 (1)
bheemsain
 
Man
ManMan
Last year paper2
Last year paper2Last year paper2
Last year paper2
bheemsain
 
Frame relay
Frame relayFrame relay
Frame relay
bheemsain
 
Foc ppt
Foc pptFoc ppt
Foc ppt
bheemsain
 
Fiber signal degradation final
Fiber  signal degradation finalFiber  signal degradation final
Fiber signal degradation final
bheemsain
 
Ese570 mos theory_p206
Ese570 mos theory_p206Ese570 mos theory_p206
Ese570 mos theory_p206
bheemsain
 
Ese570 inv stat12
Ese570 inv stat12Ese570 inv stat12
Ese570 inv stat12
bheemsain
 
Ee560 mos theory_p101
Ee560 mos theory_p101Ee560 mos theory_p101
Ee560 mos theory_p101
bheemsain
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
bheemsain
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
bheemsain
 
Ch07 2
Ch07 2Ch07 2
Ch07 2
bheemsain
 
Ch07 1
Ch07 1Ch07 1
Ch07 1
bheemsain
 
Ch03 2
Ch03 2Ch03 2
Ch03 2
bheemsain
 
Ch03 1
Ch03 1Ch03 1
Ch03 1
bheemsain
 
Ch02 2
Ch02 2Ch02 2
Ch02 2
bheemsain
 
Ch02 1
Ch02 1Ch02 1
Ch02 1
bheemsain
 
Ch01
Ch01Ch01
Ch01
bheemsain
 
Ch 6 data and computer communicationwilliam stallings
Ch 6 data and computer communicationwilliam stallingsCh 6 data and computer communicationwilliam stallings
Ch 6 data and computer communicationwilliam stallings
bheemsain
 
Ch 6 data and computer communicationwilliam stallings (1)
Ch 6 data and computer communicationwilliam stallings (1)Ch 6 data and computer communicationwilliam stallings (1)
Ch 6 data and computer communicationwilliam stallings (1)
bheemsain
 

More from bheemsain (20)

Wierless networks ch3 (1)
Wierless networks ch3 (1)Wierless networks ch3 (1)
Wierless networks ch3 (1)
 
Man
ManMan
Man
 
Last year paper2
Last year paper2Last year paper2
Last year paper2
 
Frame relay
Frame relayFrame relay
Frame relay
 
Foc ppt
Foc pptFoc ppt
Foc ppt
 
Fiber signal degradation final
Fiber  signal degradation finalFiber  signal degradation final
Fiber signal degradation final
 
Ese570 mos theory_p206
Ese570 mos theory_p206Ese570 mos theory_p206
Ese570 mos theory_p206
 
Ese570 inv stat12
Ese570 inv stat12Ese570 inv stat12
Ese570 inv stat12
 
Ee560 mos theory_p101
Ee560 mos theory_p101Ee560 mos theory_p101
Ee560 mos theory_p101
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
Ch07 2
Ch07 2Ch07 2
Ch07 2
 
Ch07 1
Ch07 1Ch07 1
Ch07 1
 
Ch03 2
Ch03 2Ch03 2
Ch03 2
 
Ch03 1
Ch03 1Ch03 1
Ch03 1
 
Ch02 2
Ch02 2Ch02 2
Ch02 2
 
Ch02 1
Ch02 1Ch02 1
Ch02 1
 
Ch01
Ch01Ch01
Ch01
 
Ch 6 data and computer communicationwilliam stallings
Ch 6 data and computer communicationwilliam stallingsCh 6 data and computer communicationwilliam stallings
Ch 6 data and computer communicationwilliam stallings
 
Ch 6 data and computer communicationwilliam stallings (1)
Ch 6 data and computer communicationwilliam stallings (1)Ch 6 data and computer communicationwilliam stallings (1)
Ch 6 data and computer communicationwilliam stallings (1)
 

86409 interfacing the keyboard to 8051 microcontroller

  • 1. Interfacing the Keyboard to 8051 microcontroller The key board here we are interfacing is a matrix keyboard. This key board is designed with a particular rows and columns. These rows and columns are connected to the microcontroller through its ports of the micro controller 8051. We normally use 8*8 matrix key board. So only two ports of 8051 can be easily connected to the rows and columns of the key board. When ever a key is pressed, a row and a column gets shorted through that pressed key and all the other keys are left open. When a key is pressed only a bit in the port goes high. Which indicates microcontroller that the key is pressed. By this high on the bit key in the corresponding column is identified. Once we are sure that one of key in the key board is pressed next our aim is to identify that key. To do this we firstly check for particular row and then we check the corresponding column the key board. To check the row of the pressed key in the keyboard, one of the row is made high by making one of bit in the output port of 8051 high. This is done until the row is found out. Once we get the row next out job is to find out the column of the pressed key. The column is detected by contents in the input ports with the help of a counter. The content of the input port is rotated with carry until the carry bit is set. The contents of the counter is then compared and displayed in the display. This display is designed using a seven segment display and a BCD to seven segment decoder IC 7447. The BCD equivalent number of counter is sent through output part of 8051 displays the number of pressed key.
  • 2. Circuit diagram of INTERFACING KEY BOARD TO 8051. The programming algorithm, program and the circuit diagram is as follows. Here program is explained with comments. Circuit diagram of INTERFACING KEY BOARD TO 8051. Keyboard is organized in a matrix of rows and columns as shown in the figure. The microcontroller accesses both rows and columns through the port. 1. The 8051 has 4 I/O ports P0 to P3 each with 8 I/O pins, P0.0 to P0.7, P1.0 to P1.7, P2.0 to P2.7, P3.0 to P3.7. The one of the port P1 (it understood that P1 means P1.0 to P1.7) as an I/P port for microcontroller 8051, port P0 as an O/P port of microcontroller 8051 and port P2 is used for displaying the number of pressed key. 2. Make all rows of port P0 high so that it gives high signal when key is pressed. 3. See if any key is pressed by scanning the port P1 by checking all columns for non zero condition. 4. If any key is pressed, to identify which key is pressed make one row high at a time. 5. Initiate a counter to hold the count so that each key is counted.
  • 3. 6. Check port P1 for nonzero condition. If any nonzero number is there in [accumulator], start column scanning by following step 9. 7. Otherwise make next row high in port P1. 8. Add a count of 08h to the counter to move to the next row by repeating steps from step 6. 9. If any key pressed is found, the [accumulator] content is rotated right through the carry until carry bit sets, while doing this increment the count in the counter till carry is found. 10. Move the content in the counter to display in data field or to memory location 11. To repeat the procedures go to step 2. Program to interface matrix keyboard to microcontroller 8051 Start of main program: to check that whether any key is pressed start: mov a,#00h mov p1,a ;making all rows of port p1 zero mov a,#0fh mov p1,a ;making all rows of port p1 high press: mov a,p2 jz press ;check until any key is pressed after making sure that any key is pressed mov a,#01h ;make one row high at a time mov r4,a mov r3,#00h ;initiating counter next: mov a,r4 mov p1,a ;making one row high at a time mov a,p2 ;taking input from port A jnz colscan ;after getting the row jump to check column mov a,r4
  • 4. rl a ;rotate left to check next row mov r4,a mov a,r3 add a,#08h ;increment counter by 08 count mov r3,a sjmp next ;jump to check next row after identifying the row to check the colomn following steps are followed colscan: mov r5,#00h in: rrc a ;rotate right with carry until get the carry jc out ;jump on getting carry inc r3 ;increment one count jmp in out: mov a,r3 da a ;decimal adjust the contents of counter before display mov p2,a jmp start ;repeat for check next key.