SlideShare a Scribd company logo
1 of 28
Lecture 01
Article 8.5 – 8.6
Input-Output Interfacing for LED and Switch
• The TM4C123 microcontroller platform has three on
board color LEDs (red, green and blue) and two switches
for simple input output interfacing.
• Both LEDs and switches are interfaced as digital devices.
• In the following, we will learn to interface each of these
two different types of devices.
• LEDs will be interfaced using GPIO pins as digital outputs
and switches will be connected by configuring the GPIO
pins as digital inputs.
• From Figure 8.10, we observe that the LEDs are
connected using digital NPN transistors.
• A digital transistor is the one that integrates the base
(bias) resistors inside the transistor package. Unlike an
ordinary transistor, a digital transistor operate in only two
states, off and saturation.
Input-Output Interfacing for LED and Switch
Working of a switch:
• This is true because, when the switch is pressed, logic low will be applied to
the GPIO port pin connected to the switch. However, when the switch is
released, there is no source (or supply) connection to ensure logic high
appears at the GPIO port pin.
• The switch interfacing shown in Figure 8.10 is not complete. With simple
microcontrollers, the switch interface of Figure 8.10 might not work properly.
• However, in case of TM4C123 the above-mentioned problem is resolved by
using the internal pull-up resistor.
• When the internal pull-up resistor is enabled, it pulls the GPIO pin to logic
high when the switch is in released state.
• The internal pull-up resistor values are in general larger than 10kQ. Since the
current drawn by the GPIO port pin, when configured as input, is so low that
the voltage drop across the pull-up resistor is almost negligible and voltage
level, approximately equal to the supply voltage, appears at the GPIO pin,
which is translated as logic high by the internal logic.
Input-Output Interfacing for LED and Switch
• A second option, different from the one shown in Figure 8.10, is to change
the switch terminal connection from ground to supply (Vcc).
• For this case we need to enable internal pull-down resistor for proper switch
functioning.
• In this case, logic high will be read by the user program, when the switch is
pressed.
8.5.1: Output Interfacing for LED
For LED interfacing we need to configure Port F pins 1, 2 and 3 as outputs. The basic steps to
configure the required Port F pins are given below.
1. Enable the clock to the GPIO port.
2. Select the general purpose IO functionality by clearing the alternate function select register
(GPIOAFSEL).
3. Configure the GPIO direction for digital output function.
4. Configure the PAD for the digital operation.
8.5.1: Output Interfacing for LED
//Initializations ()
#define SYSCTL_RCGC2_R Address
# define GPIO_PORTF_DEN_R Address
# define GPIO_PORTF_DIR_R Address
# define GPIO_PORTF_Data_R Address
//User defined variables:
# define SYSCTL_RCGC2_GPIOF 0 x0020
# define SYSTEM_CLOCK_FREQUENCY 16000000 // Default clk
# define DELAY_VALUE SYSTEM_CLOCK_FREQUENCY /80
# define GPIO_PORTF_PIN3 0x08
8.5.1: Output Interfacing for LED
• It is important to notice that the GPIO_PORTF_DATA_R register is defined as
0x40025020, which gives access to Port F pin 3 only. This allows us to perform write
operation directly in one step to toggle the LED. The LED toggling is implemented in a
loop with delay. The delay itself is implemented using a loop operation.
• In the above C program, we can observe that the configuration steps are implemented
using read-modify-write procedure.
• Same startup.s file is also required to build the executable for the C program based
implementation
8.5.2 Input Interfacing for Switch
• Mechanical switches are commonly used to feed any parameters to the
digital systems.
• The switches can be interfaced to a microcontroller using digital inputs.
• The software program for switch interfacing can be implemented using one
of the following two methods.
• Polling Based: In case of polling based method the GPIO pin connected
with the switch is polled frequently enough, in the software, to avoid
missing any key presses.
• Interrupt Based: In this method the GPIO pin is configured as an external
interrupt and any key press leads to an interrupt. The edge triggering of the
interrupt can be configured on rising or falling edge, depending on the
switch hardware connectivity.
8.5.2 Input Interfacing for Switch
• Before we proceed further, it is important to first familiarize our
self with the switch physical behavior.
• Next we describe the switch bouncing, which is one of the
critical attributes of its physical behavior.
• Electrical switches that use mechanical contacts to close or
open a circuit are subject to bouncing of the contacts
• Switch contacts are usually made of springy metals. When the
contacts strike together, their momentum and elasticity act
together to cause them to bounce one or more times before
making steady contact.
• It results in a pulsating electric signal instead of a clean
transition.
• For a microcontroller GPIO pin configured as input, this switch
bouncing can be interpreted as multiple switch presses.
• Figure 8.11 shows the bouncing of a switch with normally open
contact and is captured using digital storage oscilloscope.
8.5.2 Input Interfacing for Switch
• Both hardware as well as software solutions exist to get around the switch bouncing
problem.
Hardware solution:
• Analog filtering using an RC delay to filter out the rapid changes in switch output can be used
as hardware solution.
• The design task is to choose R and C such that the input threshold is not crossed while
bouncing is still occurring.
Software solution:
In case of software solution to the switch bouncing problem, at the beginning of polling the
switch is checked for being pressed.
If the switch is detected as pressed, then a delay (corresponding to switch denouncing interval)
is inserted and the switch is checked again for being pressed.
If the switch is detected as pressed again, we declare that the switch is pressed.
The rate at which the switch should be polled has to be fast enough that no switch press is
missed, i.e., the time gap between two consecutive switch presses is larger than the scan cycle
duration.
Switch Interfacing Illustration
• There are two user switches on TM4C123 evaluation board
• User switch labeled SW1 is connected to Port F pin 4 (abbreviated as PF4), while the
second switch SW2 is connected to Port F pin 0 (PF0).
• In the following, we will describe the configuration steps required for interfacing
switch SW1. The basic configuration steps are similar to the LED interfacing, with the
exception of port pin direction configuration, as listed below:
1. Enable the clock to the GPIO port.
2. Select the general purpose IO functionality by clearing the alternate function
select register (GPIOAFSEL).
3. Configure the GPIO direction for digital input.
4. Configure the PAD for digital operation.
5. In addition, enable the internal pull-up resistor by setting the corresponding bit of
GPIOPUR register.
This is required for proper functioning of the switch, as no external pull-up resistor
is placed on the board.
Switch Interfacing Illustration
• The C program illustration for interfacing the switch using polling method is provided in Example
8.4.
• The implementation is such that on every switch press an on board LED (green color) connected
to PF3 will be toggled, which helps to visualize the proper functioning of the switch.
• The LED toggling on switch press can be implemented in two different ways.
• One possible approach is to toggle the LED, as soon as the switch is pressed and the next toggling
of the LED only happens once the switch is first released and then pressed again. This approach
can be termed as edge based LED toggling.
• In the second approach, if the switch is pressed then the LED is toggled and the next LED toggling
happens after some predetermined delay if the switch is still pressed. This approach can be
termed as level based LED toggling.
Switch Interfacing Illustration
//Initializations ()
#define SYSCTL_RCGC2_R Address
# define GPIO_PORTF_DEN_R Address
# define GPIO_PORTF_DIR_R Address
# define GPIO_PORTF_Data_RD Address
# define GPIO_PORTF_Data_WR Address
# define GPIO_PORTF_PUP_R Address
//User defined variables:
# define SYSCTL_RCGC2_GPIOF 0 x0020
# define SYSTEM_CLOCK_FREQUENCY 16000000 // Default clk
# define DELAY_VALUE SYSTEM_CLOCK_FREQUENCY /80
# define GPIO_PORTF_PIN3 0x08
# define GPIO_PORTF_PIN4 0x10
# define DEALY_DEBOUNCE SYSTEM_CLOCK_FREQUENCY /1000
Switch Interfacing Illustration
Switch Interfacing Illustration
Switch Interfacing Illustration
• The value of the constant DEALY_DEBOUNCE depends on the switch characteristics. For many
switches a debouncing delay of few milliseconds would be sufficient.
• If the flag variable is not used by the program, then the resulting implementation will be
equivalent to level based LED toggling.
8.6 Seven-Segment LED Interfacing
• The seven-segment display is one of the widely used displays that can display
decimal, hexadecimal and in some cases special characters.
• Each of the seven LEDs in the display is called a segment, since when it is
illuminated, it constructs a segment of the digit, to be displayed.
• The eighth LED is used for the indication of a decimal point, (DP) and is used
when two or more seven-segment displays are put together to display larger
numbers.
• Each of the seven LEDs in the segment is assigned a label from a through g
based on its position in the segment.
• In addition, one of the LED pins is brought out of the package for external
connection, while all other terminals of the LEDs are connected together
internally and brought out as single common pin. The common pin is also used
to identify the type of the seven-segment display as common anode or common
cathode
8.6 Seven-Segment LED Interfacing
Common cathode:
In this display type, all cathode terminals of the LED
segments are joined together and are connected to
logic low or ground. While based on the number to
be displayed a collection of individual segments are
illuminated by applying logic high though a current
limiting resistor.
Common anode: In this display type, the
connections are reversed. The common terminal is
of anode type and is connected with logic high, while
individual segment pins are connected to logic low
selectively based on the desired digit to be
displayed.
8.6 Seven-Segment LED Interfacing
8.6 Seven-Segment LED Interfacing
8.6 Seven-Segment LED Interfacing
8.6.1 Time Multiplexing
• Although it is possible to drive each segment of a multi-digit seven-segment
display individually with its own dedicated GPIO pins, but the number of port pins
required, becomes impractical when more than a few seven-segment displays are
involved.
• In an n-digit time display is required and every segment is interfaced separately
to the microcontroller then the number of GPIO pins required is 7n (or 8n in case,
dot point is also used).
• To reduce the required number of GPIO pins, it is quite common to use a
multiplexed (specifically time multiplexed) display architecture.
• In a time multiplexed display, each seven segment element is driven individually
at a time, but due to the persistence of vision, it appears to the viewer that the
entire display is continuously active.
8.6 Seven-Segment LED Interfacing
• In an n-digit time multiplexed display, n GPIO pins for digit selection and
seven GPIO pins for each of the seven segments (or eight GPIO pins in case,
dot point is also used) are required.
• The resulting total number of GPIO pin connections required is equal to n+
7 (or n + 8).
• It should be realized that for time multiplexed display each segment is only
activated for time fraction of the total display refresh cycle duration.
• To avoid any flickering effect, the refresh frequency used is approximately
50 Hz in practice.
• The PNP transistors are used as a switch with the common anode terminals
of the display for turning ON one digit at a time.
8.6 Seven-Segment LED Interfacing
//Initializations ()
#define SYSCTL_RCGC2_R Address
# define GPIO_PORTA_DEN_R Address
# define GPIO_PORTB_DEN_R Address
# define GPIO_PORTF_DEN_R Address
# define GPIO_PORTA_DIR_R Address
# define GPIO_PORTB_DIR_R Address
# define GPIO_PORTF_DIR_R Address
# define GPIO_PORTA_Data_R Address
# define GPIO_PORTB_Data_R Address
# define GPIO_PORTF_Data_R Address
# define GPIO_PORTF_PUP_R Address
8.6 Seven-Segment LED Interfacing
//User defined variables:
# define SYSCTL_RCGC2_GPIOF 0 x0020
# define SYSTEM_CLOCK_FREQUENCY 16000000 // Default clk
# define DELAY_VALUE SYSTEM_CLOCK_FREQUENCY /80
# define GPIO_PORTF_PIN3 0x08
# define GPIO_PORTF_PIN4 0x10
# define DEALY_DEBOUNCE SYSTEM_CLOCK_FREQUENCY /1000
# define DEALY_DIGIT_REFRESH SYSTEM_CLOCK_FREQUENCY /200
# define PORT_A_PINS 0x3C //Port A pins 2,3,4
8.6 Seven-Segment LED Interfacing
8.6 Seven-Segment LED Interfacing
8.6 Seven-Segment LED Interfacing
8.6 Seven-Segment LED Interfacing

More Related Content

What's hot

Bill of Material of 132/33 KV 15 MVA Pooling Substation (15-07-2019)
Bill of Material of 132/33 KV 15 MVA Pooling Substation (15-07-2019)Bill of Material of 132/33 KV 15 MVA Pooling Substation (15-07-2019)
Bill of Material of 132/33 KV 15 MVA Pooling Substation (15-07-2019)Gensol Engineering Limited
 
Graduation Project on "SMART HOMES & RENEWABLE ENERGY" PowerPoint Presentation
Graduation Project on "SMART HOMES & RENEWABLE ENERGY" PowerPoint PresentationGraduation Project on "SMART HOMES & RENEWABLE ENERGY" PowerPoint Presentation
Graduation Project on "SMART HOMES & RENEWABLE ENERGY" PowerPoint PresentationAhmed Khalil Ibrahim
 
Power system operation corporation ltd (posoco)
Power system operation corporation ltd (posoco)Power system operation corporation ltd (posoco)
Power system operation corporation ltd (posoco)Dhruv Agarwal
 
SOLAR ENERGY FOR RURAL DEVELOPMENT
SOLAR ENERGY FOR RURAL DEVELOPMENTSOLAR ENERGY FOR RURAL DEVELOPMENT
SOLAR ENERGY FOR RURAL DEVELOPMENTjaisingh277
 
Huawei On-grid Solar Inverters
Huawei On-grid Solar InvertersHuawei On-grid Solar Inverters
Huawei On-grid Solar InvertersPremier Energy
 
PV System Design Project
PV System Design ProjectPV System Design Project
PV System Design ProjectMichael Clarke
 
Wind Power Generation Schemes
Wind Power Generation SchemesWind Power Generation Schemes
Wind Power Generation SchemesVignesh Sekar
 
Factors Enhancing Bifacial Gain in India & Middle East_06.03.2020
Factors Enhancing Bifacial Gain in India & Middle East_06.03.2020Factors Enhancing Bifacial Gain in India & Middle East_06.03.2020
Factors Enhancing Bifacial Gain in India & Middle East_06.03.2020Gensol Engineering Limited
 
Solar power integration with grid
Solar power integration with gridSolar power integration with grid
Solar power integration with gridashishant
 
Engineering Final Year Project Report on "Electrical Safety and Protection of...
Engineering Final Year Project Report on "Electrical Safety and Protection of...Engineering Final Year Project Report on "Electrical Safety and Protection of...
Engineering Final Year Project Report on "Electrical Safety and Protection of...Pratap Bhunia
 
Overview of State Estimation Technique for Power System Control
Overview of State Estimation Technique for Power System ControlOverview of State Estimation Technique for Power System Control
Overview of State Estimation Technique for Power System ControlIOSR Journals
 
Drawings & Documents Required for Solar Projects
Drawings & Documents Required for Solar ProjectsDrawings & Documents Required for Solar Projects
Drawings & Documents Required for Solar ProjectsGensol Engineering Limited
 
Future of solar Power Projects in India
Future of solar Power Projects in IndiaFuture of solar Power Projects in India
Future of solar Power Projects in IndiaHarish Sharma
 

What's hot (20)

Bill of Material of 132/33 KV 15 MVA Pooling Substation (15-07-2019)
Bill of Material of 132/33 KV 15 MVA Pooling Substation (15-07-2019)Bill of Material of 132/33 KV 15 MVA Pooling Substation (15-07-2019)
Bill of Material of 132/33 KV 15 MVA Pooling Substation (15-07-2019)
 
Graduation Project on "SMART HOMES & RENEWABLE ENERGY" PowerPoint Presentation
Graduation Project on "SMART HOMES & RENEWABLE ENERGY" PowerPoint PresentationGraduation Project on "SMART HOMES & RENEWABLE ENERGY" PowerPoint Presentation
Graduation Project on "SMART HOMES & RENEWABLE ENERGY" PowerPoint Presentation
 
GIS(GAS INSULATED SUBSTATION)
GIS(GAS  INSULATED  SUBSTATION) GIS(GAS  INSULATED  SUBSTATION)
GIS(GAS INSULATED SUBSTATION)
 
Psoc
PsocPsoc
Psoc
 
Power system operation corporation ltd (posoco)
Power system operation corporation ltd (posoco)Power system operation corporation ltd (posoco)
Power system operation corporation ltd (posoco)
 
SOLAR ENERGY FOR RURAL DEVELOPMENT
SOLAR ENERGY FOR RURAL DEVELOPMENTSOLAR ENERGY FOR RURAL DEVELOPMENT
SOLAR ENERGY FOR RURAL DEVELOPMENT
 
Huawei On-grid Solar Inverters
Huawei On-grid Solar InvertersHuawei On-grid Solar Inverters
Huawei On-grid Solar Inverters
 
List of Clearances for Solar Project
List of Clearances for Solar ProjectList of Clearances for Solar Project
List of Clearances for Solar Project
 
PV System Design Project
PV System Design ProjectPV System Design Project
PV System Design Project
 
Wind Power Generation Schemes
Wind Power Generation SchemesWind Power Generation Schemes
Wind Power Generation Schemes
 
Substation
SubstationSubstation
Substation
 
IEC61850 tutorial
IEC61850 tutorialIEC61850 tutorial
IEC61850 tutorial
 
Factors Enhancing Bifacial Gain in India & Middle East_06.03.2020
Factors Enhancing Bifacial Gain in India & Middle East_06.03.2020Factors Enhancing Bifacial Gain in India & Middle East_06.03.2020
Factors Enhancing Bifacial Gain in India & Middle East_06.03.2020
 
Solar power integration with grid
Solar power integration with gridSolar power integration with grid
Solar power integration with grid
 
Engineering Final Year Project Report on "Electrical Safety and Protection of...
Engineering Final Year Project Report on "Electrical Safety and Protection of...Engineering Final Year Project Report on "Electrical Safety and Protection of...
Engineering Final Year Project Report on "Electrical Safety and Protection of...
 
Overview of State Estimation Technique for Power System Control
Overview of State Estimation Technique for Power System ControlOverview of State Estimation Technique for Power System Control
Overview of State Estimation Technique for Power System Control
 
Siemens
SiemensSiemens
Siemens
 
Grid Connected PV Systems
Grid Connected PV SystemsGrid Connected PV Systems
Grid Connected PV Systems
 
Drawings & Documents Required for Solar Projects
Drawings & Documents Required for Solar ProjectsDrawings & Documents Required for Solar Projects
Drawings & Documents Required for Solar Projects
 
Future of solar Power Projects in India
Future of solar Power Projects in IndiaFuture of solar Power Projects in India
Future of solar Power Projects in India
 

Similar to Input-Output Interfacing for LED and Switch

Plc (PROGRAMMABLE LOGIC CONTROLLER)
Plc (PROGRAMMABLE LOGIC CONTROLLER)Plc (PROGRAMMABLE LOGIC CONTROLLER)
Plc (PROGRAMMABLE LOGIC CONTROLLER)Urval Chotalia
 
MPC of TWT based Transmitter
MPC of TWT based TransmitterMPC of TWT based Transmitter
MPC of TWT based TransmitterAbhishek Sutrave
 
Calculator design with lcd using fpga
Calculator design with lcd using fpgaCalculator design with lcd using fpga
Calculator design with lcd using fpgaHossam Hassan
 
Plc example presentation
Plc example presentationPlc example presentation
Plc example presentationRoshit Kadiru
 
Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...
Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...
Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...nipunkrn
 
summer training report (2)
summer training report (2)summer training report (2)
summer training report (2)Kavya Gupta
 
Interfacing with Atmega 16
Interfacing with Atmega 16Interfacing with Atmega 16
Interfacing with Atmega 16Ramadan Ramadan
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVRMohamed Abdallah
 
plc_training_manual.pdf
plc_training_manual.pdfplc_training_manual.pdf
plc_training_manual.pdfMarioHaguila
 

Similar to Input-Output Interfacing for LED and Switch (20)

Final Presentation
Final PresentationFinal Presentation
Final Presentation
 
Plc (PROGRAMMABLE LOGIC CONTROLLER)
Plc (PROGRAMMABLE LOGIC CONTROLLER)Plc (PROGRAMMABLE LOGIC CONTROLLER)
Plc (PROGRAMMABLE LOGIC CONTROLLER)
 
MPC of TWT based Transmitter
MPC of TWT based TransmitterMPC of TWT based Transmitter
MPC of TWT based Transmitter
 
Analog to Digital Converter
Analog to Digital ConverterAnalog to Digital Converter
Analog to Digital Converter
 
Module-3.pptx
Module-3.pptxModule-3.pptx
Module-3.pptx
 
plc introduction
plc introductionplc introduction
plc introduction
 
Calculator design with lcd using fpga
Calculator design with lcd using fpgaCalculator design with lcd using fpga
Calculator design with lcd using fpga
 
Plc example presentation
Plc example presentationPlc example presentation
Plc example presentation
 
Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...
Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...
Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...
 
Anup2
Anup2Anup2
Anup2
 
summer training report (2)
summer training report (2)summer training report (2)
summer training report (2)
 
PLC_1.ppt
PLC_1.pptPLC_1.ppt
PLC_1.ppt
 
PLCpptFeb222017.ppt
PLCpptFeb222017.pptPLCpptFeb222017.ppt
PLCpptFeb222017.ppt
 
SURVEILLANCE ROBOT
SURVEILLANCE ROBOTSURVEILLANCE ROBOT
SURVEILLANCE ROBOT
 
Basic plc
Basic plcBasic plc
Basic plc
 
Interfacing with Atmega 16
Interfacing with Atmega 16Interfacing with Atmega 16
Interfacing with Atmega 16
 
Remote ashok
Remote ashokRemote ashok
Remote ashok
 
Hardware interfacing basics using AVR
Hardware interfacing basics using AVRHardware interfacing basics using AVR
Hardware interfacing basics using AVR
 
Plc ppt
Plc pptPlc ppt
Plc ppt
 
plc_training_manual.pdf
plc_training_manual.pdfplc_training_manual.pdf
plc_training_manual.pdf
 

Recently uploaded

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 

Recently uploaded (20)

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 

Input-Output Interfacing for LED and Switch

  • 2. Input-Output Interfacing for LED and Switch • The TM4C123 microcontroller platform has three on board color LEDs (red, green and blue) and two switches for simple input output interfacing. • Both LEDs and switches are interfaced as digital devices. • In the following, we will learn to interface each of these two different types of devices. • LEDs will be interfaced using GPIO pins as digital outputs and switches will be connected by configuring the GPIO pins as digital inputs. • From Figure 8.10, we observe that the LEDs are connected using digital NPN transistors. • A digital transistor is the one that integrates the base (bias) resistors inside the transistor package. Unlike an ordinary transistor, a digital transistor operate in only two states, off and saturation.
  • 3. Input-Output Interfacing for LED and Switch Working of a switch: • This is true because, when the switch is pressed, logic low will be applied to the GPIO port pin connected to the switch. However, when the switch is released, there is no source (or supply) connection to ensure logic high appears at the GPIO port pin. • The switch interfacing shown in Figure 8.10 is not complete. With simple microcontrollers, the switch interface of Figure 8.10 might not work properly. • However, in case of TM4C123 the above-mentioned problem is resolved by using the internal pull-up resistor. • When the internal pull-up resistor is enabled, it pulls the GPIO pin to logic high when the switch is in released state. • The internal pull-up resistor values are in general larger than 10kQ. Since the current drawn by the GPIO port pin, when configured as input, is so low that the voltage drop across the pull-up resistor is almost negligible and voltage level, approximately equal to the supply voltage, appears at the GPIO pin, which is translated as logic high by the internal logic.
  • 4. Input-Output Interfacing for LED and Switch • A second option, different from the one shown in Figure 8.10, is to change the switch terminal connection from ground to supply (Vcc). • For this case we need to enable internal pull-down resistor for proper switch functioning. • In this case, logic high will be read by the user program, when the switch is pressed.
  • 5. 8.5.1: Output Interfacing for LED For LED interfacing we need to configure Port F pins 1, 2 and 3 as outputs. The basic steps to configure the required Port F pins are given below. 1. Enable the clock to the GPIO port. 2. Select the general purpose IO functionality by clearing the alternate function select register (GPIOAFSEL). 3. Configure the GPIO direction for digital output function. 4. Configure the PAD for the digital operation.
  • 6. 8.5.1: Output Interfacing for LED //Initializations () #define SYSCTL_RCGC2_R Address # define GPIO_PORTF_DEN_R Address # define GPIO_PORTF_DIR_R Address # define GPIO_PORTF_Data_R Address //User defined variables: # define SYSCTL_RCGC2_GPIOF 0 x0020 # define SYSTEM_CLOCK_FREQUENCY 16000000 // Default clk # define DELAY_VALUE SYSTEM_CLOCK_FREQUENCY /80 # define GPIO_PORTF_PIN3 0x08
  • 7. 8.5.1: Output Interfacing for LED • It is important to notice that the GPIO_PORTF_DATA_R register is defined as 0x40025020, which gives access to Port F pin 3 only. This allows us to perform write operation directly in one step to toggle the LED. The LED toggling is implemented in a loop with delay. The delay itself is implemented using a loop operation. • In the above C program, we can observe that the configuration steps are implemented using read-modify-write procedure. • Same startup.s file is also required to build the executable for the C program based implementation
  • 8. 8.5.2 Input Interfacing for Switch • Mechanical switches are commonly used to feed any parameters to the digital systems. • The switches can be interfaced to a microcontroller using digital inputs. • The software program for switch interfacing can be implemented using one of the following two methods. • Polling Based: In case of polling based method the GPIO pin connected with the switch is polled frequently enough, in the software, to avoid missing any key presses. • Interrupt Based: In this method the GPIO pin is configured as an external interrupt and any key press leads to an interrupt. The edge triggering of the interrupt can be configured on rising or falling edge, depending on the switch hardware connectivity.
  • 9. 8.5.2 Input Interfacing for Switch • Before we proceed further, it is important to first familiarize our self with the switch physical behavior. • Next we describe the switch bouncing, which is one of the critical attributes of its physical behavior. • Electrical switches that use mechanical contacts to close or open a circuit are subject to bouncing of the contacts • Switch contacts are usually made of springy metals. When the contacts strike together, their momentum and elasticity act together to cause them to bounce one or more times before making steady contact. • It results in a pulsating electric signal instead of a clean transition. • For a microcontroller GPIO pin configured as input, this switch bouncing can be interpreted as multiple switch presses. • Figure 8.11 shows the bouncing of a switch with normally open contact and is captured using digital storage oscilloscope.
  • 10. 8.5.2 Input Interfacing for Switch • Both hardware as well as software solutions exist to get around the switch bouncing problem. Hardware solution: • Analog filtering using an RC delay to filter out the rapid changes in switch output can be used as hardware solution. • The design task is to choose R and C such that the input threshold is not crossed while bouncing is still occurring. Software solution: In case of software solution to the switch bouncing problem, at the beginning of polling the switch is checked for being pressed. If the switch is detected as pressed, then a delay (corresponding to switch denouncing interval) is inserted and the switch is checked again for being pressed. If the switch is detected as pressed again, we declare that the switch is pressed. The rate at which the switch should be polled has to be fast enough that no switch press is missed, i.e., the time gap between two consecutive switch presses is larger than the scan cycle duration.
  • 11. Switch Interfacing Illustration • There are two user switches on TM4C123 evaluation board • User switch labeled SW1 is connected to Port F pin 4 (abbreviated as PF4), while the second switch SW2 is connected to Port F pin 0 (PF0). • In the following, we will describe the configuration steps required for interfacing switch SW1. The basic configuration steps are similar to the LED interfacing, with the exception of port pin direction configuration, as listed below: 1. Enable the clock to the GPIO port. 2. Select the general purpose IO functionality by clearing the alternate function select register (GPIOAFSEL). 3. Configure the GPIO direction for digital input. 4. Configure the PAD for digital operation. 5. In addition, enable the internal pull-up resistor by setting the corresponding bit of GPIOPUR register. This is required for proper functioning of the switch, as no external pull-up resistor is placed on the board.
  • 12. Switch Interfacing Illustration • The C program illustration for interfacing the switch using polling method is provided in Example 8.4. • The implementation is such that on every switch press an on board LED (green color) connected to PF3 will be toggled, which helps to visualize the proper functioning of the switch. • The LED toggling on switch press can be implemented in two different ways. • One possible approach is to toggle the LED, as soon as the switch is pressed and the next toggling of the LED only happens once the switch is first released and then pressed again. This approach can be termed as edge based LED toggling. • In the second approach, if the switch is pressed then the LED is toggled and the next LED toggling happens after some predetermined delay if the switch is still pressed. This approach can be termed as level based LED toggling.
  • 13. Switch Interfacing Illustration //Initializations () #define SYSCTL_RCGC2_R Address # define GPIO_PORTF_DEN_R Address # define GPIO_PORTF_DIR_R Address # define GPIO_PORTF_Data_RD Address # define GPIO_PORTF_Data_WR Address # define GPIO_PORTF_PUP_R Address //User defined variables: # define SYSCTL_RCGC2_GPIOF 0 x0020 # define SYSTEM_CLOCK_FREQUENCY 16000000 // Default clk # define DELAY_VALUE SYSTEM_CLOCK_FREQUENCY /80 # define GPIO_PORTF_PIN3 0x08 # define GPIO_PORTF_PIN4 0x10 # define DEALY_DEBOUNCE SYSTEM_CLOCK_FREQUENCY /1000
  • 16. Switch Interfacing Illustration • The value of the constant DEALY_DEBOUNCE depends on the switch characteristics. For many switches a debouncing delay of few milliseconds would be sufficient. • If the flag variable is not used by the program, then the resulting implementation will be equivalent to level based LED toggling.
  • 17. 8.6 Seven-Segment LED Interfacing • The seven-segment display is one of the widely used displays that can display decimal, hexadecimal and in some cases special characters. • Each of the seven LEDs in the display is called a segment, since when it is illuminated, it constructs a segment of the digit, to be displayed. • The eighth LED is used for the indication of a decimal point, (DP) and is used when two or more seven-segment displays are put together to display larger numbers. • Each of the seven LEDs in the segment is assigned a label from a through g based on its position in the segment. • In addition, one of the LED pins is brought out of the package for external connection, while all other terminals of the LEDs are connected together internally and brought out as single common pin. The common pin is also used to identify the type of the seven-segment display as common anode or common cathode
  • 18. 8.6 Seven-Segment LED Interfacing Common cathode: In this display type, all cathode terminals of the LED segments are joined together and are connected to logic low or ground. While based on the number to be displayed a collection of individual segments are illuminated by applying logic high though a current limiting resistor. Common anode: In this display type, the connections are reversed. The common terminal is of anode type and is connected with logic high, while individual segment pins are connected to logic low selectively based on the desired digit to be displayed.
  • 19. 8.6 Seven-Segment LED Interfacing
  • 20. 8.6 Seven-Segment LED Interfacing
  • 21. 8.6 Seven-Segment LED Interfacing 8.6.1 Time Multiplexing • Although it is possible to drive each segment of a multi-digit seven-segment display individually with its own dedicated GPIO pins, but the number of port pins required, becomes impractical when more than a few seven-segment displays are involved. • In an n-digit time display is required and every segment is interfaced separately to the microcontroller then the number of GPIO pins required is 7n (or 8n in case, dot point is also used). • To reduce the required number of GPIO pins, it is quite common to use a multiplexed (specifically time multiplexed) display architecture. • In a time multiplexed display, each seven segment element is driven individually at a time, but due to the persistence of vision, it appears to the viewer that the entire display is continuously active.
  • 22. 8.6 Seven-Segment LED Interfacing • In an n-digit time multiplexed display, n GPIO pins for digit selection and seven GPIO pins for each of the seven segments (or eight GPIO pins in case, dot point is also used) are required. • The resulting total number of GPIO pin connections required is equal to n+ 7 (or n + 8). • It should be realized that for time multiplexed display each segment is only activated for time fraction of the total display refresh cycle duration. • To avoid any flickering effect, the refresh frequency used is approximately 50 Hz in practice. • The PNP transistors are used as a switch with the common anode terminals of the display for turning ON one digit at a time.
  • 23. 8.6 Seven-Segment LED Interfacing //Initializations () #define SYSCTL_RCGC2_R Address # define GPIO_PORTA_DEN_R Address # define GPIO_PORTB_DEN_R Address # define GPIO_PORTF_DEN_R Address # define GPIO_PORTA_DIR_R Address # define GPIO_PORTB_DIR_R Address # define GPIO_PORTF_DIR_R Address # define GPIO_PORTA_Data_R Address # define GPIO_PORTB_Data_R Address # define GPIO_PORTF_Data_R Address # define GPIO_PORTF_PUP_R Address
  • 24. 8.6 Seven-Segment LED Interfacing //User defined variables: # define SYSCTL_RCGC2_GPIOF 0 x0020 # define SYSTEM_CLOCK_FREQUENCY 16000000 // Default clk # define DELAY_VALUE SYSTEM_CLOCK_FREQUENCY /80 # define GPIO_PORTF_PIN3 0x08 # define GPIO_PORTF_PIN4 0x10 # define DEALY_DEBOUNCE SYSTEM_CLOCK_FREQUENCY /1000 # define DEALY_DIGIT_REFRESH SYSTEM_CLOCK_FREQUENCY /200 # define PORT_A_PINS 0x3C //Port A pins 2,3,4
  • 25. 8.6 Seven-Segment LED Interfacing
  • 26. 8.6 Seven-Segment LED Interfacing
  • 27. 8.6 Seven-Segment LED Interfacing
  • 28. 8.6 Seven-Segment LED Interfacing