Module-4
Module-4
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.
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.
• GPIO Configuration
• 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
• 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
• 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).
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
• 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
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.