Top Banner
1 04-Interfacing LCD Displays. By : Mohamed Fawzy Programming AVR Microcontrollers © Mohamed F.A.B 2015
18

04 Interfacing LCD Displays.2016

Feb 14, 2017

Download

Engineering

Mohamed Fawzy
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 04 Interfacing LCD Displays.2016

1

04-Interfacing LCD Displays.

By : Mohamed Fawzy

Programming AVR Microcontrollers

© Mohamed F.A.B 2015

Page 2: 04 Interfacing LCD Displays.2016

Lecture Notes:

2

o Set Your Phone To Vibration Mode.

o Ask any time.

o During labs, Feel Free To Check Any Materials or

Internet.

o Slides are self content.

o Feel Free To Share This Materials With Your Friends.

o Work Hard For Achieving Most Of This Course.

© Mohamed F.A.B 2015

Page 3: 04 Interfacing LCD Displays.2016

3

Don't Forget !!!!

© Mohamed F.A.B 2015

Any Expert Was Once A Beginner

Page 4: 04 Interfacing LCD Displays.2016

4

Lesson(10).

© Mohamed F.A.B 2015

Lesson (10):

Interfacing LCDs displays with Microcontroller.

Page 5: 04 Interfacing LCD Displays.2016

5

Lesson (10) Topics.

© Mohamed F.A.B 2015

► Intro to LCDs screens.

► LCD Hardware Connections.

► LCD built in Functions in MIKROC.

► Displaying Numbers On LCD.

► How to Display Custom Symbols or Characters on LCD.

► How to Connect Multiple LCD With MC using Same Pins.

► Let's Have Fun With LCD.

Page 6: 04 Interfacing LCD Displays.2016

6

Intro To LCDs Screens.

© Mohamed F.A.B 2015

LCD stands for Liquid Crystal Display.

It can be used to display anything (virtually

anything!).

There are two common types of LCDs:

Character LCD : Used For

Displaying Only

Characters, Numbers and

some Custom Symbols.

Graphical LCD : Used For

Displaying almost

everything (Text, symbols

and images).“Will be discussed on Level 2”

Page 7: 04 Interfacing LCD Displays.2016

7

LCDs Memory.

© Mohamed F.A.B 2015

Memory in LCD divided into Three types:

DDRAM Memory: storing characters to be

displayed.

CGROM Memory: contains standard

character map with all characters that

can be displayed on the screen.

CGRAM Memory: a part from standard

characters, the LCD display can also

display symbols defined by the user itself.

We can use CGRAM to display custom symbols on LCD.

NOTE:

Page 8: 04 Interfacing LCD Displays.2016

8

LCD Hardware Connections.

© Mohamed F.A.B 2015

• Pins[RS,R/W,EN] Control Lines.• Pins[D0:D7] Data Lines.

Don't swap power pins to avoid damaging your LCD.

Take Care:

Page 9: 04 Interfacing LCD Displays.2016

9

alcd.h functions.

© Mohamed F.A.B 2015

Initializing the LCD controllervoid lcd_init(unsigned char lcd_columns);

EX:

Lcd_init(16); //for 2*16 LCD

Writing character to LCDvoid lcd_putchar(char c);

EX:

Lcd_write (‘A’); //display A on LCD

Defining position of cursor (x,y)void lcd_gotoxy(unsigned char x, unsigned char y);

EX:

lcd_gotoxy(0,0); //start from column 0 and row 0

write the string str located in SRAM to the LCDvoid lcd_puts(char *str);

EX:

lcd_puts(“Hello LCD !!!”);

Page 10: 04 Interfacing LCD Displays.2016

10

alcd.h functions. Cont’

© Mohamed F.A.B 2015

Clearing the LCDvoid lcd_clear(void);

EX:

lcd_clear(); //delete any data on LCD

Write byte to the LCD character generator or LCD CGRAMvoid write_byte(unsigned char address, unsigned char data);

EX:

void write_byte(char0, 0);

Writing command to LCDvoid _lcd_write_data(unsigned char cmd);

EX:

void _lcd_write_data(0x0E); //display LCD cursor

Page 11: 04 Interfacing LCD Displays.2016

11

LCD useful commands codes.

© Mohamed F.A.B 2015

Code Function0x0C Cursor OFF

0x0E Cursor underline

0x0F Cursor ON

0x10 Move cursor left by one character.

0x14 Move cursor right by one character.

#define _LCD_CURSOR_OFF 0x0C

#define _LCD_CURSOR_UNDERLINE 0x0E

#define _LCD_CURSOR_ON 0x0F

#define _LCD_CURSOR_LEFT 0x10

#define _LCD_CURSOR_RIGHT 0x14

TIP

Page 12: 04 Interfacing LCD Displays.2016

12

Displaying Numbers On LCD.

© Mohamed F.A.B 2015

• LCD displays data into ASCII format.ASCII Symbol

Do (00:99) UP Down Counter With Two Buttons.

Exercise:

Page 13: 04 Interfacing LCD Displays.2016

13

Displaying Custom Symbols On LCD.

© Mohamed F.A.B 2015

In some cases you may need to

display characters and symbols that

not defined in CGROM.

You need to define your symbol into

CGRAM.

1

2

3

We use “LCD Custom Char Builder” to draw our pattern.http://extremeelectronics.co.in/avrtutorials/download/LCDCustomCharBuilder.zip

Page 14: 04 Interfacing LCD Displays.2016

14

Displaying Custom Symbols On LCD. Cont’

© Mohamed F.A.B 2015

Exercise:

#include <io.h>

#include <alcd.h>

#include <delay.h>

// Declare your global variables here

flash unsigned char char0[8]={0x0A, 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x04, 0x00};

void define_char(unsigned char flash *pc, unsigned char char_code){

unsigned char i,a;

a=(char_code<<3)|0x040;

for (i=0;i<8;i++)lcd_write_byte(a++,*pc++);

}

void main(void)

{

lcd_init(16);

lcd_gotoxy(0,0);

while (1)

{

define_char(char0,0);

lcd_puts("I ");

lcd_putchar(0);

lcd_puts(" AVR");

}

Page 15: 04 Interfacing LCD Displays.2016

15

Connecting Multiple LCD with same I/O Pins.

© Mohamed F.A.B 2015

What if we need to use multiple LCD in one project ??!!!!.

We can do that using latch IC 74HC573.

Simply, this IC pass data from input pins to output pins in

case we enables that action.

We need to interface 2 LCDs with MC using PORTC, then displaying “LCD_1”on first LCD and displaying “LCD_2” on second LCD.

Exercise:

LCD_1 LCD_2

Page 16: 04 Interfacing LCD Displays.2016

16

Let's have Fun With LCD .

© Mohamed F.A.B 2015

Page 17: 04 Interfacing LCD Displays.2016

17

Questions:

© Mohamed F.A.B 2015

Page 18: 04 Interfacing LCD Displays.2016

Thank You All

18

[email protected]

01006032792

[email protected]

© Mohamed F.A.B 2015