72
|
1 /*
|
|
2 * OSTC - diving computer code
|
|
3 * ===========================
|
|
4 * PART 3 : word processor
|
|
5 *
|
|
6 * p3_wordprocessor.c for OSTC Mk.2
|
|
7 * Created on: 17.09.2009
|
|
8 * Author: christian.w @ heinrichsweikamp.com
|
|
9 *
|
|
10 * #include "ostc28.drx.txt"
|
|
11 * #include "ostc28.tbl.txt"
|
|
12 * #include "ostc48.tbl.txt"
|
|
13 * #include "ostc48.drx.txt"
|
|
14 * #include "ostc90.drx.txt"
|
|
15 * #include "ostc90.tbl.txt"
|
|
16 */
|
|
17
|
|
18 // Copyright (C) 2009 HeinrichsWeikamp GbR
|
|
19
|
|
20 // This program is free software: you can redistribute it and/or modify
|
|
21 // it under the terms of the GNU General Public License as published by
|
|
22 // the Free Software Foundation, either version 3 of the License, or
|
|
23 // (at your option) any later version.
|
|
24
|
|
25 // This program is distributed in the hope that it will be useful,
|
|
26 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
27 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
28 // GNU General Public License for more details.
|
|
29
|
|
30 // You should have received a copy of the GNU General Public License
|
|
31 // along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
32
|
|
33
|
|
34 // *****************************
|
|
35 // ** I N T R O D U C T I O N **
|
|
36 // *****************************
|
|
37 //
|
|
38 // OSTC
|
|
39 //
|
|
40 // code:
|
|
41 //
|
|
42 // summary:
|
|
43 // display routines
|
|
44 // for the OSTC experimental project
|
|
45 // written by Christian Weikamp
|
|
46 // last revision __________
|
|
47 // comments added _________
|
|
48 //
|
|
49 // additional files:
|
|
50 // #include "ostc28.drx.txt"
|
|
51 // #include "ostc28.tbl.txt"
|
|
52 // #include "ostc48.tbl.txt"
|
|
53 // #include "ostc48.drx.txt"
|
|
54 // #include "ostc90.drx.txt"
|
|
55 // #include "ostc90.tbl.txt"
|
|
56 // assembler code (PART 1) for working OSTC experimental plattform
|
|
57 // C code (PART 2) for working OSTC experimental plattform
|
|
58 //
|
|
59 // history:
|
|
60 //
|
|
61
|
|
62
|
|
63 // *********************
|
|
64 // ** I N C L U D E S **
|
|
65 // *********************
|
|
66 #include <p18f4685.h>
|
|
67
|
|
68 // ********************************
|
|
69 // ** C O N F I G U R A T I O N **
|
|
70 // ** for simulation without asm **
|
|
71 // ********************************
|
|
72 #pragma config OSC = IRCIO67
|
|
73 #pragma config FCMEN = OFF
|
|
74 #pragma config IESO = OFF
|
|
75 #pragma config PWRT = ON
|
|
76 #pragma config BOREN = OFF
|
|
77 #pragma config WDT = OFF
|
|
78 #pragma config WDTPS = 128
|
|
79 #pragma config MCLRE = ON
|
|
80 #pragma config LPT1OSC = OFF
|
|
81 #pragma config PBADEN = OFF
|
|
82 #pragma config DEBUG = OFF
|
|
83 #pragma config XINST = OFF
|
|
84 #pragma config LVP = OFF
|
|
85 #pragma config STVREN = OFF
|
|
86
|
|
87 // ****************************
|
|
88 // ** D E F I N E S **
|
|
89 // ** missing in p18f4685.h **
|
|
90 // ****************************
|
|
91
|
|
92 #define WP_FONT_SMALL_HEIGHT 24
|
|
93 #define WP_FONT_MEDIUM_HEIGHT 32
|
|
94 #define WP_FONT_LARGE_HEIGHT 58
|
|
95 #define oled_rw PORTA,2,0
|
|
96 #define oled_rs PORTE,0,0
|
|
97
|
|
98 // ***********************
|
|
99 // ** V A R I A B L E S **
|
|
100 // ***********************
|
|
101
|
|
102 #pragma udata bank0a=0x060
|
|
103 // input
|
|
104 volatile unsigned char wp_stringstore[26];
|
|
105 volatile unsigned char wp_color1;
|
|
106 volatile unsigned char wp_color2;
|
|
107 volatile unsigned char wp_top;
|
|
108 volatile unsigned char wp_leftx2;
|
|
109 volatile unsigned char wp_font;
|
|
110 volatile unsigned char wp_invert;
|
|
111 // internal
|
|
112 volatile unsigned char wp_temp_U8;
|
|
113 volatile unsigned char wp_txtptr;
|
|
114 volatile unsigned char wp_char;
|
|
115 volatile unsigned char wp_command;
|
|
116 volatile unsigned int wp_data_16bit;
|
|
117 volatile unsigned char wp_data_8bit_one;
|
|
118 volatile unsigned char wp_data_8bit_two;
|
|
119 volatile unsigned int wp_start;
|
|
120 volatile unsigned int wp_end;
|
|
121 volatile unsigned int wp_i;
|
|
122 volatile unsigned char wp_black;
|
|
123 volatile unsigned char wp_debug_U8;
|
|
124
|
|
125
|
|
126 // *************************
|
|
127 // ** P R O T O T Y P E S **
|
|
128 // *************************
|
|
129 void main(void);
|
|
130
|
|
131 void main_calc_wordprocessor(void);
|
|
132
|
|
133 void wp_write_command(void);
|
|
134 void wp_write_data(void);
|
|
135 void wp_write_black(void);
|
|
136 void wp_write_color(void);
|
|
137 void wp_set_window(void);
|
|
138 void wp_set_char_font_small(void);
|
|
139 void wp_set_char_font_medium(void);
|
|
140 void wp_set_char_font_large(void);
|
|
141 void wordprocessor(void);
|
|
142
|
|
143 // *******************************
|
|
144 // ** start **
|
|
145 // ** necessary for compilation **
|
|
146 // *******************************
|
|
147 #pragma romdata der_code = 0x0000
|
|
148 #pragma code der_start = 0x0000
|
|
149 void der_start(void)
|
|
150 {
|
|
151 _asm
|
|
152 goto main
|
|
153 _endasm
|
|
154 }
|
|
155
|
|
156 // ***********************************
|
|
157 // ** main code for simulation / **
|
|
158 // ** tests without assembler code **
|
|
159 // ** is NOT a part of the OSTC **
|
|
160 // ***********************************
|
|
161 #pragma code main = 0x9000
|
|
162 void main(void)
|
|
163 {
|
|
164 wp_top = 10;
|
|
165 wp_leftx2 = 10;
|
|
166 wp_color1 = 255;
|
|
167 wp_color2 = 255;
|
|
168 wp_font = 0;
|
|
169 wp_invert = 0;
|
|
170 wp_stringstore[0] = ' ';
|
|
171 wp_stringstore[1] = '!';
|
|
172 wp_stringstore[2] = '"';
|
|
173 wp_stringstore[3] = ':';
|
|
174 wp_stringstore[4] = 0;
|
|
175 wordprocessor();
|
|
176 }
|
|
177
|
|
178 // ******************************************************
|
|
179 // ******************************************************
|
|
180 // ** THE FOLLOWING CODE HAS TO BE COPPIED TO THE OSTC **
|
|
181 // ******************************************************
|
|
182 // ******************************************************
|
|
183 // ***************
|
|
184 // ***************
|
|
185 // ** THE FONTS **
|
|
186 // ***************
|
|
187 // ***************
|
|
188 // all new for bigscreen
|
|
189 #pragma romdata font_data_large = 0x09A00
|
|
190 rom const rom unsigned int wp_large_data[] =
|
|
191 {
|
|
192 #include "ostc90.drx.txt" // length 0x59A
|
|
193 };
|
|
194 #pragma romdata font_table_large = 0x09FA0
|
|
195 rom const rom unsigned int wp_large_table[] =
|
|
196 {
|
|
197 #include "ostc90.tbl.txt" // length 0x18
|
|
198 };
|
|
199 #pragma romdata font_table_medium = 0x0A000
|
|
200 rom const rom unsigned int wp_medium_table[] =
|
|
201 {
|
|
202 #include "ostc48.tbl.txt" // length 0x22
|
|
203 };
|
|
204 #pragma romdata font_data_medium = 0x0A024
|
|
205 rom const rom unsigned int wp_medium_data[] =
|
|
206 {
|
|
207 #include "ostc48.drx.txt" // length 0x374 // geht bis einschl. 0xA398
|
|
208 };
|
|
209 #pragma romdata font_table_small = 0x0A39A
|
|
210 rom const rom unsigned int wp_small_table[] =
|
|
211 {
|
|
212 #include "ostc28.tbl.txt" // length 0xE8
|
|
213 };
|
|
214 #pragma romdata font_data_small = 0x0A488
|
|
215 rom const rom unsigned int wp_small_data[] =
|
|
216 {
|
|
217 #include "ostc28.drx.txt"
|
|
218 };
|
|
219
|
|
220 // **********************
|
|
221 // **********************
|
|
222 // ** THE JUMP-IN CODE **
|
|
223 // ** for the asm code **
|
|
224 // **********************
|
|
225 // **********************
|
|
226 #pragma code main_wordprocessor = 0x0B468
|
|
227 void main_wordprocessor(void)
|
|
228 {
|
|
229 wordprocessor();
|
|
230 }
|
|
231
|
|
232 // *********************
|
|
233 // *********************
|
|
234 // ** THE SUBROUTINES **
|
|
235 // *********************
|
|
236 // *********************
|
|
237
|
|
238 #pragma code subroutines2 = 0x0B470 // can be adapted to fit the romdata tables ahead
|
|
239
|
|
240 // ------------
|
|
241 // write new //
|
|
242 // ------------
|
|
243
|
|
244 void wp_write_command(void)
|
|
245 {
|
|
246 _asm
|
|
247 bcf oled_rs
|
|
248 movff wp_command,PORTD
|
|
249 bcf oled_rw
|
|
250 bsf oled_rw
|
|
251 _endasm
|
|
252 }
|
|
253
|
|
254 void wp_write_data(void)
|
|
255 {
|
|
256 wp_data_8bit_one = wp_data_16bit >> 8;
|
|
257 wp_data_8bit_two = wp_data_16bit;
|
|
258 _asm
|
|
259 bsf oled_rs
|
|
260 movff wp_data_8bit_one,PORTD
|
|
261 bcf oled_rw
|
|
262 bsf oled_rw
|
|
263 movff wp_data_8bit_two,PORTD
|
|
264 bcf oled_rw
|
|
265 bsf oled_rw
|
|
266 _endasm
|
|
267 }
|
|
268
|
|
269 void wp_write_black(void)
|
|
270 {
|
|
271 _asm
|
|
272 movff wp_black,PORTD
|
|
273 bcf oled_rw
|
|
274 bsf oled_rw
|
|
275 bcf oled_rw
|
|
276 bsf oled_rw
|
|
277 _endasm
|
|
278 }
|
|
279
|
|
280 void wp_write_color(void)
|
|
281 {
|
|
282 _asm
|
|
283 movff wp_color1,PORTD
|
|
284 bcf oled_rw
|
|
285 bsf oled_rw
|
|
286 movff wp_color2,PORTD
|
|
287 bcf oled_rw
|
|
288 bsf oled_rw
|
|
289 _endasm
|
|
290 }
|
|
291
|
|
292 void wp_set_window(void)
|
|
293 {
|
|
294 // x axis start ( 0 - 319)
|
|
295 wp_command = 0x35;
|
|
296 wp_write_command();
|
|
297 wp_data_16bit = ((unsigned int)wp_leftx2) << 1;
|
|
298 wp_write_data();
|
|
299 // x axis end ( 0 - 319)
|
|
300 wp_command = 0x36;
|
|
301 wp_write_command();
|
|
302 wp_data_16bit = 319;
|
|
303 wp_write_data();
|
|
304 // y axis start + end ( 0 - 239 )
|
|
305 wp_command = 0x37;
|
|
306 wp_write_command();
|
|
307 // the bottom part
|
|
308 wp_data_16bit = wp_top;
|
|
309 if(wp_font == 2)
|
|
310 wp_data_16bit += WP_FONT_LARGE_HEIGHT;
|
|
311 else if(wp_font == 1)
|
|
312 wp_data_16bit += WP_FONT_MEDIUM_HEIGHT;
|
|
313 else
|
|
314 wp_data_16bit += WP_FONT_SMALL_HEIGHT;
|
|
315 wp_data_16bit--;
|
|
316 if(wp_data_16bit > 239)
|
|
317 wp_data_16bit = 239;
|
|
318 // the top part
|
|
319 wp_data_16bit |= ((unsigned int)wp_top) << 8;
|
|
320 // all together in one 16bit transfer
|
|
321 wp_write_data();
|
|
322 // start
|
|
323 wp_command = 0x20;
|
|
324 wp_write_command();
|
|
325 wp_data_16bit = wp_top;
|
|
326 wp_write_data();
|
|
327 wp_command = 0x21;
|
|
328 wp_write_command();
|
|
329 wp_data_16bit = ((unsigned int)wp_leftx2) << 1;
|
|
330 wp_write_data();
|
|
331 }
|
|
332
|
|
333 void wp_set_char_font_small(void)
|
|
334 {
|
|
335 if(wp_char == ' ')
|
|
336 wp_char = '¶';
|
|
337 if (wp_char > 0x7E) // skip space between ~ and ¡
|
|
338 wp_char -= 34;
|
|
339 if((wp_char < '!') || (wp_char > 0xA3)) // font has 34 chars after ~ // ¾ + 4 chars limit to end of battery at the moment
|
|
340 wp_char = 0x82; // ¤
|
|
341 wp_start = wp_small_table[wp_char - '!'];
|
|
342 wp_end = wp_small_table[1 + wp_char - '!'];
|
|
343 }
|
|
344
|
|
345 void wp_set_char_font_medium(void)
|
|
346 {
|
|
347 // space is 3E
|
|
348 if (wp_char == 0x27) // 0x27 == '
|
|
349 wp_char = 0x3B;
|
|
350 if (wp_char == '"')
|
|
351 wp_char = 0x3C;
|
|
352 if (wp_char == 'm')
|
|
353 wp_char = 0x3D;
|
|
354 if (wp_char == ' ')
|
|
355 wp_char = 0x3E;
|
|
356 if((wp_char < '.') || (wp_char > 0x3E))
|
|
357 wp_char = 0x3E;
|
|
358 wp_start = wp_medium_table[wp_char - '.'];
|
|
359 wp_end = wp_medium_table[1 + wp_char - '.'];
|
|
360 }
|
|
361 void wp_set_char_font_large(void)
|
|
362 {
|
|
363 // space is / = 0x2F
|
|
364 if (wp_char == ' ')
|
|
365 wp_char = 0x2F;
|
|
366 if((wp_char < '.') || (wp_char > '9'))
|
|
367 wp_char = 0x2F;
|
|
368 wp_start = wp_large_table[wp_char - '.'];
|
|
369 wp_end = wp_large_table[1 + wp_char - '.'];
|
|
370 }
|
|
371 void wordprocessor(void)
|
|
372 {
|
|
373 #define TOPLIMIT 230
|
|
374 #define LEFTLIMIT 155
|
|
375
|
|
376 if(wp_top > TOPLIMIT)
|
|
377 wp_top = TOPLIMIT;
|
|
378 if(wp_leftx2 > LEFTLIMIT)
|
|
379 wp_leftx2 = LEFTLIMIT;
|
|
380
|
|
381 wp_set_window();
|
|
382 // access to GRAM
|
|
383 wp_command = 0x22;
|
|
384 wp_write_command();
|
|
385 _asm
|
|
386 bsf oled_rs
|
|
387 _endasm
|
|
388 wp_txtptr = 0;
|
|
389 wp_char = wp_stringstore[wp_txtptr];
|
|
390 /*
|
|
391 _asm
|
|
392 lfsr 0x2,0x60
|
|
393 movff 0xfde,wp_char
|
|
394 _endasm
|
|
395 */
|
|
396 if(!wp_char)
|
|
397 {
|
|
398 wp_char = ':';
|
|
399 wp_txtptr = 25;
|
|
400 }
|
|
401 _asm
|
|
402 clrf TBLPTRU, ACCESS
|
|
403 _endasm
|
|
404 while((wp_char) && (wp_txtptr < 26))
|
|
405 {
|
|
406 if(wp_font == 2)
|
|
407 wp_set_char_font_large();
|
|
408 else if(wp_font == 1)
|
|
409 wp_set_char_font_medium();
|
|
410 else
|
|
411 wp_set_char_font_small();
|
|
412 wp_black = 0;
|
|
413 for(wp_i = wp_start; wp_i<wp_end;wp_i++)
|
|
414 {
|
|
415 if(wp_font == 2)
|
|
416 wp_data_16bit = wp_large_data[wp_i / 2];
|
|
417 else if(wp_font == 1)
|
|
418 wp_data_16bit = wp_medium_data[wp_i / 2];
|
|
419 else
|
|
420 wp_data_16bit = wp_small_data[wp_i / 2];
|
|
421 if(wp_i & 1)
|
|
422 wp_temp_U8 = wp_data_16bit & 0xFF;
|
|
423 else
|
|
424 wp_temp_U8 = wp_data_16bit >> 8;
|
|
425 if((wp_temp_U8 & 128))
|
|
426 {
|
|
427 wp_temp_U8 -= 127;
|
|
428 if(wp_invert)
|
|
429 {
|
|
430 while(wp_temp_U8 > 0)
|
|
431 {
|
|
432 wp_temp_U8--;
|
|
433 wp_write_color();
|
|
434 }
|
|
435 }
|
|
436 else
|
|
437 {
|
|
438 _asm
|
|
439 movff wp_black,PORTD
|
|
440 _endasm
|
|
441 while(wp_temp_U8 > 0)
|
|
442 {
|
|
443 wp_temp_U8--;
|
|
444 _asm
|
|
445 bcf oled_rw
|
|
446 bsf oled_rw
|
|
447 bcf oled_rw
|
|
448 bsf oled_rw
|
|
449 _endasm
|
|
450 }
|
|
451 }
|
|
452 }
|
|
453 else
|
|
454 {
|
|
455 wp_temp_U8++;
|
|
456 if(wp_invert)
|
|
457 {
|
|
458 _asm
|
|
459 movff wp_black,PORTD
|
|
460 _endasm
|
|
461 while(wp_temp_U8 > 0)
|
|
462 {
|
|
463 wp_temp_U8--;
|
|
464 _asm
|
|
465 bcf oled_rw
|
|
466 bsf oled_rw
|
|
467 bcf oled_rw
|
|
468 bsf oled_rw
|
|
469 _endasm
|
|
470 }
|
|
471 }
|
|
472 else
|
|
473 {
|
|
474 while(wp_temp_U8 > 0)
|
|
475 {
|
|
476 wp_temp_U8--;
|
|
477 wp_write_color();
|
|
478 }
|
|
479 }
|
|
480 }
|
|
481 }
|
|
482 /*
|
|
483 _asm
|
|
484 movff 0xfde,wp_char
|
|
485 _endasm
|
|
486 */
|
|
487 wp_txtptr++;
|
|
488 wp_char = wp_stringstore[wp_txtptr];
|
|
489 }
|
|
490 wp_command = 0x00;
|
|
491 wp_write_command();
|
|
492 }
|