Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
EMBEDDED SYSTEMS
CHAPTER FIVE
LCD & ANALOG I/O
ARDUINO PROGRAMMING
Al-Hussein Bin Talal University
Faculty of Engineering
Department of Computer Engineering
Spring 2019
LCD
■ The LiquidCrystal library allows you to control LCD displays that are compatible with
the Hitachi HD44780 driver.
■ you can usually tell them by the 16-pin interface.
■ The LCDs have a parallel interface, meaning that the microcontroller has to
manipulate several interface pins at once to control the display
1
4/22/2019
LCD cont..
LCD Interface
■ The LCDs have a parallel interface, meaning that the microcontroller has to
manipulate several interface pins at once to control the display. The interface
consists of the following pins:
– A register select (RS) pin that controls where in the LCD's memory you're
writing data to. You can select either the data register, which holds what goes
on the screen, or an instruction register, which is where the LCD's controller
looks for instructions on what to do next.
2
4/22/2019
LCD Interface
LiquidCrystal Library
■ This library allows an Arduino board to control LiquidCrystal displays (LCDs) based
on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-
based LCDs.
■ The library works with in either 4- or 8-bit mode (i.e. using 4 or 8 data lines in
addition to the rs, enable, and, optionally, the rw control lines).
3
4/22/2019
LCD Functions
■ LiquidCrystal(): Creates a variable of type LiquidCrystal. The display can be controlled
using 4 or 8 data lines. If the former, omit the pin numbers for d0 to d3 and leave
those lines unconnected. The RW pin can be tied to ground instead of connected to a
pin on the Arduino; if so, omit it from this function's parameters.
– Syntax: LiquidCrystal(rs, enable, d4, d5, d6, d7)
■ begin(): Initializes the interface to the LCD screen, and specifies the dimensions (width
and height) of the display.
– Syntax: lcd.begin(cols, rows)
■ clear(): Clears the LCD screen and positions the cursor in the upper-left corner.
– Syntax lcd.clear()
LCD Functions
4
4/22/2019
LCD Functions
LCD Functions
■ scrollDisplayRight(): Scrolls the contents of the display (text and cursor) one space to the right.
– Syntax: lcd.scrollDisplayRight()
■ autoscroll(): Turns on automatic scrolling of the LCD. This causes each character output to the display to push previous characters
over by one space.
– Syntax: lcd.autoscroll()
■ noAutoscroll(): Turns off automatic scrolling of the LCD.
– Syntax: lcd.noAutoscroll()
■ leftToRight(): Set the direction for text written to the LCD to left-to-right, the default.
– Syntax: lcd.leftToRight()
■ rightToLeft(): Set the direction for text written to the LCD to right-to-left (the default is left-to-right)
– Syntax: lcd.rightToLeft()
■ createChar(): Create a custom character (glyph) for use on the LCD. Up to eight characters of 5x8 pixels are supported (numbered
0 to 7).
– Syntax: lcd.createChar(num, data)
5
4/22/2019
LCD Example
"Hello World!“
Schematic
6
4/22/2019
LCD Blink
7
4/22/2019
■ potentiometer
is a variable
resistor.
8
4/22/2019
Analog Functions
■ analogWrite(): Writes an analog value (PWM wave) to a pin. Can be used to light a
LED at varying brightnesses or drive a motor at various speeds.
■ Syntax: analogWrite(pin, value)
■ analogRead(): Reads the value from the specified analog pin. Arduino boards
contain a multichannel, 10-bit analog to digital converter. This means that it will
map input voltages between 0 and the operating voltage(5V or 3.3V) into integer
values between 0 and 1023.
– Syntax: analogRead(pin)
9
4/22/2019
Example X
■ Reads an analog input pin, maps the result to a range from 0 to 255 and uses the
result to set the pulsewidth modulation (PWM) of an output pin.
■ prints the results to the serial monitor.
Example X
Code
10
4/22/2019
11