-
Notifications
You must be signed in to change notification settings - Fork 0
/
lcd.c
89 lines (77 loc) · 1.26 KB
/
lcd.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <xc.h>
#include "lcd.h"
#include "atraso.h"
void lcd_wr(unsigned char val)
{
LPORT=val;
}
void lcd_cmd(unsigned char val)
{
LENA=1;
lcd_wr(val);
LDAT=0;
atraso_ms(4);
LENA=0;
atraso_ms(4);
LENA=1;
}
void lcd_dat(unsigned char val)
{
LENA=1;
lcd_wr(val);
LDAT=1;
atraso_ms(4);
LENA=0;
atraso_ms(4);
LENA=1;
}
void lcd_init(void)
{
LENA=0;
LDAT=0;
atraso_ms(20);
LENA=1;
lcd_cmd(L_CFG);
atraso_ms(5);
lcd_cmd(L_CFG);
atraso_ms(1);
lcd_cmd(L_CFG); //configura
lcd_cmd(L_OFF);
lcd_cmd(L_ON); //liga
lcd_cmd(L_CLR); //limpa
lcd_cmd(L_CFG); //configura
lcd_cmd(L_L1);
}
void lcd_str(const char* str)
{
unsigned char i=0;
while(str[i] != 0 )
{
lcd_dat(str[i]);
i++;
}
}
void lcd_set_cursor(unsigned char col, unsigned char row)
{
unsigned char address;
switch(row)
{
case 1:
address = 0x80;
break;
case 2:
address = 0xC0;
break;
case 3:
address = 0x94;
break;
case 4:
address = 0xD4;
break;
default:
address = 0x80;
break;
}
address += (col - 1);
lcd_cmd(address);
}