-
Notifications
You must be signed in to change notification settings - Fork 0
/
lcd.c
60 lines (47 loc) · 1009 Bytes
/
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
#include "pic18f4520.h"
#include "lcd.h"
#include "delay.h"
void lcd_wr(unsigned char val) {
PORTD = val;
}
void lcd_cmd(unsigned char val) {
BitSet(PORTE,1); // Enable - PORTEbits.RE1
lcd_wr(val);
BitClr(PORTE,2); // Data - PORTEbits.RE2
atraso_ms(3);
BitClr(PORTE,1);
atraso_ms(3);
BitSet(PORTE,1);
}
void lcd_dat(unsigned char val) {
BitSet(PORTE,1);
lcd_wr(val);
BitSet(PORTE,2);
atraso_ms(3);
BitClr(PORTE,1);
atraso_ms(3);
BitSet(PORTE,1);
}
void lcd_init(void) {
BitClr(PORTE,1);
BitClr(PORTE,2);
atraso_ms(20);
BitSet(PORTE,1);
lcd_cmd(L_CFG);
atraso_ms(5);
lcd_cmd(L_CFG);
atraso_ms(1);
lcd_cmd(L_CFG); //configura
lcd_cmd(L_OFF); //desliga
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++;
}
}