0% found this document useful (0 votes)
7 views

Module-4

Module 4 discusses Input/Output (I/O) programming in embedded microcontrollers, focusing on the LPC1768 ARM Cortex-M3 microcontroller. It covers the configuration and functionality of GPIO ports, pin connect blocks, and various interfacing techniques for devices like LEDs, seven-segment displays, stepper motors, and LCDs. The document provides an overview of the microcontroller's architecture, capabilities, and practical applications in embedded systems.

Uploaded by

pubpubg190
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Module-4

Module 4 discusses Input/Output (I/O) programming in embedded microcontrollers, focusing on the LPC1768 ARM Cortex-M3 microcontroller. It covers the configuration and functionality of GPIO ports, pin connect blocks, and various interfacing techniques for devices like LEDs, seven-segment displays, stepper motors, and LCDs. The document provides an overview of the microcontroller's architecture, capabilities, and practical applications in embedded systems.

Uploaded by

pubpubg190
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 101

Module 4

INPUT/OUTPUT (IO) PROGRAMMING


On most embedded microcontrollers, the I/O ports are memory
mapped.

The software can access an input/output port simply by reading from or


writing to the appropriate address.

It is important to realize that even though I/O operations “look” like reads
and writes to memory variables, the I/O ports often DO NOT act like
memory.
• The simplest I/O port on a microcontroller is the parallel port.
• A parallel I/O port is a simple mechanism that allows the software to interact
with external devices.

• It is called parallel because multiple signals can be accessed all at once.

An input port, which is read only, allows the software to read external digital signals.
A read cycle access from the port address returns the values existing on the inputs at that time.
What happens if the software writes to an input
port?
What is IO programming?
• Through IO programming microcontroller can be used to control other devices such
as sensors, displays, On-chip modules etc.
• It is done through GPIO (General purpose Input Output).
• GPIO is a pin on an IC (Integrated Circuit). It can be either input pin or output pin,
whose behavior can be controlled at the run time. It's a standard interface used to
connect microcontrollers to other electronic devices.

• In LPC1768, there are 5 ports, P0 to P4 each 32 bit (i.e., 32 pins). Few port pins are
not available. (total pins = 100)
• In GPIO operation we perform general purpose operation to read from the port and
to write to the port.
LPC 1768
• The LPC1768 is an ARM Cortex-M3 based microcontroller for embedded applications
requiring a high level of integration and low power dissipation.
• The ARM Cortex-M3 CPU incorporates a 3-stage pipeline and uses a Harvard
architecture with separate local instruction and data buses as well as a third bus for
peripherals.
• The ARM Cortex-M3 is a general purpose 32-bit microprocessor, which offers high
• performance and very low power consumption. The Cortex-M3 offers many new
features, including a Thumb instruction set, low interrupt latency etc.

• Applications
• e-Metering
• Lighting
• Industrial networking
• Alarm systems
• Motor control
The LPC1768 is a microcontroller based on the ARM Cortex-M3 architecture.

It has a variety of pins that can be configured for different purposes.

Basic overview of the pin configuration for the LPC1768:

• Pin Connect Block (PCB)

• Pin Function Select Registers (PFS)

• General Purpose Input and Output (GPIO) Registers

• GPIO Configuration

• GPIO Programming using ARM C Language


Pin Connect Block (PCB)
• The Pin Connect Block is depicted as a rectangular box
with pins labeled from 0 to 31. This box represents
the hardware on the microcontroller that is
responsible for configuring the pinout and pin
• Responsible for configuring the pinout and functions.
• The pins are arranged in a grid of rows and columns.
pin functions of the device. Each pin can be assigned a specific function, such as
input, output, or alternate function, using the Pin
• Allows to assign various functions to the Connect Block.
pins on the microcontroller, such as input, • The specific pin functions and assignments will
depend on the particular microcontroller being used.
output, interrupts, and analog inputs.
• The pins are labeled from 0 to 31, indicates that this
particular microcontroller has 32 pins that can be
configured using the Pin Connect Block.
• The pins labeled as "IO" indicate that they can be
used as either inputs or outputs, depending on how
they are configured.
• The horizontal lines at the top and bottom of the box
represent the power and ground pins of the
microcontroller. These pins provide the necessary
power and ground connections for the device to
operate.
• The Pin Connect Block is a key component of the ARM
Cortex-M3 microcontroller, as it allows developers to
configure the pin functions and assignments to meet
the specific requirements of their applications.
INPUT/OUTPUT (IO) PROGRAMMING
LPC1768 pin configuration 512 K Flash memory
64K SRAM
8K ROM
100 pin IC
GPIO in LPC1768

• 5 general purpose bidirectional digital IO ports,


Port 0, Port 1, Port 2, Port 3 and Port 4.
❑ Fast GPIO-enhanced /Accelerated Features
❑ Additionally, Port 0 and Port 2 pins can provide a single interrupt
• Application
❑ General purpose I/O, Driving LEDs or other indicators, Controlling
off-chip devices, Sensing digital inputs, detecting edges
• Port 0 Pins 12, 13, 14 & 31 are not available.
• Port 1 Pins 2, 3, 7, 6, 5, 11, 12, & 13 are not available.
• Port 2 only pins 0 to 13 are available and rest are reserved.
• Port 3 only pins 25,26 are available and rest are reserved.
• Port 4 only 28,29 are available and rest are reserved.

• In total 70 GPIO pins are available for the user.


Pin connect block

• The naming convention for port pins is ‘Px.y’ where ‘x’ is the
port number and ‘y’ is simply the pin number in port ‘x’.
For example:
P0.7 refers to Pin number 7 of Port 0 , P2.11 refers to Pin
number 11 in Port 2.
Pin Connect Block Registers

• Pin function select registers


GPIO port output Set register FIOxSET (FIO0SET to FIO4SET)
• This register is used to produce a High-level output at the port pins configured as
GPIO in an OUTPUT mode.
❑ Writing 1 produces a HIGH level at the corresponding port pins
❑ Writing 0 has no effect
• If any pin is configured as an input or a secondary function, writing 1 to the
corresponding bit in the FIOxSET has no effect.
• Reading the FIOxSET register returns the value of this register, as determined by
previous writes to FIOxSET and FIOxCLR (or FIOxPIN).
• Access to a port pin via the FIOxSET register is conditioned by the corresponding
bit of the FIOxMASK register
GPIO port output Clear register FIOxCLR (FIO0CLR to FIO4CLR)

• This register is used to produce a LOW-level output at port pins


configured as GPIO in an OUTPUT mode.
• Writing 1 produces a LOW level at the corresponding port pin and clears
the corresponding bit in the FIOxSET register.
• Writing 0 has no effect. If any pin is configured as an input or a
secondary function, writing to FIOxCLR has no effect.
• Access to a port pin via the FIOxCLR register is conditioned by the
corresponding bit of the FIOxMASK register
Ref:
• https://www.youtube.com/watch?v=5ipqQsguqdE -- FIOxDIR
• https://www.youtube.com/watch?v=WmZFfokztXg Pin Connect block
• Chapter 8 and 9 in the user manual
UM10360 pdf, UM10360 Description, UM10360 Datasheet, UM10360 view ::: ALLDATASHEET :::
GPIO port Pin value register FIOxPIN (FIO0PIN to FIO4PIN)
• This register provides the value of port pins that are configured to perform only digital
functions.
• The register will give the logic value of the pin regardless of whether the pin is
configured for input or output, or as GPIO or an alternate digital function.
• Any configuration of that pin will allow its current logic state to be read from the
corresponding FIOxPIN register.
• Access to a port pin via the FIOxPIN register is conditioned by the corresponding bit of
the FIOxMASK register
• Only pins masked with zeros in the Mask register will be correlated to the current content
of the Fast GPIO port pin value register.
Fast GPIO port Mask register FIOxMASK (FIO0MASK to FIO4MASK)

• This register is used to select port pins that will and will not be affected by
write accesses to the FIOxPIN, FIOxSET or FIOxCLR register. Mask register
also filters out port’s content when the FIOxPIN register is read.
• A zero in this register’s bit enables an access to the corresponding physical
pin via a read or write access. If a bit in this register is one, corresponding pin
will not be changed with write access and if read, will not be reflected in the
updated FIOxPIN register.
INTERFACING LED TO ARM
MICROCONTROLLER
LED to pin P1.29 of LPC1768
Microcontroller as shown in circuit diagram. General
steps for an application to
blink LED using LPC1768 Micro
Controller

• Initialize a microcontroller system, which take care setup procedure


like powering up peripherals, set clock rate etc.
• Connect necessary pins using pin connect block. The purpose of pin
connect block is to configure the microcontroller pin to desired
function.
• And then set or clear the bit of respective pin to turn ON & OFF
LED.
INTERFACING SEVEN SEGMENT
TO ARM MICROCONTROLLER
Seven Segment Display

• Seven segment displays are the output display device that provides a way to display
information in the form of images or text or decimal numbers which is an alternative
to the more complex dot matrix displays.
• It is widely used in digital clocks, basic calculators, electronic meters, and other
electronic devices that display numerical information.
• It consists of seven segments of light-emitting diodes (LEDs) which are assembled like
numerical 8.
Working of Seven Segment Displays
• The number 8 is displayed when the power is given to all the segments and if you
disconnect the power for ‘g’, then it displays the number 0.
• In a seven-segment display, power (or voltage) at different pins can be applied at the
same time, so we can form combinations of display numerical from 0 to 9.
• Each display unit has a Dot/Decimal point (DP).

Since seven-segment displays cannot form alphabets like X and Z, so it cannot be


used for the alphabet, and they can be used only for displaying decimal numerical
magnitudes.

However, seven-segment displays can form alphabets A, B, C, D, E, and F.


Types of Seven Segment Displays
Two types of configurations of
seven-segment displays
• Common anode display
• Common cathode display
Common Cathode Seven Segment Displays, all the
cathode connections of LED segments are connected to logic 0 or
ground.
We use logic 1 through a current limiting resistor to forward bias
the individual anode terminals a to g.

Anode connections of the LED segments are


connected to logic 1 in a common anode seven segment
display. We use logic 0 through a current limiting
resistor to the cathode of a particular segment a to g.
INTERFACING STEPPER MOTOR
TO ARM MICROCONTROLLER
• Stepper motors are the motors that move in
discrete steps or convert electrical pulses into
rotatory motion.
• They have multiple coils (4coils) that are
organized in groups called "phases"(stators
named as A,B,C and D).
• By energizing each phase in sequence, the
motor will rotate, one step at a time.
INTERFACING LCD
TO ARM MICROCONTROLLER
Apart from the voltage supply connections the
important pins from the programming perspective
are:

• The data lines(8-bit Data bus)


• Register select
• Read/Write
• Enable pin
Data Bus
• An LCD has 8-bit data bus referenced as D0-D7.
• As it is an 8-bit data bus, we can send the data/cmd to LCD in bytes.
• It also provides the provision to send the the data/cmd in chunks of 4-bit, which is used when there are
limited number of GPIO lines on the microcontroller.

Register Select(RS)

The LCD has two register namely a Data register and Command register.
• Any data that needs to be displayed on the LCD must be written to the data register of LCD.
• Command can be issued to LCD by writing it to Command register of LCD. This signal is used to
differentiate the data/cmd received by the LCD.
❑ If the RS signal is LOW, then the LCD interprets the 8-bit info as Command and writes it Command
register and performs the action as per the command.
❑ If the RS signal is HIGH, then the LCD interprets the 8-bit info as data and copies it to data register. After
that the LCD decodes the data for generating the 5x7 pattern and finally displays on the LCD.
NOTE:
• A character in lcd is generated in a matrix of 5×8 or 5×7.
• Where 5 represents number of columns and 7/8 represent number of rows.
• Maximum size of the matrix is 5×8.
• You can not display character greater than 5×8-dimension matrix.
• Normally we display a character in 5×7 matrix and left the 8th row for the cursor.
• If we use the 8th row of the matrix for the character display, then there will be no room for cursor.

Read/Write(RW)
• This signal is used to write the data/cmd to LCD and reads the busy flag of LCD.
• For write operation the RW should be LOW and for read operation the R/W should be HIGH.

Enable(EN)
• This pin is used to enable and disable LCD.
• When this pin is active low, LCD controller will be disabled.
• That means control pins and data pins will not have any effect on the display.
• On the other hand, when the enable pin is set to active high, the LCD will work normally and process all
data and control instructions. .
8-bit Mode

4-bit Mode
Steps for Sending Command

• Send the I/P command to LCD.


• Select the Control Register by making
RS low.
• Select Write operation making RW
low.
• Send a High-to-Low pulse on Enable
PIN with some delay_us.

Steps for Sending Data

• Send the character to LCD.


• Select the Data Register by making
RS high.
• Select Write operation making RW
low.
• Send a High-to-Low pulse on Enable
PIN with some delay_us.
• LCD display takes a time of 39-43µS to place a character or
execute a command, except for clearing display and to seek cursor
to home position which takes 1.53ms to 1.64ms.

• Any attempt to send any data before this interval may lead to
failure to read data or execution of the current data. So we have to
give appropriate delay after each command/data writing.
LCD Initialization

Before displaying characters on the LCD display, it must be


configured first. To configure an LCD display, four command words
must be sent to LCD.

The commands are:


1. Function set
2. Display On/Off control
3. Entry mode set
4. Display and Clear
Before
function set,
we need to
configure in 4
bit mode
Sl.No. Hex Code Command to LCD instruction Register
1 01 Clear display screen
2 02 Return home
3 04 Decrement cursor (shift cursor to left)
4 06 Increment cursor (shift cursor to right)
5 05 Shift display right
6 07 Shift display left
7 08 Display off, cursor off

Control and display 8 0A Display off, cursor on


9 0C Display on, cursor off
commands 10 0E Display on, cursor blinking
11 0F Display on, cursor blinking
12 10 Shift cursor position to left
13 14 Shift cursor position to right
14 18 Shift the entire display to the left
15 1C Shift the entire display to the right
16 80 Force cursor to beginning ( 1st line)
17 C0 Force cursor to beginning ( 2nd line)
18 38 2 Lines and 5x7 Matrix
INTERFACING 4X4 Keyboard
TO ARM MICROCONTROLLER
4×4 matrix keypad

A total of 8 input-output pins of the micro-controller will


be required for interfacing.

One-half of the 8 pins will be hardware controlled and the


other half will be software controlled.

The blue lines are the columns, and the red lines are the
rows.

The rows are the four LSBs of the 8-bit pins and the
columns are the MSBs of the 8-bit pins.

You might also like