04 Interfacing LCD Displays.2016

Post on 14-Feb-2017

55 Views

Category:

Engineering

5 Downloads

Preview:

Click to see full reader

Transcript

1

04-Interfacing LCD Displays.

By : Mohamed Fawzy

Programming AVR Microcontrollers

© Mohamed F.A.B 2015

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

3

Don't Forget !!!!

© Mohamed F.A.B 2015

Any Expert Was Once A Beginner

4

Lesson(10).

© Mohamed F.A.B 2015

Lesson (10):

Interfacing LCDs displays with Microcontroller.

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.

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”

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:

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:

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 !!!”);

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

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

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:

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

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");

}

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

16

Let's have Fun With LCD .

© Mohamed F.A.B 2015

17

Questions:

© Mohamed F.A.B 2015

Thank You All

18

mo7amed.fawzy33@gmail.com

01006032792

fawzy.fab@gmail.com

© Mohamed F.A.B 2015

top related