Embedded Systems Design - Module 4.2 Keypad Seven Segment PDF
Document Details
Uploaded by Ameera
University of Sharjah
Dr. Bilal Arain
Tags
Summary
This document provides an introduction to embedded systems design, focusing on digital I/O, keypads, and seven-segment displays. It includes examples, diagrams, and calculations for connecting and utilizing these components in embedded systems.
Full Transcript
Embedded Systems Design Digital I/O – Keypad and Seven Segment Display Dr. Bilal Arain Parallel I/O Ports - Example Connecting Commonly Used Peripherals Switches and LEDs are I/O devices commonly used in systems with microcontrollers Example: Three possible ways for...
Embedded Systems Design Digital I/O – Keypad and Seven Segment Display Dr. Bilal Arain Parallel I/O Ports - Example Connecting Commonly Used Peripherals Switches and LEDs are I/O devices commonly used in systems with microcontrollers Example: Three possible ways for connecting these devices to the pins in port B of a PIC microcontroller, shown in the diagram Current Sourcing When a load is connected to a device so that the device supplies current to the load then the configuration is said to be current sourcing Imagine, the device is supplying the current to the LED, as highlighted in the figure Example: LED2 is ON when with the pin RB is high. In this configuration the LED2 current leaves the pin. Current Sourcing Let us denote the supply current as I2 It is necessary that the supply current should be less than or equal to the maximum output current for the pin. That is The PIC16F877 datasheets provide the electrical characteristics PIC16F877 Electrical Characteristics Current Sourcing Question: Calculate the value of RL2 using a PIC16F877 electrical characteristics, assuming the voltage supply is VDD = 5V. The red LED forward voltage is 1.6 V and the forward current is 10 mA. Solution: The PIC16F877 datasheet electrical characteristics are as follows: VOH (Output high voltage) = 4.3 V from the PIC16F877 datasheet Current Sinking When a load is connected to a device so that current flows from the power supply through the load and into the device, then the configuration is said to be current sinking. When current flows into the device, it is said to be sinking current. Current Sinking Question: Calculate the value of RL1 using a PIC16F877 electrical characteristics, assuming the voltage supply is VDD = 5V. The red LED forward voltage is 1.6 V and the forward current is 10 mA. Solution: The PIC16F877 datasheet electrical characteristics are as follows: The output low voltage is given VOL = 0.35V for IOL = 10mA, from PIC data sheet. Current Sourcing Versus Current Sinking Sinking current into a microcontroller means that the current flows into the microcontroller's input pins and is then consumed by the internal components of the microcontroller. Usually, it is generally easier for the microcontroller to shunt sink current to ground rather than generate the sourcing current. Sourcing current can cause large voltage swings on the input which can introduce noise. Microcontrollers have an internal protection mechanism such as pull- up/pull-down resistors and clamping diodes. These are designed to help sink current into the microcontroller, further enabling them to safely handle the incoming current. Pull up and Pull down Configurations The keypad inputs are configured using either pull-up or pull-down resistors A pull-up resistor connects the input to a high voltage (Vcc), while a pull-down resistor connects it to the ground. In pull-up configuration, when a button is not pressed, the row input is pulled high (Vcc) In a pull-down configuration, when a button is not pressed, the row input is pulled down (ground) Pull-up Resistor Pull-up are more commonly used with buttons and switches than Pull-downs. They operate using the same concepts, except the pull-up resistor is connected to the high voltage (usually 5V and often referred to as VCC). The pull-down resistor is connected to ground. With a pull-up resistor, the input pin will read a high state when the button is not pressed. Pull-up Resistor When the button is pressed, it connects the input pin directly to ground. The current flows through the resistor to ground, thus the input pin reads a low state. What happens if the resistor Rk is not there? This will connect the Vcc to ground which is also knows as short. What could be the value of Rk? Pull-up Resistor The value of the pull-up resistor needs to be chosen to satisfy two conditions: 1. When the button is pressed, the input pin is pulled low. The value of resistor Rk controls how much current you want to flow from VCC, through the button, and then to ground. 2. When the button is not pressed, the input pin is pulled high. The value of the pull-up resistor Rk controls the voltage on the input pin. Pull-up Resistor When the button is pressed The lower the resistance value of Rk, the more power will be used when the button is pressed. A large resistor value of Rk may conflict with the condition when the button is not pressed. Matrix Keypads Matrix keypads allow us to read multiple buttons with minimal I/O pins Rows and columns are connected in a grid, with each button at an intersection By scanning the rows and columns, we can determine which button is pressed Useful for creating user input interfaces on embedded systems Matrix Keypads The standard 4x4-matrix keypad has 4-row lines and 4 column lines. The keypad itself is a passive component. It relies entirely on external power sources for its operation. Exploration lines Return lines Matrix Keypads Each key press closes a circuit, allowing current to flow through the appropriate path to the microcontroller or another connected device. The keypad itself does not have an internal power source—it merely acts as a pathway or switch for the current. Exploration lines Return lines Matrix Keypads The state of a matrix keypad can be explored by sending signals through its rows (exploration lines) and reading the information received through its columns (return lines). When none of the keys is pressed, all return lines will have logic _________. Exploration lines Return lines Matrix Keypads Explore the matrix keypad to determine the key that was pressed. We sequentially explore the rows, meaning we cycle the rows by sending high logic in a pattern (0001, 0010, 0100, 1000). Each time a row line is driven HIGH (see the pattern), the column lines are read sequentially to detect a key press. Exploration lines Return lines Matrix Keypads Row 1 RD4 Row 2 RD5 Row 3 RD6 Row 4 RD7 Column 1 RD0 Column 2 RD1 Column 3 RD2 Column 4 RD3 Matrix Keypads Example: Button2 on row 1 is pressed. Your program determines the meaning of Buttton2 row1 is pressed. 1 0 0 0 0 1 0 0 PIC16F877 Matrix Keypads What happens when the button is pressed other than the active row? No button in Row 1 is pressed. It depends on which row is active. What should be the scanning 1 0 0 0 pattern in the pull-up 0 0 0 0 configuration? PIC16F877 Seven Segment Display Seven Segment Display