You are on page 1of 7

DISPLAY DE LCD 16x2

O chip que se encontra dentro do display um HITACHI HD44780 ou algum outro que seja compatvel com o mesmo. Possui 14 pinos: Nmero Smbolo Funo 1 Vss 0v Power Supply (GND Level) 2 Vdd Power Supply for Logic Circuit 3 Vo Is for adjusting the contrast of the display. Usually, when this pin is grounded the pixels will be the darkest 4 RS Data/Instruction select 5 R/W Determines if we read from or write to the LCD 6 E Enables or disables the LCD module 7-14 DB0-DB7 Bi-directional data bus OBS: Quando o pino E est baixo, o display se encontra desabilitado e os valores que se encontram nos pinos RS, R/W e no barramento de dados sero ignorados.

Register Select (RS):


RS = 0 quando se envia para o display uma instruo (instruction register) RS = 1 quando se envia para o display um caractere (data register) Segue abaixo um esquemtico do display:

Display Data RAM (DDRAM):


Display data RAM pra onde voc manda os caracteres (ASCII code) que voc quer ver na tela do LCD. Sua capacidade de 80 caracteres (bytes). O endereo da DDRAM a posio do cursor (ex: onde o dado que voc enviou ser mostrado). Abaixo so mostrados os endereos da DDRAM:

Character Generator RAM (CGRAM):


No CGRAM o usurio pode definir seus prprios caracteres por programao. CG RAM de 64 bytes.

Registers:
O HDD44780 tem dois registradores de 8 bits, um o instruction register (IR) e o outro o data register (DR). O IR grava cdigos de instrues, como limpar display e shift do cursor, e informao de endereo para DDRAM e CGRAM. O DR grava temporariamente dados para serem escritos na DDRAM ou CGRAM e dados para serem lidos da DDRAM ou CGRAM. O dado escrito no DR automaticamente escrito na DDRAM ou CGRAM por uma operao interna. Esses dois registradores podem ser selecionados pelo register select (RS):

Register Selection RS R/W Operation 0 0 1 1 0 IR write as an internal operation (display clear, etc.) 1 Read busy flag (DB7) and address counter (DB0 to DB6) 0 1 DR write as an internal operation (DR to DDRAM or CGRAM) DR read as an internal operation (DDRAM or CGRAM to DR)

Busy Flag (BF):


Quando o busy flag 1, o HD44780 est no modo de operao interno e a prxima instruo no ser aceita. Quando RS = 0 e R/W = 1, o busy flag colocado na sada do DB7. A instruo seguinte deve ser escrita aps ter-se assegurado de que o busy flag 0.

Address Counter (AC):


O AC atribui endereos para DDRAM e CGRAM. Quando o endereo de uma instruo setada no DDRAM/CGRAM escrito dentro do IR, o endereo da informao mandado do IR para o AC. A seleo tanto do DDRAM como do CGRAM determinada tambm simultaneamente pela instruo. Depois de

escrever na (ou ler da) DDRAM ou CGRAM, o AC automaticamente incrementado ou decrementado por 1. Para mostrar um caractere, a posio do dado escrita no IR (endereo na DDRAM). O cdigo do caractere ento escrito no DR e o LCD mostra o caractere correspondente na posio especificada. O LCD pode ainda incrementar ou decrementar a posio no display depois de cada caractere ter sido mostrado, s que para isso acontecer deve-se ter uma string de caracteres. Para que um caractere seja escrito no display, o mesmo deve ser inicializado antes.

LCD Commands:
+----+-----+-------------------------------------------+ | RS | P0 | Descrio | +----+-----+-------------------------------------------+ | 0 | 38H | 8 bits, 2 linhas, 5 x 8 font | | 0 | 0FH | display on, cursor on, blink on | | 0 | C0H | posiciona o cursor na na linha 1, coluna 0| | 0 | 80H | posiciona o cursor na na linha 0, coluna 0| | 0 | 84H | posiciona o cursor na na linha 0, coluna 4| | 0 | C8H | posiciona o cursor na na linha 1, coluna 8| | 0 | 07H | inc. cursor position, scroll on | | 0 | 01H | clear display | | 1 | xxH | escreve dado xx (ASCII) no display 8 bits | +----+-----+-------------------------------------------+ A informao, tanto de configurao quanto de dado, s ser escrita no display, no evento de uma transio de 1 para 0 no bit EN (P3.6). A transio dever levar, no mnimo, 450 ns para ocorrer (ex. colocar o sinal EN em '1', executar uma rotina de delay para esperar por 450 ns, colocar o sinal EN de volta em '0' para realizar a escrita no display). Um delay em torno de 5 us suficiente.

The commands for HD44780 chip are shown in the table below. INSTRUCTION Function set (8-bit interface, 2 lines, 5*7 Pixels) Function set (8-bit interface, 1 line, 5*7 Pixels) Function set (4-bit interface, 2 lines, 5*7 Pixels) Function set (4-bit interface, 1 line, 5*7 Pixels) Entry mode set Scroll display one character right (all lines) Scroll display one character left (all lines) Home (move cursor to top/left character position) Move cursor one character left Move cursor one character right Decimal 56 48 40 32 See Below 28 24 2 16 20 Hexadecimal 38 30 28 20 See Below 1E 18 2 10 14

Turn on visible underline cursor Turn on visible blinking-block cursor Make cursor invisible Blank the display (without clearing) Restore the display (with cursor hidden) Clear Screen Set cursor position (DDRAM address) Set pointer in character-generator RAM (CG RAM address) Read DDRAM/CGRAM & Check Busy Flag Entry mode set command

14 15 12 8 12 1 128 + addr 64 + addr See Below

0E 0F 0C 08 0C 01 80+ addr 40+ addr See Below

This command sets cursor move direction and display shift ON/OFF. There are 4 possible function set commands;04, 05, 06, and 07. This command changes the direction the cursor moves by setting the address counter to increment or decrement. When the address counter is set to DECREMENT, strings sent to the LCD will be printed in reverse order. The same thing applies to the CG RAM, as well. http://www.geocities.com/dinceraydin/lcd/commands.htm Checking the Busy Flag To check the state of the busy flag and read the address counter: 1. 2. 3. 4. Set R/W Pin of the LCD HIGH(read from the LCD) Select the instruction register by setting RS pin LOW Enable the LCD by Setting the enable pin HIGH The most significant bit of the LCD data bus is the state of the busy flag(1=Busy,0=ready to accept instructions/data).The other bits hold the current value of the address counter.

Complete command reference:

Defining Custom Characters:


Character-Generator ROM and RAM: When you send the ASCII code for a character like A to an LCD module, the modules controller looks up the appropriate 5x8-pixel pattern in ROM (read-only memory) and displays that pattern on the LCD. That charactergenerator ROM contains 192 bit maps corresponding to the alphabet, numbers, punctuation, Japanese Kanji characters, and Greek symbols. The ROM is part of the main LCD controller (e.g., HD44780, KS0066, etc.), is mask-programmed, and cannot be changed by the user. The manufacturers

do offer alternative symbols sets in ROM for European and Asian languages, but most U.S. distributors stock only the standard character set shown in the LCD Serial Backpack manual. Alphanumeric LCD controllers do not allow you to turn individual pixels on or offthey just let you pick a particular pattern (corresponding to an ASCII code) and display it on the screen. If you cant change the ROM and you cant control pixels, how do you create graphics on these LCDs? Easy. Theres a 64-byte hunk of RAM (random-access memory) that the LCD controller uses in the same way as character-generator (CG) ROM. When the controller receives an ASCII code in the range thats mapped to the CG RAM, it uses the bit patterns stored there to display a pattern on the LCD. The main difference is that you can write to CG RAM, thereby defining your own graphic symbols. Each byte of CG RAM is mapped to a five-bit horizontal row of pixels, and LCD characters are typically eight rows high, so 64 bytes of CG RAM is enough to define eight custom characters. These characters correspond to ASCII codes 0 through 7, which normally serve as control codes for marking the beginning of a serial transmission or ringing the bell on a terminal. Since these have no meaning to an LCD module, the designers appropriated them for CG RAM. When an LCD is first powered up, CG RAM contains random bits garbage. If necessary,you may clear CG RAM by writing 00 into each CG RAM cell. Writing to CG RAM: Writing to CG RAM is a lot like moving the cursor to a particular position on the display and displaying characters at that new location. The steps are:

Reset RS and R/W pins of the LCD to prepare the LCD to accept instructions Set the CG RAM address by sending an instruction byte from 64 to 127 (locations 063 in CG RAM). Switch to DATA MODE by changing setting the RS pin Send bytes with the bit patterns for your symbol(s). The LCD controller automatically increments CG RAM addresses, just as it does cursor positions on the display. To leave CG RAM,switch to COMMAND MODE to set address counter to a valid display address (e.g. 128, 1st character of 1st line); the clear-screen instruction (byte 1); or the home instruction (byte 2). Now bytes are once again being written to the visible portion of the display. To see the custom character(s) you have defined, print ASCII codes 0 through 7.

Bitmap layout example:

Simple Animation: You can create a sort of animation by rapidly printing a series of custom characters at the same screen position.

Links:
1) http://www.geocities.com/dinceraydin/lcd/index.html 2) http://www.inf.pucrs.br/~eduardob/disciplinas/topicos_sdacii_pos/8051/Exe mplos_C/display.c

You might also like