1 | /********** lcd.c *****************/
|
2 | #include <16F1829.H>
|
3 | #include "lcd.h"
|
4 | #use delay(clock=16000000)
|
5 |
|
6 | void LCD_write4Bit(unsigned char zeichen)
|
7 | {
|
8 | LCD_E=0;
|
9 | LCD_D7=zeichen &0x80;
|
10 | LCD_D6=zeichen &0x40;
|
11 | LCD_D5=zeichen &0x20;
|
12 | LCD_D4=zeichen &0x10;
|
13 | LCD_E=1;
|
14 | delay_us(50); //50µs warten
|
15 | LCD_E=0;
|
16 | LCD_D7=zeichen &0x08;
|
17 | LCD_D6=zeichen &0x04;
|
18 | LCD_D5=zeichen &0x02;
|
19 | LCD_D4=zeichen &0x01;
|
20 | LCD_E=1;
|
21 | delay_us(50); //50 µs warten
|
22 | LCD_E=0;
|
23 | }
|
24 |
|
25 | void LCD_reset()
|
26 | {
|
27 | LCD_E=0;
|
28 | LCD_RS=REG;
|
29 | LCD_D7=0;
|
30 | LCD_D6=0;
|
31 | LCD_D5=1;
|
32 | LCD_D4=1;
|
33 | LCD_E=1;
|
34 | delay_ms(5);
|
35 | LCD_E=0;
|
36 | LCD_D7=0;
|
37 | LCD_D6=0;
|
38 | LCD_D5=1;
|
39 | LCD_D4=1;
|
40 | LCD_E=1;
|
41 | delay_us(100);
|
42 | LCD_E=0;
|
43 | LCD_D7=0;
|
44 | LCD_D6=0;
|
45 | LCD_D5=1;
|
46 | LCD_D4=1;
|
47 | LCD_E=1;
|
48 | delay_ms(1);
|
49 | LCD_E=0;
|
50 | }
|
51 |
|
52 |
|
53 | void LCD_init()
|
54 | {
|
55 | LCD_reset();
|
56 | LCD_E=0;
|
57 | LCD_RS=REG;
|
58 | LCD_D7=0;
|
59 | LCD_D6=0;
|
60 | LCD_D5=1;
|
61 | LCD_D4=0;
|
62 | LCD_E=1;
|
63 | delay_ms(2);
|
64 | LCD_E=0;
|
65 | LCD_write4Bit(0x28);
|
66 | delay_ms(2);
|
67 | LCD_write4Bit(0x0c);
|
68 | delay_ms(2);
|
69 | LCD_write4Bit(0x01);
|
70 | delay_ms(2); //1 ms warten
|
71 | }
|
72 |
|
73 | void LCD_del()
|
74 | {
|
75 | LCD_RS=REG; //Registerbefehl
|
76 | LCD_write4Bit(0x01); //Daten werden gesendet
|
77 | delay_ms(1);//700µs warten
|
78 | }
|
79 |
|
80 | void LCD_pos1()
|
81 | {
|
82 | LCD_RS=REG; //Registerbefehl
|
83 | LCD_write4Bit(0x02); //Daten werden gesendet
|
84 | delay_ms(1);//700µs warten
|
85 | }
|
86 |
|
87 | void LCD_on()
|
88 | {
|
89 | LCD_RS=REG; //Registerbefehl
|
90 | LCD_write4Bit(0x0C);//Daten werden gesendet
|
91 | delay_us(50);//50µs warten
|
92 | }
|
93 |
|
94 |
|
95 | void LCD_out(char *text)
|
96 | {
|
97 | LCD_RS=DAT;
|
98 | while(*text!='\0')
|
99 | {
|
100 | LCD_write4Bit(*text++); //string wird zeichen für zeichen ausgegeben bis '\0'
|
101 | }
|
102 | }
|
103 | void LCD_movexy(unsigned char row, unsigned char col)
|
104 | {
|
105 | unsigned char address;
|
106 | if (row==1)
|
107 | {
|
108 | address=0x80+col; //0x80 1.Zeile 1.Zeichen
|
109 | }
|
110 | else
|
111 | {
|
112 | address=0xc0+col; //0xc0 2.Zeile 1.Zeichen
|
113 | }
|
114 | LCD_RS=REG; //Registerbefehl
|
115 | LCD_write4Bit(address); //Daten werden gesendet
|
116 | delay_ms(1);//1 ms warten
|
117 | }
|
118 | void LCD_enable()
|
119 | {
|
120 | LCD_E=1;//negative Flanke wird erzeugt
|
121 | delay_us(50);
|
122 | LCD_E=0;
|
123 | }
|
124 |
|
125 |
|
126 | void DefineBarSigns()
|
127 | {
|
128 | // to set a bar with xx elements 0-100%
|
129 | // 8 rows must be inserted for one user sign
|
130 | unsigned char i;
|
131 | unsigned char addr_inc;
|
132 | unsigned char value=0;
|
133 | unsigned char fac=1;
|
134 |
|
135 | LCD_RS = REG;
|
136 | LCD_write4Bit(0x40); // address 0 character ram
|
137 | // address auto increment
|
138 | delay_ms(1);
|
139 | for(addr_inc=0;addr_inc<6;addr_inc++)
|
140 | {
|
141 | LCD_RS = DAT;
|
142 | LCD_write4Bit(0x1F);//(0b00011111); //Daten werden gesendet
|
143 | delay_ms(1);
|
144 | for (i=0;i<6;i++)
|
145 | {
|
146 | LCD_write4Bit(0x1F-value);//0b00011111 - value
|
147 | delay_ms(1);
|
148 | }
|
149 | LCD_write4Bit(0x1F); //0b00011111
|
150 | delay_ms(1);
|
151 | value=value + fac;
|
152 | fac=fac*2;
|
153 | }
|
154 | }
|
155 |
|
156 | void DrawBar(unsigned char percent) //10 segment
|
157 | {
|
158 | unsigned char i;
|
159 | unsigned char rest=0;
|
160 | unsigned char cnt_full=0;
|
161 | unsigned char cnt_rest=0;
|
162 | unsigned char cnt_barseg=0;
|
163 |
|
164 | if(percent>100)percent=100;
|
165 | if(percent<0)percent=0;
|
166 |
|
167 | cnt_full = percent / 10;
|
168 | rest = percent - cnt_full * 10;
|
169 |
|
170 | for(i=0;i<cnt_full;i++)
|
171 | {
|
172 | LCD_RS=DAT;
|
173 | LCD_write4Bit(0);
|
174 | cnt_barseg++;
|
175 | }
|
176 |
|
177 | if(cnt_full<10)
|
178 | {cnt_rest = rest / 2;
|
179 | LCD_RS=DAT;
|
180 | LCD_write4Bit(5-cnt_rest);
|
181 | cnt_barseg++;
|
182 | }
|
183 | for(i=0;i<(10-cnt_barseg);i++)
|
184 | {
|
185 | LCD_RS=DAT;
|
186 | LCD_write4Bit(5);
|
187 | }
|
188 | }
|