-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLCD.cpp
79 lines (62 loc) · 1.71 KB
/
LCD.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* LCD.cpp
*
* Created on: Jul 3, 2019
* Author: root
*/
#include "LCD.h";
#include <avr/io.h>
#include <util/delay.h>
#define LCD_Data_Dir DDRF //Registrador do dos dados do lcd
#define LCD_Command_Dir DDRC // registrador dosc comandos do lcd
#define LCD_Data_Port PORTF //Port dos dados
#define LCD_Command_Port PORTC //Port dos comandos
#define RS PC0 // Pino de controle RS
#define RW PC1 // Pino de controle RW
#define EN PC2 // Pino de controle EN
LCD::LCD(){
}
void LCD::LCD_Command(unsigned char cmnd)
{
LCD_Data_Port= cmnd; //comando em hexa nos pinos de controle
LCD_Command_Port &= ~(1<<RS); //coloca Rs em 0
LCD_Command_Port &= ~(1<<RW); // Rw em 0 para modo escrita
LCD_Command_Port |= (1<<EN); // Enable 1 , para escrever comando.
_delay_us(1);
LCD_Command_Port &= ~(1<<EN);
_delay_ms(3);
}
void LCD::LCD_Char (unsigned char char_data)
{
LCD_Data_Port= char_data;
LCD_Command_Port |= (1<<RS);
LCD_Command_Port &= ~(1<<RW);
LCD_Command_Port |= (1<<EN);
_delay_us(1);
LCD_Command_Port &= ~(1<<EN);
_delay_ms(1);
}
void LCD::LCD_Init (void)
{
LCD_Command_Dir = 0xFF; //define como saida 11111111 pinos de controle
LCD_Data_Dir = 0xFF; // pinos de dados como saida
_delay_ms(20); //aguarda inicio do lcd (15ms minimos)
LCD_Command (0x38); // comando para lcd funcionar em 16x2 e 8bits de dados
LCD_Command (0x0C); // display ON cursor off
LCD_Command (0x06); // cursor incrementa sozinho
LCD_Command (0x01); // clear no display
LCD_Command (0x80); // cursor no inicio
}
void LCD::LCD_String (char *str)
{
int i;
for(i=0;str[i]!=0;i++)
{
LCD_Char (str[i]);
}
}
void LCD::LCD_Clear()
{
LCD_Command (0x01); //limpa display
LCD_Command (0x80); // cursor no inicio
}