ET53C - SISTEMAS DIGITAIS Display de Cristal Líquido Profs: Glauber Brante e Mariana Furucho gbrante@utfpr.edu.br marianafurucho@utfpr.edu.br UTFPR Universidade Tecnológica Federal do Paraná DAELT Departamento Acadêmico de Eletrotécnica Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 1 / 21
Objetivos Estudar o funcionamento básico do Display LCD Utilizar as funções de controle do Display LCD no MikroC Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 2 / 21
Display de Cristal Líquido Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 3 / 21
Display de Cristal Líquido Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 4 / 21
Display de Cristal Líquido Gráfico Grande e mais complicado Utiliza controladores externos e tem uma taxa de atualização Texto Simples de usar, porém um pouco mais limitado É suficiente para muitas aplicações!! Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 5 / 21
Display de Cristal Líquido Baseado no controlador HD44780 Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 6 / 21
Pinos do LCD Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 7 / 21
Comandos Básicos I/D: 1 = Increment (by 1) 0 = Decrement (by 1) S: 1 = Display shift on 0 = Display shift off R/L: DL: 1 = Shift right 0 = Shift left 1 = 8-bit interface 0 = 4-bit interface D: 1 = Display on 0 = Display off U: 1 = Cursor on 0 = Cursor off N: 1 = Display in two lines 0 = Display in one line F: 1 = Character format 5x10 dots 0 = Character format 5x7 dots D: 1 = Blink on 0 = Blink off D/C: 1 = Display shift 0 = Cursor shift rof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 8 / 21
Memórias Internas do Display LCD Um display LCD contém três blocos de memória: DDRAM Display Data RAM; CGRAM Character Generator RAM; CGROM Character Generator ROM. Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 9 / 21
CGROM ROM com tabela ASCII Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 10 / 21
CGRAM Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 11 / 21
Hardware Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 12 / 21
Programação Funções da Biblioteca do MikroC: Lcd_Init (); Lcd_Out (char row, char column, char *text); Lcd_Out_Cp (char *text); Lcd_Chr (char row, char column, char out_char); Lcd_Chr_Cp (char out_char); Lcd_Cmd (char out_char); Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 13 / 21
Comandos Comando _LCD_FIRST_ROW _LCD_SECOND_ROW _LCD_CLEAR _LCD_RETURN_HOME _LCD_CURSOR_OFF _LCD_UNDERLINE_ON _LCD_BLINK_CURSOR_ON _LCD_MOVE_CURSOR_LEFT _LCD_MOVE_CURSOR_RIGHT _LCD_TURN_ON _LCD_TURN_OFF _LCD_SHIFT_LEFT _LCD_SHIFT_RIGHT Ação Move para 1a. linha Move para 2a. linha Limpa display (limpa RAM) Retorna cursor/display para posição inicial Desliga cursor Liga cursor traço Liga cursor piscando Move cursor para esquerda Move cursor para direita Liga display Desliga display Desloca display para esquerda Desloca display para direita Prof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 14 / 21
Exemplo (configuração padrão - 4 bits) Exemplo MikroC: // LCD module connections sbit LCD_RS at RD0_bit ; sbit LCD_EN at RD1_bit ; sbit LCD_D4 at RD4_bit ; sbit LCD_D5 at RD5_bit ; sbit LCD_D6 at RD6_bit ; sbit LCD_D7 at RD7_bit ; sbit LCD_RS_Direction at TRISD0_bit ; sbit LCD_EN_Direction at TRISD1_bit ; sbit LCD_D4_Direction at TRISD4_bit ; sbit LCD_D5_Direction at TRISD5_bit ; sbit LCD_D6_Direction at TRISD6_bit ; sbit LCD_D7_Direction at TRISD7_bit ; // End LCD module connections char * text = " Hello World!!! "; void main () { TRISD = 0 x00 ; // configura PORTD como saída Lcd_Init (); // Inicializa display segundo conexoes acima Lcd_Cmd ( _LCD_CLEAR ); // Limpa display Lcd_Cmd ( _LCD_CURSOR_OFF ); // Desliga cursor Lcd_Out (1, 1, text ); // Imprime text no display iniciando na linha 1, coluna 1 rof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 15 / 21
Exemplo (N linhas e com deslocamento) Exemplo MikroC: // LCD module connections sbit LCD_RS at RD0_bit ; sbit LCD_EN at RD1_bit ; sbit LCD_D4 at RD4_bit ; sbit LCD_D5 at RD5_bit ; sbit LCD_D6 at RD6_bit ; sbit LCD_D7 at RD7_bit ; sbit LCD_RS_Direction at TRISD0_bit ; sbit LCD_EN_Direction at TRISD1_bit ; sbit LCD_D4_Direction at TRISD4_bit ; sbit LCD_D5_Direction at TRISD4_bit ; sbit LCD_D6_Direction at TRISD6_bit ; sbit LCD_D7_Direction at TRISD7_bit ; // End LCD module connections char txt1 [] = " Aula de Sistemas "; char txt2 [] = " Digitais "; char txt3 [] = " Exemplo "; char txt4 [] = "N linhas LCD "; char i; // Loop variable void Move_Delay () { // Function used for text moving Delay_ms (500) ; // You can change the moving speed here rof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 16 / 21
Continuação (N linhas e com deslocamento) Exemplo MikroC: void main (){ TRISD = 0 x00 ; Delay_ms (1000) ; Lcd_Init (); // Initialize LCD Delay_ms (2000) ; Lcd_Cmd ( _LCD_CLEAR ); // Clear display Delay_ms (1000) ; Lcd_Cmd ( _LCD_CURSOR_OFF ); // Cursor off Delay_ms (1000) ; Lcd_Out (1,6, txt3 ); // Write text in first row Delay_ms (1000) ; Lcd_Out (2,4, txt4 ); // Write text in second row Delay_ms (1000) ; Lcd_Cmd ( _LCD_CLEAR ); // Clear display Delay_ms (1000) ; Lcd_Out (1,1, txt1 ); // Write text in first row Delay_ms (2000) ; Lcd_Out (2,5, txt2 ); // Write text in second row Delay_ms (2000) ; rof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 17 / 21
Continuação (N linhas e com deslocamento) Exemplo MikroC: // Moving text for (i =0; i <4; i ++) { // Move text to the right 4 times Lcd_Cmd ( _LCD_SHIFT_RIGHT ); Move_Delay (); Delay_ms (500) ; while (1) { // Endless loop for (i =0; i <8; i ++) { // Move text to the left 7 times Lcd_Cmd ( _LCD_SHIFT_LEFT ); Move_Delay (); Delay_ms (500) ; for (i =0; i <8; i ++) { // Move text to the right 7 times Lcd_Cmd ( _LCD_SHIFT_RIGHT ); Move_Delay (); Delay_ms (500) ; rof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 18 / 21
Exibindo Caracter Especial Exemplo MikroC: // LCD module connections sbit LCD_RS at RD0_bit ; sbit LCD_EN at RD1_bit ; sbit LCD_D4 at RD4_bit ; sbit LCD_D5 at RD5_bit ; sbit LCD_D6 at RD6_bit ; sbit LCD_D7 at RD7_bit ; sbit LCD_RS_Direction at TRISD0_bit ; sbit LCD_EN_Direction at TRISD1_bit ; sbit LCD_D4_Direction at TRISD4_bit ; sbit LCD_D5_Direction at TRISD5_bit ; sbit LCD_D6_Direction at TRISD6_bit ; sbit LCD_D7_Direction at TRISD7_bit ; // End LCD module connections char *text = " Feliz na Aula!!"; const char character [] = {14,14,4,21,31,4,31,0; void CustomChar ( char pos_row, char pos_char ) { char i; Lcd_Cmd (64) ; for (i = 0; i <=7; i ++) Lcd_Chr_CP ( character [i]); Lcd_Cmd ( _LCD_RETURN_HOME ); Lcd_Chr ( pos_row, pos_char, 0); rof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 19 / 21
Continuação - Exibindo Caracter Especial Exemplo MikroC: void main () { int i,j; TRISD = 0 x00 ; // configura PORTD como saída Lcd_Init (); // Inicializa display segundo conexoes acima Lcd_Cmd ( _LCD_CLEAR ); // Limpa display Lcd_Cmd ( _LCD_CURSOR_OFF ); // Desliga cursor Lcd_Out (1, 1, text ); // Imprime text no display iniciando na linha 1, coluna 1 while (1) { for (i =1; i ++; i <=16) { delay_ms (500) ; Lcd_Cmd ( _LCD_CLEAR ); // Limpa display CustomChar (1,i); rof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 20 / 21
Exercício Adicional Cronômetro Digital: Desenvolva um cronômetro digital para contar segundos e minutos na forma 00:00 até 59:59 e o exiba no LCD. Simule seu funcionamento no Proteus. rof. Glauber Brante e Mariana Furucho (UTFPR) Display LCD 21 / 21