10/24/2015 Amrita Vishwa Vidyapeetham 1 Key Board & LED Interfacing.

Slides:



Advertisements
Similar presentations
INPUT-OUTPUT ORGANIZATION
Advertisements

1 ECE 372 – Microcontroller Design Parallel IO Ports - Outputs Parallel IO Ports E.g. Port T, Port AD Used to interface with many devices Switches LEDs.
Week10 Boolean Instructions on the Boolean Instructions  Boolean (or Bit) addressable capability is unique to the 8051  Enables efficient handling.
FPGA Configuration. Introduction What is configuration? – Process for loading data into the FPGA Configuration Data Source Configuration Data Source FPGA.
8051 I/O Interfacing Need for more ports PPI 8255
Programmable Interval Timer
Lab 09 :D Flip Flop, Shift Registers and Switch Bounce: Slide 2 Slide 3 The D Flip Flop. 4-Bit Shift Register. Slide 4 Shift Register De-bounce System:
kashanu.ac.ir Microprocessors 6-1 I/O Devices Switches, LED, LCD Lec note 6.
TK2633 Introduction to Parallel Data Interfacing DR MASRI AYOB.
Input/Output (I/O) Ports and Interfacing
Input/Output Ports and Interfacing ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
Switch Debouncing. Switches connected to sources of constant logic 0 and 1 are often used in digital systems to supply “user inputs”. In high speed digital.
Microprocessor and Microcontroller
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Debouncing Switches Mechanical switches are one of the most common interfaces to a uC. Switch inputs are asynchronous to the uC and are not electrically.
P Address bus Data bus Read-Only Memory (ROM) Read-Write Memory (RAM)
Railway Foundation Electronic, Electrical and Processor Engineering.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Railway Foundation Electronic, Electrical and Processor Engineering.
Digital Outputs 7-Segment Display
Digital I/O Connecting to the Outside World
Embedded Systems Design 1 Lecture Set B Interfacing the MCS-51 to: –7 and 16 segment displays –a Multiplexed 7-Segment Display –a Keypad –an LCD.
Lecture – 7 Basic input and output
Group 7 Jhonathan Briceño Reginal Etienne Christian Kruger Felix Martinez Dane Minott Immer S Rivera Ander Sahonero.
INPUT-OUTPUT ORGANIZATION
Khaled A. Al-Utaibi  8086 Pinout & Pin Functions  Minimum & Maximum Mode Operations  Microcomputer System Design  Minimum Mode.
1 © Unitec New Zealand Embedded Hardware ETEC 6416 Date: - 10 Aug,2011.
UNIT 8 Keypad Interface Contact Closure Counter Exceptions (Interrupts and Reset)
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
A Simple Tour of the MSP430. Light LEDs in C LEDs can be connected in two standard ways. Active high circuit, the LED illuminates if the pin is driven.
Parallel Ports, Power Supply and the Clock Oscillator Material to be covered  Parallel I/O ports  Interfacing external switches and LEDs  Clock Oscillator.
Industrial Process Control System Simon Hui Engineer Control and Informatics, Industrial Centre.
Dr. Rabie A. Ramadan Al-Azhar University Lecture 6
Input/Output Ports and Interfacing
16F877A. Timer 0 The Timer0 module timer/counter has the following features: –8-bit timer/counter –Readable and writable –8-bit software programmable.
Chapter 4 TIMER OPERATION
The 8253 Programmable Interval Timer
MICROPROCESSOR INPUT/OUTPUT
I/O devices Peripheral devices (also called I/O devices) are pieces of equipment that exchange data with a CPU Examples: switches, LED, CRT, printers,
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
One of the most important feature of the microcontroller is a number of input/output pins used for connection with peripherals. In the case of PIC 167CX,
COMP3221: Microprocessors and Embedded Systems Lecture 18: Computer Buses and Parallel Input/Output (II) Lecturer: Hui.
Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”
Memory Layout and SLC500 System Addresses. Processor Memory Division An SLC 500 processor's memory is divided into two storage areas. Like two drawers.
Eng.Samra Essalaimeh Philadelphia University 2013/ nd Semester PIC Microcontrollers.
8279 KEYBOARD AND DISPLAY INTERFACING
ECE 448: Spring 11 Lab 3 Part 1 Sequential Logic for Synthesis.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
Chapter 2 Introducing the PIC Mid-Range Family and the 16F84A The aims of this chapter are to introduce: The PIC mid-range family, in overview The overall.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs.
12/16/  List the elements of 8255A Programmable Peripheral Interface (PPI)  Explain its various operating modes  Develop a simple program to.
PPI-8255.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
8279 KEYBOARD AND DISPLAY INTERFACING
Interfacing to External Devices  Explore Digital Interfaces techniques  Introduce some complex optical devices and how to interface them  Describe methods.
Parallel I/O. Introduction This section focuses on performing parallel input and output operations on the 68HC11 3 operation types – Simple, blind data.
EE365 - Microprocessors period 26 10/23/00 D. R. Schertz # Parallel Ports.
Lecture 4 General-Purpose Input/Output NCHUEE 720A Lab Prof. Jichiang Tsai.
Chapter 12 Some PIC Microcontroller Advances The aims of this chapter are to introduce: To introduce in overview two microcontrollers which show some enhanced.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Mark Neil - Microprocessor Course 1 Decoding and Using a 4x4 Keyboard.
ECE 447: Lecture 12 Keypads ECE 447: Lecture 10. ECE 447: Matrix Keypad.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
KEYBOARD/DISPLAY CONTROLLER - INTEL Features of 8279 The important features of 8279 are, Simultaneous keyboard and display operations. Scanned keyboard.
Special Features. Device Configuration bits Revision Device Configuration bits Revision On-chip Power-on Reset (POR) Revision On-chip Power-on Reset (POR)
16F877A.
Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.
Presentation transcript:

10/24/2015 Amrita Vishwa Vidyapeetham 1 Key Board & LED Interfacing

10/24/2015 Amrita Vishwa Vidyapeetham 2 External World Interfacing The peripheral now to be discussed – Key Board Typical application of weak pull-ups A key is the simplest mechanical device that can be interfaced to a μC. Depending on the number of keys to be interfaced and the type of application, different approaches to interface are available.

10/24/2015 Amrita Vishwa Vidyapeetham 3 Key – On/Off Bounce Period ~ 20 ms

10/24/2015 Amrita Vishwa Vidyapeetham 4 Key - Bounce / Debounce A key is a mechanical device with spring action. When a Key is pressed, it may take a few ms to settle to the ON state. In the interim period, the contact may be made and broken repeatedly due to the vibration of the moving mechanism. When released, it reverts to the OFF state after a similar period of vibration. The duration of bounce and the high frequency of vibration associated with it depend on the key structure. The status of the key is not clearly defined during the bounce duration. The key can be ‘debounced’ (the effect of bounce nullified) in two ways - hardware or software

10/24/2015 Amrita Vishwa Vidyapeetham 5 Hardware Debounce - 1

10/24/2015 Amrita Vishwa Vidyapeetham 6 Hardware Debounce - 1 The RC time constant can be of the order of 5 ms to filter out bounce generated voltage spikes. When the key is pressed, the voltage at point X increases from 0V to 5V smoothly. The buffer B has threshold voltages for the up and down transitions Y changes to high state (from the earlier low state) when the voltage at X crosses the threshold. The debounce circuit behavior is similar for the transition from high to low state.

10/24/2015 Amrita Vishwa Vidyapeetham 7 Hardware Debounce - 2 Debouncing can be done by employing a simple RS latch. The latch is normally in the reset state. When the key is pressed, the latch changes to set state; output Q changes from low to high state. The instant of transition is decided by the first spike at input which is wide enough to make the latch set. Once the latch is set, it remains in set state even after the key is released. The μC has to reset it by applying a high state pulse at R; it is to be done with a reasonable time gap of about 1s after key closure.

10/24/2015 Amrita Vishwa Vidyapeetham 8 Software Key Debounce The debounce is handled by the software program Usually a delay period is assumed over which the level of the key press signal should not change

10/24/2015 Amrita Vishwa Vidyapeetham 9 4x3 Keypad

10/24/2015 Amrita Vishwa Vidyapeetham 10 4x3 Key Pad In this particular example there are 12 switches Rather than use up all these scarce I/O pins it is hardware efficient to connect these switches in the form of a 4×3 matrix Without matrix – 12 I/O pins are required With matrix, total I/O pin count is 7. Larger keypads show an even greater efficiency gain, with a 64-contact 8 × 8 keyboard needing only 16 I/O pins.

10/24/2015 Amrita Vishwa Vidyapeetham 11 Working of 4x3 Key Pad The four rows are read in via RB7:4 with internal pull-up resistors enabled. The three columns connected to RB1:3 can be individually selected in turn by driving the appropriate pin low, thus scanning through the matrix. This is called key board scanning. The switch contacts are normally open and, because of the pull-up resistors, read as logic 1. When a switch connected to a low column line is closed then the appropriate row line is low. Once the closed key row has been detected the column : row intersection is known (i.e. the key that is pressed is identified).

10/24/2015 Amrita Vishwa Vidyapeetham 12 Key Pad Subroutine Let us write subroutine SCAN_IT for scanning a Key Pad. SCAN_IT initializes the column count key to 1 and the column scan pattern to b. This test vector is sent to Port B and each row is tested in turn adding 3, 6 or 9 to the value of key if a zero is found and loop is exited (break). If after the four rows have been tested no outcome has been detected, the column scan pattern is shifted right and key is incremented. The process is continued until either a 0 is found or count reaches 13. In the latter case a key value of FFh (−1) is returned.

10/24/2015 Amrita Vishwa Vidyapeetham 13 Algorithm for SCAN_IT subroutine 1. Two global variables KEY_COUNT, PATTERN 2. Key 1 is the first key 3. Set initial KEY_COUNT = 1 4. Set initial PATTERN = b’ ’ 5. Start a loop – SLOOP 6. Output PATTERN to PORTB 7. Move KEY_COUNT to W 8. Check ROW1 - RB7 9. IF zero THEN found the key, exit the subroutine with Key identifier, ELSE increment KEY_COUNT by Check ROW2 – RB6 11. IF zero THEN found the key, exit the subroutine with Key identifier, ELSE increment KEY_COUNT by Check ROW3 – RB5 13. IF zero THEN found the key, exit the subroutine with Key identifier, ELSE increment KEY_COUNT by Check ROW4 – RB4 15. IF zero THEN found the key, exit the subroutine with Key identifier, ELSE increment KEY_COUNT by If no closed key, W = Advance KEY_COUNT one column 18. Shift (right) scan pattern once -> 19. Check - has the 0 reached RB0? 20. IF not DO another column. Go to SLOOP 21. IF yes, return with KEY_COUNT in W

10/24/2015 Amrita Vishwa Vidyapeetham 14 Flow chart SCAN_IT KEY_COUNT = 1 PATTERN = b’ O/P PATTERN to PORTB W = KEY_COUNT RB7 = 0 RB6 = 0 RB5 = 0 RB4 = 0 W = h’FF KEY_COUNT + 1 PATTERN >> 1 RB0 = 0 W = W + 3 KEY ID = W a a Yes No Yes No W = W + 3

10/24/2015 Amrita Vishwa Vidyapeetham 15 Real World Issues In the real world a subroutine like this would often read in rubbish due to switch bounce Also possibly noise induced in the connections between keypad and the electronics. One way of filtering out this unpredictability is debounce subroutine – S/W Here the state of the keypad is interrogated using the SCAN_IT subroutine of Program By keeping the state of the previous reading in Data memory, any change can be detected. Only if no change over 256 readings occurs will subroutine GET_IT return with the keypad state. Depending on the quality of the keypad, ambient noise and processor speed, the outcome can be improved at the expense of response time by including a short delay in the loop, or by using a 2-byte stability count.

10/24/2015 Amrita Vishwa Vidyapeetham 16 Keypad Subroutine with debounce GET_IT keeps a number of tries count tally, last reading OLD_KEY and current reading NEW_KEY variables. COUNT is incremented after calling SCAN_IT if the current reading is the same as the last reading. If not, COUNT is reset and OLD_KEY is updated. The loop exits if count reaches 255 (8-bit register), indicating that the last 255 readings are the same.

10/24/2015 Amrita Vishwa Vidyapeetham 17 Algorithm for GET_IT subroutine 1. Three global variables COUNT, NEW_KEY, OLD_KEY 2. Initial value of OLD_KEY& NEW_KEY is Zero 3. Initial value of COUNT is zero. 4. Call the subroutine SCAN_IT 5. Raw value returned in W is moved to NEW_KEY 6. Check if NEW_KEY = OLD_KEY 7. IF same go to STEP 9 ; 8. ELSE the readings are different, so: Make OLD_KEY = NEW_KEY and start all over again. Go to STEP 3 9. IF readings are the same THEN Increment COUNT 10. IF not rolled around to 00 repeat ELSE we got the key identifier.

10/24/2015 Amrita Vishwa Vidyapeetham 18 Flow Chart GET_IT NEW_KEY = 0 OLD_KEY = 0 COUNT = 0 CALL SCAN_IT NEW_KEY = W NEW_KEY = OLD_KEY COUNT = COUNT + 1 OLD_KEY = NEW_KEY COUNT = 0 Yes No Yes No KEY_ID = OLD_KEY

10/24/2015 Amrita Vishwa Vidyapeetham 19 Seven Segment LEDs

10/24/2015 Amrita Vishwa Vidyapeetham 20 Multiplexing 7 Segment Displays - 1

10/24/2015 Amrita Vishwa Vidyapeetham 21 Multiplexing 7 Segment Displays - 1 Assuming each display requires eight lines (seven segments plus decimal point) then a budget of 8 × n parallel lines are required for an ndigit display. The straightforward solution to this problem - a 3-digit display is driven from three parallel registers on a single bus. The principle can be extended to six or more digits using the appropriate number of registers.

10/24/2015 Amrita Vishwa Vidyapeetham 22 Multiplexing 7 Segment Displays - 2

10/24/2015 Amrita Vishwa Vidyapeetham 23 Multiplexing 7 Segment Displays - 2 An alternative approach, is frequently used with LED-based displays. Instead of using a register for each digit, all readouts are connected in parallel to the one PIC port. Each readout is enabled in turn for a short time with the appropriate data from the output port. Provided that the scan rate is greater than 50 per second (preferably greater than 100) the brain’s persistence of vision will trick the onlooker into visualizing the display as flicker free. Of course this is how the brain interprets a series of 24 still frames per minute in a movie, each shown twice, as a moving image.

10/24/2015 Amrita Vishwa Vidyapeetham 24

10/24/2015 Amrita Vishwa Vidyapeetham 25

10/24/2015 Amrita Vishwa Vidyapeetham 26

10/24/2015 Amrita Vishwa Vidyapeetham 27

10/24/2015 Amrita Vishwa Vidyapeetham 28

10/24/2015 Amrita Vishwa Vidyapeetham 29 DD uring normal operation, a WDT time-out generates a device RESET. II f the device is in SLEEP mode, a WDT time-out causes the device to wake-up and continue with normal operation, this is known as a WDT wake-up. TT he WDT can be permanently disabled by clearing the WDTE configuration bit. TT he postscaler assignment is fully under software control,

10/24/2015 Amrita Vishwa Vidyapeetham 30 WDT Period TT he WDT has a nominal time-out period of 18 ms, II f longer time-outs are desired, a postscaler with a division ratio of up to 1:128 can be assigned TT hus, time-out periods of up to 2.3 seconds can be realized. TT he CLRWDT and SLEEP instructions clear the WDT and the postscaler (if assigned to the WDT). aa nd prevent it from timing out and generating a device RESET. TT he TO bit in the STATUS register will be cleared upon a Watchdog Timer time-out (WDT Reset and WDT wake-up). ***********************************************************