-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLCD.h
134 lines (122 loc) · 1.64 KB
/
LCD.h
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#define E RB3
#define RS RB2
//#define RW RB6
void pulse()
{
__delay_ms(1);
E = 1;
__delay_ms(1);
E = 0;
}
void LCD_data(char data)
{
RS = 1;
PORTB &= 0x0F;
PORTB |= (data & 0xF0);
pulse();
PORTB &= 0x0F;
PORTB |= (data & 0x0F) << 4;
pulse();
}
void LCD_cmd_hf(char cmd)
{
RS = 0;
PORTB &= 0x0F;
PORTB |= (cmd & 0xF0);
pulse();
}
void LCD_cmd(char cmd)
{
RS = 0;
PORTB &= 0x0F;
PORTB |= (cmd & 0xF0);
pulse();
PORTB &= 0x0F;
PORTB |= (cmd & 0x0F)<<4;
pulse();
}
void LCD_Set_Line(int line)
{
if(line == 1)
{
LCD_cmd(0x80);
}
else if(line == 2)
{
LCD_cmd(0xC0);
}
}
void LCD_CLR()
{
LCD_cmd(0x01);
LCD_cmd(0x80);
}
void setup_LCD()
{
TRISB = 0x00;
PORTB = 0x00;
E = 0;
//RW = 0;
RS = 0;
__delay_ms(30);
LCD_cmd_hf(0x30);
__delay_ms(10);
LCD_cmd_hf(0x30);
__delay_ms(5);
LCD_cmd_hf(0x20);
__delay_ms(5);
LCD_cmd(0x28);
LCD_cmd(0x06);
LCD_cmd(0x0E);
LCD_cmd(0x01);
//LCD_cmd(0x80);
}
void LCD_write(char* a)
{
int g = 0;
while(a[g])
{
LCD_data(a[g]);
g++;
}
}
void LCD_write_int(int a)
{
int b,c,d;
if(a<10)
{
LCD_data(0x30+a);
}
else if(a>9 && a<100)
{
b = a%10;
a = a/10;
LCD_data(0x30+a);
LCD_data(0x30+b);
}
else if(a>99 && a<1000)
{
b = a%10;
a = a/10;
c = a%10;
a = a/10;
LCD_data(0x30+a);
LCD_data(0x30+c);
LCD_data(0x30+b);
}
else if(a>999 && a<10000)
{
b = a%10;
a = a/10;
c = a%10;
a = a/10;
d = a%10;
a = a/10;
LCD_data(0x30+a);
LCD_data(0x30+d);
LCD_data(0x30+c);
LCD_data(0x30+b);
}
else
{}
}