Vous êtes sur la page 1sur 18

Embedded Systems

Interfacing PIC with external devices


LCD

Eng. Anis Nazer


Second Semester 2016-2017
LCD

Liquid crystal display (LCD)


LCD

Liquid crystal display (LCD)


LCD

Liquid crystal display (LCD)


Matrix of small dots that can be controlled to display an
image or text
some LCDs contain a controller to simplify using the LCD
alphanumeric LCD has a controller to simplify displaying
letters (text)
Popular controller: HD44780
Alphanumeric LCD

LCDs that has the controller: HD44780


LCD pinout
GND, VCC: ground, power
VEE: control the contrast (analog value)
RS: register select,
RS=0 : command
RS=1 : data
R/W: Read / Write (normally we need to write to the LCD)
R/W = 0 : Write
R/W = 1 : Read
EN : enable, active after a falling edge (falling edge triggered)
DB7-DB0 : 8 bits of data
LED + : back light LED anode
LED - : back-light LED cathode
HD44780 controller

You can send the data as an ASCII code character and the
LCD controller will display the character
You can send commands:
e.g. :clear display, cursor home, ...
the controller has two modes:
8 bit mode: data is sent through 8 bits DB0-DB7
4 bit mode: data is sent through 4 bits DB4-DB7
two phases to send data: 4 bits at a time
LCD mikroC Library
Fortunately, mikroC has a library for LCD
This library uses the 4-bit mode
Information is available through help
You need to configure the port connected to the LCD
Functions:
Lcd_Out(r, c, text) : display a text starting from row r and column c
Lcd_Out_Cp(text) : display a text on current cursor position
Lcd_Chr(r,c, ch) : display a character on row r and column c
Lcd_Chr_Cp(ch) : display character on current cursor position
Lcd_Cmd (cmd) : send a command, e.g. _LCD_CLEAR
LCD mikroC Library - Configuration

You can use the default function to initialize the LCD:


Lcd_Init( &PORT ) ;
initialize the LCD that is connected to PORT
Uses a default connection:
D<7:4> PORT<7:4>
EN PORT<3>
RS PORT<2>
RW PORT<0>
LCD mikroC Library - Configuration
Or you can use a custom configuration:
Lcd_Config(&PORT, RS, EN, WR, D7, D6, D5, D4)
example:
Lcd_Config(&PORTB,1,2,0,3,4,5,6);
RS RB1
EN RB2
WR RB0
D7 RB3
D6 RB4
D5 RB5
D4 RB6
Example

Use an LCD to display your name. Draw the circuit and


write the code
Questions:
how many pins are required ?
Which PIC is appropriate ?
To which port should I connect the LCD ?
Example
Questions:
how many pins are required ?
4 for data, RS, EN, WR
Which PIC is appropriate ?
PIC16F84A has 13 I/O pins... more than enough
To which port should I connect the LCD ?
I chose to connect the LCD as follows:
RB<6:3> data
RB0 RS
RB1 EN
RB2 WR
so: Lcd_Config(&PORTB, 0, 1, 2, 6, 5, 4, 3)
Example - Circuit diagram
Example - Program

voidmain()
{
Lcd_Config(&PORTB,0,1,2,6,5,4,3);
Lcd_Out(1,1,"Anis");
Lcd_Cmd(LCD_CURSOR_OFF);
while(1)
{
}
}

Exercise: Display your name and make it scroll across the LCD
Example

Implement a tally counter and display the count on the


LCD
Questions:
What are the components ?
How many I/O pins ?
Which PIC ?
Circuit design ?
Program ?
Example

What are the components ?


PIC
button
LCD
How many I/O pins ?
1 for the button
7 for the LCD
Which PIC ?
PIC16F84A is suitable
Example

Circuit design:
Example - Program
voidmain()
{
intx;
chars[8];
Lcd_Config(&PORTB,0,1,2,6,5,4,3);
Lcd_Out(1,1,"Count:");
IntToStr(x,s);
Lcd_Out(1,8,s);
Lcd_Cmd(LCD_CURSOR_OFF);
x=0;
TRISA.F0=1;
while(1)
{
if(PORTA.F0==1)
{
x=x+1;
while(PORTA.F0==1);
IntToStr(x,s);
Lcd_Out(1,8,s);
}
}
}