Electronic Design

  
Reprints     Printer-Friendly    Email this Article    RSS        Font Size     What's This?


[Ideas For Design]
Connect any keyboard with any microcontroller using only one pin

Contributing Author  |   ED Online ID #6303  |   May 1, 1998


After “Use A Tiny Microcontroller With A Large Keypad” was published (ELECTRONIC DESIGN, Sept. 2, 1997, p. 166), I got a number of responses that prompted me to develop a corollary design. Presented here is a design applicable to microcontrollers not equipped with a built-in ADC.

Looking at the figure, you’ll notice a familiar 4x4 keypad with a single difference —each row and column are separated by a resistor. If key #1 is pressed, the resistance between nodes A and B (R1AB) is equal to 1.5*R; for key #2—R2AB = 1.5*R+R = 2.5*R; and so on ... key #N—RNAB = N.5*R. This variable resistor network is connected to a 555 timer (CMOS version), configured as an oscillator with the period of oscillation equal to T = 1.4*RAB*C, directly proportional to RAB.

The oscillator runs only when a key is pressed, causing an interrupt request for the microcontroller. The INT0 pin is set up as edge-sensitive. The general algorithm can be described as: 1) after detecting the edge on the INT0 pin, wait 20 ms to eliminate ringing; 2) detect the next edge and start the internal timer; 3) the following edge stops the internal timer. The measured period (the time between two consecutive positive edges) will define the key number. Any microcontroller with a built-in timer (the vast majority of microcontrollers) can implement this idea.

For a specific example, I will use the 8051-family microcontroller with a 12-MHz clock. In this situation, the single count of the timer will be 1 µs. If we choose 47 nF for the capacitor and 3.9 kΩ as the resistor value, we will have T = 1.4*R*C = 256.6 ≈ 256 µs. That is the period difference between oscillations produced by two serial keys. After calculating the period interval produced by any key pressed, we need only to make integer division by 0xFF (25610) to get the key number of the depressed key. The value for R1 =1.5*R is chosen to provide the highest error margin for the elements by moving the period value in the middle of two consecutive numbers.

Some possible sources of errors in this application are: 1) component tolerances; 2) 256.6 µs instead of 256 for 1% resistors; 3) the closest value to 4*R, if R = 3.9k, will be 15.4K or 15.8K instead of the calculated 15.6k., an additional 1% error for each following column; 4) the 555 oscillator inaccuracy—temperature drift of 75 ppm/C° and variation 0.03% for a power-supply variation of ±0.1 V.


Reprints   Printer-Friendly  Email this Article  RSS    Font Size   What's This?


  • 45-nm Via-Programmable ASICs Add High-Speed I/O Transceivers To Feature Mix
  • Verification Evolves Into Lean, Mean Bug-Stomping Machines
  • User Advisory Group To Guide Open Verification Methodology’s Evolution
  • DDR3 and DDR2 Memory IP Bolsters SoC Designs
  • PCB Tools Cross-Probe Between Layout And Schematic
  • Constraint-Driven Flow Targets PCB High-Density Interconnects
  • Cadence Abandons Its Bid To Buy Mentor Graphics
  • Model Extractor For CMOS Sports Improved RF/DC Parameters
    1) Barbers, Adaptability, And Electric Pickup Trucks
    (743 views today)
    2) Low-Dropout (LDO) Linear Regulators
    (459 views today)
    3) Build A Smart Battery Charger Using A Single-Transistor Circuit
    (414 views today)
    4) SDR Transforms Amateur Radio
    (226 views today)
    5) Easily Convert Decimal Numbers To Their Binary And BCD Formats
    (222 views today)
    ALL TOP 20



    Reader Comments

    sir/madam, Am very urgent to interface a keyboard(4x4) with a normal lcd using c.The keypads are arranged as follows.. 1 2 3 left arrow 4 5 6 up arrow 7 8 9 down arrow esc o dot enter Can u plz help me to do tiz??? Very urgent..

    Divya -August 25, 2008

    i want to directly connect my normal PC keyboard to a microcontrolle 80C51 which is used for moving LED message display. please help me. please send data sheet of any ic that nterface my keyboard to microcontoller 80c51. is it not available in kerla, please take any action for get it. i need assebly language program and C progran for use it as a ascii Keyboard interfase. l hope u reply immediately. can u give it with in march 10. its very urgend. please help me

    cibinsreedhar -March 01, 2008

    I want to use normal keyboard of my PC to send stream of characters to 8051 or 89c51 micro controller which will display on dot matrix or 'alphanumeric character display'. Please help me. Not hesitate to answer me. i need to write a programme in c language as well as in assembly language

    Anonymous -January 16, 2008

    hello this is mahipal and have a dout as whether the keyboard is having any controller...and it is embedded device

    is keyboard have avy controller -August 10, 2007

    hello everyone.

    I require a variable potentiometer that is operated with a keypad, rather than the usual knob.

    The ED Online ID #6303 is quite similar, but a keypad would be able to provide more gradual and controllable variance.

    Kevin -July 15, 2007

    i wanna interface a standard 104 keys keyboard used for pc to the 89c51

    kindly help with the circuit layout and a bit of programming algos...

    i cant figure out how to make the keyboard compatible to the 8051

    what output does the keyboard give... ASCII values???

    krishna -April 02, 2007

    i have to write a code using embedded c to interface a 4x4 keypad using a microcontroller...i think 80s52... here i need to address issues like key jamming...key rollover...key debounce... i am told to use keil...which i am finding dificult... can you help me out here... do u have some sort of basic code for this on which i can improvise..

    aditya -March 20, 2007

    I am very interested in writing code in C with uC 8051 but now i am using AT89C52. Have you written code or an algorithm to your "Connect Any Keypad with Any Micro controller Using Only One Pin”?

    Thank You.

    Bc -January 17, 2007

    sir, i need to write a programme in c language for 8051 mcu interfaced with lcd,keyboard,and led i have got the code for interfacing the lcd and led but iam struggling with key board interface programme.how can i sort out the problem.how can the keypad could be initailsed and how can it can recognise when the key is pressed.

    praveen -November 21, 2006   (Article Rating: )

    This is one heck of an idea!!! Incredible. A pity that you did not mention any code here, but still I get the general idea. I'm going to try this one out. My teacher at college wanted a few of us to make an interface of a matrix keyboard to an 8051 and if this works, I'll be saving about 4-8 pins!!! Wonderful.

    In fact, this is a perfect example on how to use interrupts well.

    GREAT WORK!!

    Jabbar SharpEyes -October 31, 2006   (Article Rating: )

    hi I want to connect 8051 to printer. Please help me to do this. thank you so much.

    Anonymous -October 12, 2006

    I want to build a supercomputer that will control a fleet of intergalactic space ships. I want a matrix keypad to control the computer. will you design and build the computer, and fleet of ships for me, and then send me the plans because i dont want to actually do any work please??

    seriously though, great approach for saving pins.

    Sumgye -September 23, 2006   (Article Rating: )

    I want to build a supercomputer that will control a fleet of intergalactic space ships. I want a matrix keypad to control the computer. will you design and build the computer, and fleet of ships for me, and then send me the plans because i dont want to actually do any work please??

    seriously though, great approach for saving pins.

    Sumgye -September 23, 2006   (Article Rating: )

    hello sir i want to make a power supply having 3*5 keypad. means if i pres 1 it should display on lcd 1. if i press 12.5 it should display like this. can any one help me to give some ideat abt it. i am writing my code in c

    arti dwivedi -August 22, 2006

    I'm looking for a simple keypad circuit (4x4 or 3x4). to enter numeric values to the 8051. any one can help me???

    Anonymous -July 06, 2006

    I want to use normal alpha-numeric keyboard of my PC to send stream of characters to 8051 micro controller. Please help me. Not hesitate to answer me.

    Muhammad Ahmed -June 03, 2006

    I want to use normal alpha-numeric PC- Keyboard to send streams of characters to 8051 micro controller. Is it possible??? Please help me to write code in c for this. I have scan set 2. Will this give me benifit???

    Anonymous -June 03, 2006   (Article Rating: )

    i have problem to choose one ic that connect keypad to 8515 microcontroller

    Anonymous -May 14, 2006

    I connect an at keyboard(PC) to 8051, using 2 wires: data(p10) and sck (p32_ex0) the code is below here when any key is pressed, i get the code of that key but programing don't exit the interupt Could you help me? org 0 ljmp main

    org 0003h ljmp ex0isr

    main: mov ie, #81h setb it0

    loop: inc p0 lcall delay mov r0, p0 cjne r0, #255, loop mov p0, #0 sjmp lap

    ;The interrupt ex0isr: clr ex0 mov r1, #8

    nhan12: jnb p3.2, nhan12 ;pass start bit nhan13: jb p3.2, nhan13

    nhan2: jnb p3.2, nhan2 ;wait ck edge nhan3: jb p3.2, nhan3 mov c, p3.1 rrc a ;get LSB djnz r1, nhan2 mov p2, a ;p2 display the keycode

    nhan4: jnb p3.2, nhan4 nhan5: jb p3.2, nhan5 ;pass parity bit

    nhan6: jnb p3.2, nhan6 nhan7: jb p3.2, nhan7 ;pass stop bit

    setb p3.0 setb p3.2 ; lcall delay setb ex0 reti

    delay: mov r7, #255 nhan8: mov r6, #255 nhan9: djnz r6, nhan9 djnz r7, nhan8 ret end

    Nguyenhop -February 17, 2006

    I have a program in assembly tat scans 4x4 keypad which can be conected to a sengle port. A number of different scannong sub routines are there. It helps in selecting different types of scan.

    Rejith -January 13, 2006

    i want a program for interfacing keyboard with microcontrolle 8051, the keyboard having two keys for up down counting

    Anonymous -January 01, 2006   (Article Rating: )

    Quote: I want to know if an alphanumeric keypad can be interfaced to the microcontroller with this fashion because there we have to note down the number of times the key is pressed since for ex a key may represent 1, a, b, c. If pressed once, it's 1 next it's a and so on. How to tackle this? ---

    I'd like to know how to solve this problem too.

    Luis A.

    LA -September 21, 2005

    Very useful! Thank u!

    CAO NAM -September 08, 2005   (Article Rating: )

    I'm looking for a simple keypad circuit, I'm building an alarm and I need to a keypad (matrix 4x4) circuit to enter the password. I need 4 digits circuit. Does anybody know where I can find one???

    Gustavo -August 01, 2005

    comments same as suma i am using keil but am finding it difficult to prog some what

    zaheer -May 28, 2005   (Article Rating: )

    I want to know if an alphanumeric keypad can be interfaced to the microcontroller with this fashion because there we have to note down the number of times the key is pressed since for ex a key may represent 1, a, b, c. If pressed once, it's 1 next it's a and so on. How to tackle this?

    Suma -January 22, 2005   (Article Rating: )

    I am very interested in writing code in C with uC 8051. Have you written code or an algorithm to your "Connect Any Keypad with Any Micro controller Using Only One Pin”? It will be great help to me if you show your code because I am no voice in programming the 8051.

    Regards Salam

    Salam -August 21, 2004

    POST YOUR COMMENTS HERE
    Name:

    Email:
    Your Comments:

    Enter the text from the image below


    Please refresh the page if you have trouble reading this text.

    Search Electronic Design
         
      
     
    Web Seminar
    Sponsored By:
    Title: Read Pacing: A Performance Enhancing Feature of PCI Express Gen 2 Switch Devices
    Speakers: 
    Date: 07/01/08
    Register: 

    Electronic Design Europe Electronic Design China EEPN Power Electronics Auto Electronics Microwaves & RF RF Design
    Schematics Find Power Products Military Electronics Featured Vendors EE Events Free Design Resources