18
Embedded Systems Interfacing PIC with external devices LCD Eng. Anis Nazer First Semester 2017-2018

Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

  • Upload
    others

  • View
    18

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

Embedded Systems

Interfacing PIC with external devicesLCD

Eng. Anis NazerFirst Semester 2017-2018

Page 2: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

LCD

● Liquid crystal display (LCD)

Page 3: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

LCD

● Liquid crystal display (LCD)

Page 4: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

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

Page 5: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

Alphanumeric LCD

● LCDs that has the controller: HD44780

Page 6: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

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

Page 7: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

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

Page 8: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

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

Page 9: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

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

– Assumes a default connection:

D<7:4> → PORT<7:4>

EN → PORT<3>

RS → PORT<2>

RW → PORT<0>

Page 10: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

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

Page 11: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

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 ?

Page 12: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

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)

Page 13: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

Example - Circuit diagram

Page 14: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

Example - Program

void main(){   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

Page 15: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

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 ?

Page 16: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

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

Page 17: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

Example

● Circuit design:

Page 18: Embedded Systems - Philadelphia University Systems /08... · LCD mikroC Library Fortunately, mikroC has a library for LCD This library uses the 4-bit mode Information is available

Example - Program

void main(){   int x=0;   char s[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);      }   }}