Rev 112 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 112 | Rev 114 | ||
---|---|---|---|
1 | 1 | ||
- | 2 | //#define F_CPU 7372800UL |
|
2 | #define F_CPU 7372800UL |
3 | |
3 | #include <avr/io.h> |
4 | #include <avr/io.h> |
4 | #include <inttypes.h> |
5 | #include <inttypes.h> |
5 | #include <stdlib.h> |
6 | #include <stdlib.h> |
6 | #include <avr/pgmspace.h> |
7 | #include <avr/pgmspace.h> |
7 | #include <util/delay.h> |
8 | #include <util/delay.h> |
8 | 9 | ||
9 | #include "font8x6.h" |
10 | #include "font8x6.h" |
10 | #include "main.h" |
11 | #include "main.h" |
11 | #include "lcd.h" |
12 | #include "lcd.h" |
12 | 13 | ||
13 | #define DISP_W 128 |
14 | #define DISP_W 128 |
14 | #define DISP_H 64 |
15 | #define DISP_H 64 |
15 | // #define LCD_ORIENTATION 0 // 0 MJ Tasten unten / 4 Original Tasten oben |
16 | // #define LCD_ORIENTATION 0 // 0 MJ Tasten unten / 4 Original Tasten oben |
16 | 17 | ||
17 | 18 | ||
18 | uint8_t lcd_xpos; |
19 | uint8_t lcd_xpos; |
19 | uint8_t lcd_ypos; |
20 | uint8_t lcd_ypos; |
20 | //volatile uint8_t display_buffer[1024]; // Display-Puffer, weil nicht zurückgelesen werden kann |
21 | //volatile uint8_t display_buffer[1024]; // Display-Puffer, weil nicht zurückgelesen werden kann |
21 | //volatile uint16_t display_buffer_pointer; // Pointer auf das aktuell übertragene Byte |
22 | //volatile uint16_t display_buffer_pointer; // Pointer auf das aktuell übertragene Byte |
22 | //volatile uint8_t display_buffer_counter; // Hilfszähler zur Selektierung der Page |
23 | //volatile uint8_t display_buffer_counter; // Hilfszähler zur Selektierung der Page |
23 | //volatile uint8_t display_page_counter; // aktuelle Page-Nummer |
24 | //volatile uint8_t display_page_counter; // aktuelle Page-Nummer |
24 | //volatile uint8_t display_mode; // Modus für State-Machine |
25 | //volatile uint8_t display_mode; // Modus für State-Machine |
25 | 26 | ||
26 | 27 | ||
27 | void send_byte (uint8_t data) |
28 | void send_byte (uint8_t data) |
28 | { |
29 | { |
29 | clr_cs(); |
30 | clr_cs(); |
30 | SPDR = data; |
31 | SPDR = data; |
31 | while(!(SPSR & (1<<SPIF))); |
32 | while(!(SPSR & (1<<SPIF))); |
32 | SPSR = SPSR; |
33 | SPSR = SPSR; |
33 | set_cs(); |
34 | set_cs(); |
34 | } |
35 | } |
35 | 36 | ||
36 | void cls (void) |
37 | void cls (void) |
37 | { |
38 | { |
38 | uint16_t i,j; |
39 | uint16_t i,j; |
39 | 40 | ||
40 | for (i=0;i<1024;i++) |
41 | for (i=0;i<1024;i++) |
41 | display_buffer[i] = 0x00; |
42 | display_buffer[i] = 0x00; |
42 | 43 | ||
43 | for (i=0;i<8;i++) |
44 | for (i=0;i<8;i++) |
44 | { |
45 | { |
45 | clr_A0(); |
46 | clr_A0(); |
46 | send_byte(0xB0+i); //1011xxxx |
47 | send_byte(0xB0+i); //1011xxxx |
47 | send_byte(0x10); //00010000 |
48 | send_byte(0x10); //00010000 |
48 | // send_byte(0x04); //00000100 gedreht plus 4 Byte |
49 | // send_byte(0x04); //00000100 gedreht plus 4 Byte |
49 | // send_byte(0x00); //00000000 |
50 | // send_byte(0x00); //00000000 |
50 | send_byte(LCD_ORIENTATION); //00000000 |
51 | send_byte(LCD_ORIENTATION); //00000000 |
51 | 52 | ||
52 | 53 | ||
53 | set_A0(); |
54 | set_A0(); |
54 | for (j=0;j<128;j++) |
55 | for (j=0;j<128;j++) |
55 | send_byte(0x00); |
56 | send_byte(0x00); |
56 | } |
57 | } |
57 | 58 | ||
58 | lcd_xpos = 0; |
59 | lcd_xpos = 0; |
59 | lcd_ypos = 0; |
60 | lcd_ypos = 0; |
60 | } |
61 | } |
61 | 62 | ||
62 | void lcd_cls (void) |
63 | void lcd_cls (void) |
63 | { |
64 | { |
64 | cls(); |
65 | cls(); |
65 | } |
66 | } |
66 | 67 | ||
67 | void wait_1ms(void) |
68 | void wait_1ms(void) |
68 | { |
69 | { |
69 | _delay_ms (1.0); |
70 | _delay_ms (1.0); |
70 | } |
71 | } |
71 | 72 | ||
72 | void wait_ms (uint16_t time) |
73 | void wait_ms (uint16_t time) |
73 | { |
74 | { |
74 | uint16_t i; |
75 | uint16_t i; |
75 | 76 | ||
76 | for (i=0; i<time; i++) |
77 | for (i=0; i<time; i++) |
77 | wait_1ms(); |
78 | wait_1ms(); |
78 | } |
79 | } |
79 | 80 | ||
80 | void lcd_init (void) |
81 | void lcd_init (void) |
81 | { |
82 | { |
82 | lcd_xpos = 0; |
83 | lcd_xpos = 0; |
83 | lcd_ypos = 0; |
84 | lcd_ypos = 0; |
84 | 85 | ||
85 | 86 | ||
86 | DDRB = 0xFF; |
87 | DDRB = 0xFF; |
87 | 88 | ||
88 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<CPHA)|(1<<CPOL)|(1<<SPR1); |
89 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<CPHA)|(1<<CPOL)|(1<<SPR1); |
89 | 90 | ||
90 | set_cs(); |
91 | set_cs(); |
91 | clr_reset(); |
92 | clr_reset(); |
92 | wait_ms(10); |
93 | wait_ms(10); |
93 | set_reset(); |
94 | set_reset(); |
94 | 95 | ||
95 | clr_cs(); |
96 | clr_cs(); |
96 | clr_A0(); |
97 | clr_A0(); |
97 | 98 | ||
98 | send_byte(0x40); |
99 | send_byte(0x40); |
99 | 100 | ||
100 | if (LCD_ORIENTATION == 0) |
101 | if (LCD_ORIENTATION == 0) |
101 | { |
102 | { |
102 | send_byte(0xA1); // A1 normal A0 reverse(original) |
103 | send_byte(0xA1); // A1 normal A0 reverse(original) |
103 | send_byte(0xC0); // C0 normal C8 reverse(original) |
104 | send_byte(0xC0); // C0 normal C8 reverse(original) |
104 | } |
105 | } |
105 | else |
106 | else |
106 | { |
107 | { |
107 | send_byte(0xA0); // A1 normal A0 reverse(original) |
108 | send_byte(0xA0); // A1 normal A0 reverse(original) |
108 | send_byte(0xC8); // C0 normal C8 reverse(original) |
109 | send_byte(0xC8); // C0 normal C8 reverse(original) |
109 | } |
110 | } |
110 | send_byte(0xA6); |
111 | send_byte(0xA6); |
111 | send_byte(0xA2); |
112 | send_byte(0xA2); |
112 | send_byte(0x2F); |
113 | send_byte(0x2F); |
113 | send_byte(0xF8); |
114 | send_byte(0xF8); |
114 | send_byte(0x00); |
115 | send_byte(0x00); |
115 | send_byte(0x27); |
116 | send_byte(0x27); |
116 | send_byte(0x81); |
117 | send_byte(0x81); |
117 | send_byte(0x16); |
118 | send_byte(0x16); |
118 | send_byte(0xAC); |
119 | send_byte(0xAC); |
119 | send_byte(0x00); |
120 | send_byte(0x00); |
120 | send_byte(0xAF); |
121 | send_byte(0xAF); |
121 | 122 | ||
122 | cls(); |
123 | cls(); |
123 | 124 | ||
124 | } |
125 | } |
125 | 126 | ||
126 | void set_adress (uint16_t adress, uint8_t data) |
127 | void set_adress (uint16_t adress, uint8_t data) |
127 | { |
128 | { |
128 | uint8_t page; |
129 | uint8_t page; |
129 | uint8_t column; |
130 | uint8_t column; |
130 | 131 | ||
131 | page = adress >> 7; |
132 | page = adress >> 7; |
132 | 133 | ||
133 | clr_A0(); |
134 | clr_A0(); |
134 | send_byte(0xB0 + page); |
135 | send_byte(0xB0 + page); |
135 | 136 | ||
136 | // column = (adress & 0x7F) + 4; Wenn gedreht |
137 | // column = (adress & 0x7F) + 4; Wenn gedreht |
137 | // column = (adress & 0x7F); |
138 | // column = (adress & 0x7F); |
138 | column = (adress & 0x7F) + LCD_ORIENTATION; |
139 | column = (adress & 0x7F) + LCD_ORIENTATION; |
139 | 140 | ||
140 | send_byte(0x10 + (column >> 4)); |
141 | send_byte(0x10 + (column >> 4)); |
141 | send_byte(column & 0x0F); |
142 | send_byte(column & 0x0F); |
142 | 143 | ||
143 | set_A0(); |
144 | set_A0(); |
144 | send_byte(data); |
145 | send_byte(data); |
145 | } |
146 | } |
146 | 147 | ||
147 | void scroll (void) |
148 | void scroll (void) |
148 | { |
149 | { |
149 | uint16_t adress; |
150 | uint16_t adress; |
150 | 151 | ||
151 | for (adress=0;adress<896;adress++) |
152 | for (adress=0;adress<896;adress++) |
152 | { |
153 | { |
153 | display_buffer[adress] = display_buffer[adress+128]; |
154 | display_buffer[adress] = display_buffer[adress+128]; |
154 | set_adress(adress,display_buffer[adress]); |
155 | set_adress(adress,display_buffer[adress]); |
155 | } |
156 | } |
156 | for (adress=896;adress<1024;adress++) |
157 | for (adress=896;adress<1024;adress++) |
157 | { |
158 | { |
158 | display_buffer[adress] = 0; |
159 | display_buffer[adress] = 0; |
159 | set_adress(adress,0); |
160 | set_adress(adress,0); |
160 | } |
161 | } |
161 | } |
162 | } |
162 | 163 | ||
163 | // |
164 | // |
164 | // x,y = character-Pos. ! |
165 | // x,y = character-Pos. ! |
165 | // |
166 | // |
166 | // mode: 0=Overwrite, 1 = OR, 2 = XOR, 3 = AND, 4 = Delete |
167 | // mode: 0=Overwrite, 1 = OR, 2 = XOR, 3 = AND, 4 = Delete |
167 | void put_char (uint8_t x, uint8_t y, uint8_t c, uint8_t mode) |
168 | void put_char (uint8_t x, uint8_t y, uint8_t c, uint8_t mode) |
168 | { |
169 | { |
169 | uint8_t ch; |
170 | uint8_t ch; |
170 | uint8_t i; |
171 | uint8_t i; |
171 | uint16_t adress; |
172 | uint16_t adress; |
172 | 173 | ||
173 | switch(c) |
174 | switch(c) |
174 | { |
175 | { |
175 | case 'ä': |
176 | case 'ä': |
176 | c = 0x84; |
177 | c = 0x84; |
177 | break; |
178 | break; |
178 | case 'ö': |
179 | case 'ö': |
179 | c = 0x94; |
180 | c = 0x94; |
180 | break; |
181 | break; |
181 | case 'ü': |
182 | case 'ü': |
182 | c = 0x81; |
183 | c = 0x81; |
183 | break; |
184 | break; |
184 | case 'Ä': |
185 | case 'Ä': |
185 | c = 0x8E; |
186 | c = 0x8E; |
186 | break; |
187 | break; |
187 | case 'Ö': |
188 | case 'Ö': |
188 | c = 0x99; |
189 | c = 0x99; |
189 | break; |
190 | break; |
190 | case 'Ü': |
191 | case 'Ü': |
191 | c = 0x9A; |
192 | c = 0x9A; |
192 | break; |
193 | break; |
193 | case 'ß': |
194 | case 'ß': |
194 | c = 0xE1; |
195 | c = 0xE1; |
195 | break; |
196 | break; |
196 | } |
197 | } |
197 | 198 | ||
198 | adress = y*128 + x*6; |
199 | adress = y*128 + x*6; |
199 | adress &= 0x3FF; |
200 | adress &= 0x3FF; |
200 | 201 | ||
201 | for (i=0;i<6;i++) |
202 | for (i=0;i<6;i++) |
202 | { |
203 | { |
203 | ch = pgm_read_byte (&f8x6[0][0] + i + c * 6); |
204 | ch = pgm_read_byte (&f8x6[0][0] + i + c * 6); |
204 | 205 | ||
205 | switch (mode) |
206 | switch (mode) |
206 | { |
207 | { |
207 | case 0: |
208 | case 0: |
208 | display_buffer[adress+i] = ch; |
209 | display_buffer[adress+i] = ch; |
209 | break; |
210 | break; |
210 | case 1: |
211 | case 1: |
211 | display_buffer[adress+i] |= ch; |
212 | display_buffer[adress+i] |= ch; |
212 | break; |
213 | break; |
213 | case 2: |
214 | case 2: |
214 | display_buffer[adress+i] ^= ch; |
215 | display_buffer[adress+i] ^= ch; |
215 | break; |
216 | break; |
216 | case 3: |
217 | case 3: |
217 | display_buffer[adress+i] &= ch; |
218 | display_buffer[adress+i] &= ch; |
218 | break; |
219 | break; |
219 | case 4: |
220 | case 4: |
220 | display_buffer[adress+i] &= ~ch; |
221 | display_buffer[adress+i] &= ~ch; |
221 | break; |
222 | break; |
222 | } |
223 | } |
223 | 224 | ||
224 | set_adress(adress+i,display_buffer[adress+i]); |
225 | set_adress(adress+i,display_buffer[adress+i]); |
225 | } |
226 | } |
226 | } |
227 | } |
227 | 228 | ||
228 | void new_line (void) |
229 | void new_line (void) |
229 | { |
230 | { |
230 | lcd_ypos++; |
231 | lcd_ypos++; |
231 | 232 | ||
232 | if (lcd_ypos > 7) |
233 | if (lcd_ypos > 7) |
233 | { |
234 | { |
234 | scroll(); |
235 | scroll(); |
235 | lcd_ypos = 7; |
236 | lcd_ypos = 7; |
236 | } |
237 | } |
237 | } |
238 | } |
238 | 239 | ||
239 | 240 | ||
240 | void lcd_printp (const char *text, uint8_t mode) |
241 | void lcd_printp (const char *text, uint8_t mode) |
241 | { |
242 | { |
242 | while (pgm_read_byte(text)) |
243 | while (pgm_read_byte(text)) |
243 | { |
244 | { |
244 | if (pgm_read_byte(text) > 0x1F) |
245 | if (pgm_read_byte(text) > 0x1F) |
245 | { |
246 | { |
246 | put_char(lcd_xpos,lcd_ypos,pgm_read_byte(text++),mode); |
247 | put_char(lcd_xpos,lcd_ypos,pgm_read_byte(text++),mode); |
247 | 248 | ||
248 | lcd_xpos++; |
249 | lcd_xpos++; |
249 | if (lcd_xpos > 20) |
250 | if (lcd_xpos > 20) |
250 | { |
251 | { |
251 | lcd_xpos = 0; |
252 | lcd_xpos = 0; |
252 | new_line(); |
253 | new_line(); |
253 | } |
254 | } |
254 | } |
255 | } |
255 | else |
256 | else |
256 | { |
257 | { |
257 | switch (pgm_read_byte(text)) |
258 | switch (pgm_read_byte(text)) |
258 | { |
259 | { |
259 | case 0x0D: |
260 | case 0x0D: |
260 | lcd_xpos = 0; |
261 | lcd_xpos = 0; |
261 | break; |
262 | break; |
262 | case 0x0A: |
263 | case 0x0A: |
263 | new_line(); |
264 | new_line(); |
264 | break; |
265 | break; |
265 | } |
266 | } |
266 | text++; |
267 | text++; |
267 | } |
268 | } |
268 | } |
269 | } |
269 | } |
270 | } |
270 | 271 | ||
271 | void lcd_print_atp (uint8_t x, uint8_t y, const char *text, uint8_t mode) |
272 | void lcd_print_atp (uint8_t x, uint8_t y, const char *text, uint8_t mode) |
272 | { |
273 | { |
273 | lcd_xpos = x; |
274 | lcd_xpos = x; |
274 | lcd_ypos = y; |
275 | lcd_ypos = y; |
275 | lcd_printp (text, mode); |
276 | lcd_printp (text, mode); |
276 | } |
277 | } |
277 | 278 | ||
278 | 279 | ||
279 | void lcd_print (uint8_t *text, uint8_t mode) |
280 | void lcd_print (uint8_t *text, uint8_t mode) |
280 | { |
281 | { |
281 | while (*text) |
282 | while (*text) |
282 | { |
283 | { |
283 | if (*text > 0x1F) |
284 | if (*text > 0x1F) |
284 | { |
285 | { |
285 | put_char(lcd_xpos,lcd_ypos,*text++,mode); |
286 | put_char(lcd_xpos,lcd_ypos,*text++,mode); |
286 | 287 | ||
287 | lcd_xpos++; |
288 | lcd_xpos++; |
288 | if (lcd_xpos > 20) |
289 | if (lcd_xpos > 20) |
289 | { |
290 | { |
290 | lcd_xpos = 0; |
291 | lcd_xpos = 0; |
291 | new_line(); |
292 | new_line(); |
292 | } |
293 | } |
293 | } |
294 | } |
294 | else |
295 | else |
295 | { |
296 | { |
296 | switch (*text) |
297 | switch (*text) |
297 | { |
298 | { |
298 | case 0x0D: |
299 | case 0x0D: |
299 | lcd_xpos = 0; |
300 | lcd_xpos = 0; |
300 | break; |
301 | break; |
301 | case 0x0A: |
302 | case 0x0A: |
302 | new_line(); |
303 | new_line(); |
303 | break; |
304 | break; |
304 | } |
305 | } |
305 | text++; |
306 | text++; |
306 | } |
307 | } |
307 | } |
308 | } |
308 | } |
309 | } |
309 | 310 | ||
310 | void lcd_print_at (uint8_t x, uint8_t y, uint8_t *text, uint8_t mode) |
311 | void lcd_print_at (uint8_t x, uint8_t y, uint8_t *text, uint8_t mode) |
311 | { |
312 | { |
312 | lcd_xpos = x; |
313 | lcd_xpos = x; |
313 | lcd_ypos = y; |
314 | lcd_ypos = y; |
314 | lcd_print(text, mode); |
315 | lcd_print(text, mode); |
315 | } |
316 | } |
316 | 317 | ||
317 | 318 | ||
318 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
319 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
319 | // + Plot (set one Pixel) |
320 | // + Plot (set one Pixel) |
320 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
321 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
321 | // mode: |
322 | // mode: |
322 | // 0=Clear, 1=Set, 2=XOR |
323 | // 0=Clear, 1=Set, 2=XOR |
323 | void lcd_plot (uint8_t xpos, uint8_t ypos, uint8_t mode) |
324 | void lcd_plot (uint8_t xpos, uint8_t ypos, uint8_t mode) |
324 | { |
325 | { |
325 | uint16_t adress; |
326 | uint16_t adress; |
326 | uint8_t mask; |
327 | uint8_t mask; |
327 | 328 | ||
328 | if ((xpos < 128) && (ypos < 64)) |
329 | if ((xpos < 128) && (ypos < 64)) |
329 | { |
330 | { |
330 | adress = (ypos/8) * 128 + xpos; // adress = 0/8 * 128 + 0 = 0 |
331 | adress = (ypos/8) * 128 + xpos; // adress = 0/8 * 128 + 0 = 0 |
331 | mask = 1<<(ypos & 0x07); // mask = 1<<0 = 1 |
332 | mask = 1<<(ypos & 0x07); // mask = 1<<0 = 1 |
332 | 333 | ||
333 | adress &= 0x3FF; |
334 | adress &= 0x3FF; |
334 | 335 | ||
335 | switch (mode) |
336 | switch (mode) |
336 | { |
337 | { |
337 | case 0: |
338 | case 0: |
338 | display_buffer[adress] &=~mask; |
339 | display_buffer[adress] &=~mask; |
339 | break; |
340 | break; |
340 | case 1: |
341 | case 1: |
341 | display_buffer[adress] |= mask; |
342 | display_buffer[adress] |= mask; |
342 | break; |
343 | break; |
343 | case 2: |
344 | case 2: |
344 | display_buffer[adress] ^= mask; |
345 | display_buffer[adress] ^= mask; |
345 | break; |
346 | break; |
346 | } |
347 | } |
347 | 348 | ||
348 | set_adress(adress,display_buffer[adress]); |
349 | set_adress(adress,display_buffer[adress]); |
349 | } |
350 | } |
350 | } |
351 | } |
351 | 352 | ||
352 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
353 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
353 | // + Line (draws a line from x1,y1 to x2,y2 |
354 | // + Line (draws a line from x1,y1 to x2,y2 |
354 | // + Based on Bresenham line-Algorithm |
355 | // + Based on Bresenham line-Algorithm |
355 | // + found in the internet, modified by thkais 2007 |
356 | // + found in the internet, modified by thkais 2007 |
356 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
357 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
357 | 358 | ||
358 | void lcd_line(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, uint8_t mode) |
359 | void lcd_line(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, uint8_t mode) |
359 | 360 | ||
360 | { |
361 | { |
361 | int x,y,count,xs,ys,xm,ym; |
362 | int x,y,count,xs,ys,xm,ym; |
362 | 363 | ||
363 | x=(int)x1; |
364 | x=(int)x1; |
364 | y=(int)y1; |
365 | y=(int)y1; |
365 | xs=(int)x2 - (int)x1; |
366 | xs=(int)x2 - (int)x1; |
366 | ys=(int)y2 - (int)y1; |
367 | ys=(int)y2 - (int)y1; |
367 | if(xs < 0) |
368 | if(xs < 0) |
368 | xm= -1; |
369 | xm= -1; |
369 | else |
370 | else |
370 | if(xs > 0) |
371 | if(xs > 0) |
371 | xm= 1; |
372 | xm= 1; |
372 | else |
373 | else |
373 | xm= 0; |
374 | xm= 0; |
374 | if(ys < 0) |
375 | if(ys < 0) |
375 | ym= -1; |
376 | ym= -1; |
376 | else |
377 | else |
377 | if(ys > 0) |
378 | if(ys > 0) |
378 | ym= 1; |
379 | ym= 1; |
379 | else |
380 | else |
380 | ym= 0; |
381 | ym= 0; |
381 | if(xs < 0) |
382 | if(xs < 0) |
382 | xs= -xs; |
383 | xs= -xs; |
383 | if(ys < 0) |
384 | if(ys < 0) |
384 | ys= -ys; |
385 | ys= -ys; |
385 | 386 | ||
386 | lcd_plot((unsigned char)x, (unsigned char)y, mode); |
387 | lcd_plot((unsigned char)x, (unsigned char)y, mode); |
387 | 388 | ||
388 | if(xs > ys) // Flat Line <45 degrees |
389 | if(xs > ys) // Flat Line <45 degrees |
389 | { |
390 | { |
390 | count= -(xs / 2); |
391 | count= -(xs / 2); |
391 | while(x != x2) |
392 | while(x != x2) |
392 | { |
393 | { |
393 | count= count + ys; |
394 | count= count + ys; |
394 | x= x + xm; |
395 | x= x + xm; |
395 | if(count > 0) |
396 | if(count > 0) |
396 | { |
397 | { |
397 | y= y + ym; |
398 | y= y + ym; |
398 | count= count - xs; |
399 | count= count - xs; |
399 | } |
400 | } |
400 | lcd_plot((unsigned char)x, (unsigned char)y, mode); |
401 | lcd_plot((unsigned char)x, (unsigned char)y, mode); |
401 | } |
402 | } |
402 | } |
403 | } |
403 | else // Line >=45 degrees |
404 | else // Line >=45 degrees |
404 | { |
405 | { |
405 | count=- (ys / 2); |
406 | count=- (ys / 2); |
406 | while(y != y2) |
407 | while(y != y2) |
407 | { |
408 | { |
408 | count= count + xs; |
409 | count= count + xs; |
409 | y= y + ym; |
410 | y= y + ym; |
410 | if(count > 0) |
411 | if(count > 0) |
411 | { |
412 | { |
412 | x= x + xm; |
413 | x= x + xm; |
413 | count= count - ys; |
414 | count= count - ys; |
414 | } |
415 | } |
415 | lcd_plot((unsigned char)x, (unsigned char)y, mode); |
416 | lcd_plot((unsigned char)x, (unsigned char)y, mode); |
416 | } |
417 | } |
417 | } |
418 | } |
418 | } |
419 | } |
419 | 420 | ||
420 | 421 | ||
421 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
422 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
422 | // + Filled rectangle |
423 | // + Filled rectangle |
423 | // + x1, y1 = upper left corner |
424 | // + x1, y1 = upper left corner |
424 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
425 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
425 | 426 | ||
426 | void lcd_frect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode) |
427 | void lcd_frect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode) |
427 | { |
428 | { |
428 | uint16_t x2, y2; |
429 | uint16_t x2, y2; |
429 | uint16_t i; |
430 | uint16_t i; |
430 | 431 | ||
431 | if (x1 >= DISP_W) |
432 | if (x1 >= DISP_W) |
432 | x1 = DISP_W - 1; |
433 | x1 = DISP_W - 1; |
433 | if (y1 >= DISP_H) |
434 | if (y1 >= DISP_H) |
434 | y1 = DISP_H - 1; |
435 | y1 = DISP_H - 1; |
435 | x2 = x1 + widthx; |
436 | x2 = x1 + widthx; |
436 | y2 = y1 + widthy; |
437 | y2 = y1 + widthy; |
437 | 438 | ||
438 | if (x2 > DISP_W) |
439 | if (x2 > DISP_W) |
439 | x2 = DISP_W; |
440 | x2 = DISP_W; |
440 | if (y2 > DISP_H) |
441 | if (y2 > DISP_H) |
441 | y2 = DISP_H; |
442 | y2 = DISP_H; |
442 | 443 | ||
443 | for (i=y1;i<=y2;i++) |
444 | for (i=y1;i<=y2;i++) |
444 | { |
445 | { |
445 | lcd_line(x1,i,x2,i,mode); |
446 | lcd_line(x1,i,x2,i,mode); |
446 | } |
447 | } |
447 | 448 | ||
448 | } |
449 | } |
449 | 450 | ||
450 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
451 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
451 | // + outline of rectangle |
452 | // + outline of rectangle |
452 | // + x1, y1 = upper left corner |
453 | // + x1, y1 = upper left corner |
453 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
454 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
454 | 455 | ||
455 | void lcd_rect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode) |
456 | void lcd_rect (uint8_t x1, uint8_t y1, uint8_t widthx, uint8_t widthy, uint8_t mode) |
456 | { |
457 | { |
457 | uint16_t x2, y2; |
458 | uint16_t x2, y2; |
458 | 459 | ||
459 | if (x1 >= DISP_W) |
460 | if (x1 >= DISP_W) |
460 | x1 = DISP_W - 1; |
461 | x1 = DISP_W - 1; |
461 | if (y1 >= DISP_H) |
462 | if (y1 >= DISP_H) |
462 | y1 = DISP_H - 1; |
463 | y1 = DISP_H - 1; |
463 | x2 = x1 + widthx; |
464 | x2 = x1 + widthx; |
464 | y2 = y1 + widthy; |
465 | y2 = y1 + widthy; |
465 | 466 | ||
466 | if (x2 > DISP_W) |
467 | if (x2 > DISP_W) |
467 | x2 = DISP_W; |
468 | x2 = DISP_W; |
468 | if (y2 > DISP_H) |
469 | if (y2 > DISP_H) |
469 | y2 = DISP_H; |
470 | y2 = DISP_H; |
470 | 471 | ||
471 | lcd_line (x1, y1, x2, y1, mode); |
472 | lcd_line (x1, y1, x2, y1, mode); |
472 | lcd_line (x2, y1, x2, y2, mode); |
473 | lcd_line (x2, y1, x2, y2, mode); |
473 | lcd_line (x2, y2, x1, y2, mode); |
474 | lcd_line (x2, y2, x1, y2, mode); |
474 | lcd_line (x1, y2, x1, y1, mode); |
475 | lcd_line (x1, y2, x1, y1, mode); |
475 | } |
476 | } |
476 | 477 | ||
477 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
478 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
478 | // + outline of a circle |
479 | // + outline of a circle |
479 | // + Based on Bresenham-algorithm found in wikipedia |
480 | // + Based on Bresenham-algorithm found in wikipedia |
480 | // + modified by thkais (2007) |
481 | // + modified by thkais (2007) |
481 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
482 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
482 | 483 | ||
483 | 484 | ||
484 | void draw_circle(int16_t x0, int16_t y0, int16_t radius, uint8_t mode) |
485 | void draw_circle(int16_t x0, int16_t y0, int16_t radius, uint8_t mode) |
485 | { |
486 | { |
486 | int16_t f = 1 - radius; |
487 | int16_t f = 1 - radius; |
487 | int16_t ddF_x = 0; |
488 | int16_t ddF_x = 0; |
488 | int16_t ddF_y = -2 * radius; |
489 | int16_t ddF_y = -2 * radius; |
489 | int16_t x = 0; |
490 | int16_t x = 0; |
490 | int16_t y = radius; |
491 | int16_t y = radius; |
491 | 492 | ||
492 | lcd_plot(x0, y0 + radius, mode); |
493 | lcd_plot(x0, y0 + radius, mode); |
493 | lcd_plot(x0, y0 - radius, mode); |
494 | lcd_plot(x0, y0 - radius, mode); |
494 | lcd_plot(x0 + radius, y0, mode); |
495 | lcd_plot(x0 + radius, y0, mode); |
495 | lcd_plot(x0 - radius, y0, mode); |
496 | lcd_plot(x0 - radius, y0, mode); |
496 | 497 | ||
497 | while(x < y) |
498 | while(x < y) |
498 | { |
499 | { |
499 | if(f >= 0) |
500 | if(f >= 0) |
500 | { |
501 | { |
501 | y --; |
502 | y --; |
502 | ddF_y += 2; |
503 | ddF_y += 2; |
503 | f += ddF_y; |
504 | f += ddF_y; |
504 | } |
505 | } |
505 | x ++; |
506 | x ++; |
506 | ddF_x += 2; |
507 | ddF_x += 2; |
507 | f += ddF_x + 1; |
508 | f += ddF_x + 1; |
508 | 509 | ||
509 | lcd_plot(x0 + x, y0 + y, mode); |
510 | lcd_plot(x0 + x, y0 + y, mode); |
510 | lcd_plot(x0 - x, y0 + y, mode); |
511 | lcd_plot(x0 - x, y0 + y, mode); |
511 | 512 | ||
512 | lcd_plot(x0 + x, y0 - y, mode); |
513 | lcd_plot(x0 + x, y0 - y, mode); |
513 | lcd_plot(x0 - x, y0 - y, mode); |
514 | lcd_plot(x0 - x, y0 - y, mode); |
514 | 515 | ||
515 | lcd_plot(x0 + y, y0 + x, mode); |
516 | lcd_plot(x0 + y, y0 + x, mode); |
516 | lcd_plot(x0 - y, y0 + x, mode); |
517 | lcd_plot(x0 - y, y0 + x, mode); |
517 | 518 | ||
518 | lcd_plot(x0 + y, y0 - x, mode); |
519 | lcd_plot(x0 + y, y0 - x, mode); |
519 | lcd_plot(x0 - y, y0 - x, mode); |
520 | lcd_plot(x0 - y, y0 - x, mode); |
520 | } |
521 | } |
521 | } |
522 | } |
522 | 523 | ||
523 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
524 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
524 | // + filled Circle |
525 | // + filled Circle |
525 | // + modified circle-algorithm thkais (2007) |
526 | // + modified circle-algorithm thkais (2007) |
526 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
527 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
527 | 528 | ||
528 | void draw_fcircle(int16_t x0, int16_t y0, int16_t radius) |
529 | void draw_fcircle(int16_t x0, int16_t y0, int16_t radius) |
529 | { |
530 | { |
530 | int16_t f = 1 - radius; |
531 | int16_t f = 1 - radius; |
531 | int16_t ddF_x = 0; |
532 | int16_t ddF_x = 0; |
532 | int16_t ddF_y = -2 * radius; |
533 | int16_t ddF_y = -2 * radius; |
533 | int16_t x = 0; |
534 | int16_t x = 0; |
534 | int16_t y = radius; |
535 | int16_t y = radius; |
535 | 536 | ||
536 | lcd_line(x0, y0 + radius,x0, y0 - radius,1); |
537 | lcd_line(x0, y0 + radius,x0, y0 - radius,1); |
537 | 538 | ||
538 | lcd_line(x0 + radius, y0,x0 - radius, y0,1); |
539 | lcd_line(x0 + radius, y0,x0 - radius, y0,1); |
539 | 540 | ||
540 | while(x < y) |
541 | while(x < y) |
541 | { |
542 | { |
542 | if(f >= 0) |
543 | if(f >= 0) |
543 | { |
544 | { |
544 | y--; |
545 | y--; |
545 | ddF_y += 2; |
546 | ddF_y += 2; |
546 | f += ddF_y; |
547 | f += ddF_y; |
547 | } |
548 | } |
548 | x++; |
549 | x++; |
549 | ddF_x += 2; |
550 | ddF_x += 2; |
550 | f += ddF_x + 1; |
551 | f += ddF_x + 1; |
551 | 552 | ||
552 | lcd_line(x0 + x, y0 + y,x0 - x, y0 + y,1); |
553 | lcd_line(x0 + x, y0 + y,x0 - x, y0 + y,1); |
553 | lcd_line(x0 + x, y0 - y,x0 - x, y0 - y,1); |
554 | lcd_line(x0 + x, y0 - y,x0 - x, y0 - y,1); |
554 | lcd_line(x0 + y, y0 + x,x0 - y, y0 + x,1); |
555 | lcd_line(x0 + y, y0 + x,x0 - y, y0 + x,1); |
555 | lcd_line(x0 + y, y0 - x,x0 - y, y0 - x,1); |
556 | lcd_line(x0 + y, y0 - x,x0 - y, y0 - x,1); |
556 | } |
557 | } |
557 | } |
558 | } |
558 | 559 |