Repository navigation
Expand file tree
/
Copy pathhd44780.c
More file actions
executable file
·179 lines (141 loc) · 3.16 KB
/
Copy pathhd44780.c
File metadata and controls
executable file
·179 lines (141 loc) · 3.16 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include<avr/io.h>
#include<util/delay.h>
#include "hd44780.h"
/*--------------------------------------------------------*/
/* Zapis danej lub instrukcji */
void WriteToLCD (unsigned char v,unsigned char rs)
{
unsigned char bf;
SET_OUT_LCD_D4;
SET_OUT_LCD_D5;
SET_OUT_LCD_D6;
SET_OUT_LCD_D7;
if(v&0x10) SET_LCD_D4; else CLR_LCD_D4;
if(v&0x20) SET_LCD_D5; else CLR_LCD_D5;
if(v&0x40) SET_LCD_D6; else CLR_LCD_D6;
if(v&0x80) SET_LCD_D7; else CLR_LCD_D7;
CLR_LCD_E;
if(rs) SET_LCD_RS;else CLR_LCD_RS;
CLR_LCD_RW;
LCD_NOP;
SET_LCD_E;
LCD_NOP;
CLR_LCD_E;
LCD_NOP;
if(v&0x01) SET_LCD_D4; else CLR_LCD_D4;
if(v&0x02) SET_LCD_D5; else CLR_LCD_D5;
if(v&0x04) SET_LCD_D6; else CLR_LCD_D6;
if(v&0x08) SET_LCD_D7; else CLR_LCD_D7;
LCD_NOP;
SET_LCD_E;
LCD_NOP;
CLR_LCD_E;
LCD_NOP;
SET_IN_LCD_D4;
SET_IN_LCD_D5;
SET_IN_LCD_D6;
SET_IN_LCD_D7;
CLR_LCD_RS;
SET_LCD_RW;
SET_LCD_D7;
/* Przyda?by si? pe?ny odczyt */
do
{
LCD_NOP;
SET_LCD_E;
LCD_NOP;
bf = IS_SET_LCD_D7;
CLR_LCD_E;
LCD_NOP;
SET_LCD_E;
LCD_NOP;
LCD_NOP;
CLR_LCD_E;
}while( bf );
}
/*--------------------------------------------------------*/
/* Funkcja odczytuje adres i flage zajetosci */
unsigned char ReadAddressLCD ( void)
{
unsigned char g = 0 ;
CLR_LCD_RS;
SET_LCD_RW;
SET_IN_LCD_D4;
SET_IN_LCD_D5;
SET_IN_LCD_D6;
SET_IN_LCD_D7;
LCD_NOP;
SET_LCD_E;
LCD_NOP;
if(IS_SET_LCD_D4) g+=16;
if(IS_SET_LCD_D4) g+=32;
if(IS_SET_LCD_D4) g+=64;
if(IS_SET_LCD_D4) g+=128;
CLR_LCD_E;
LCD_NOP;
SET_LCD_E;
LCD_NOP;
if(IS_SET_LCD_D4) g+=8;
if(IS_SET_LCD_D4) g+=4;
if(IS_SET_LCD_D4) g+=2;
if(IS_SET_LCD_D4) g+=1;
CLR_LCD_E;
return g ;
}
/*---------------------------------------------------------*/
/* Inicjalizacja wy?wietlacza */
void lcd_init(void)
{
_delay_ms(31);
SET_OUT_LCD_RS;
SET_OUT_LCD_RW;
SET_OUT_LCD_E;
SET_OUT_LCD_D4;
SET_OUT_LCD_D5;
SET_OUT_LCD_D6;
SET_OUT_LCD_D7;
CLR_LCD_E;
CLR_LCD_RS;
CLR_LCD_RW;
SET_LCD_D4;
SET_LCD_D5;
CLR_LCD_D6;
CLR_LCD_D7;
LCD_NOP;
SET_LCD_E;
LCD_NOP;
CLR_LCD_E;
LCD_NOP;
_delay_ms(10);
LCD_NOP;
SET_LCD_E;
LCD_NOP;
CLR_LCD_E;
LCD_NOP;
_delay_ms(2);
LCD_NOP;
SET_LCD_E;
LCD_NOP;
CLR_LCD_E;
LCD_NOP;
_delay_ms(2);
CLR_LCD_D4;
LCD_NOP;
SET_LCD_E;
LCD_NOP;
CLR_LCD_E;
LCD_NOP;
_delay_us(80);
WriteToLCD (0x28 , LCDCOMMAND) ;
LCD_DISPLAY(0) ;
LCD_CLEAR ;
LCD_ENTRY_MODE(LCDINCREMENT) ;
}
/*--------------------------------------------------------*/
/* Wyswietla tekst na aktualnej pozycji kursora */
void lcd_puts(char *str)
{
unsigned char i =0;
while( str[i])
LCD_WRITE_DATA(str[i++]) ;
}