Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/src/sc1602.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations) (download) (as text)
Wed Aug 22 08:03:12 2012 UTC (11 years, 9 months ago) by tekken_boss
File MIME type: text/x-csrc
File size: 14880 byte(s)
000.001.012: 2012/08/22 16:59 : Single chip mode is implemented.

== Modification
 * [GEN] Single chip mode (Enable ROM_VERSION, default off)
      --> TO CHANGE TO SINGLE CHIP MODE
       * Enable ROM_VERSION
       * Modify Makefile to apply H8-3069_single.x as linker script.
 * [SCI] Transfer debug UI is added.

== Confirmation
 * Compilable. 



1
2 /* --------------------------------------------- */
3 /* H8-3069F SC-1602 control function */
4 /* */
5 /* CPU : Renesus H8/3069F 25MHz */
6 /* Memory : ROM 512KB, RAM 16KB E-RAM 2MB */
7 /* (c) KAZ.Imamura */
8 /* --------------------------------------------- */
9
10
11 #include "sc1602.h"
12
13 #define _DB4 P4DR.BIT.B0
14 #define _DB5 P4DR.BIT.B1
15 #define _DB6 P4DR.BIT.B2
16 #define _DB7 P4DR.BIT.B3
17 #define _RS P4DR.BIT.B4
18 #define _E P4DR.BIT.B5
19
20
21 // -------------------------------------------
22 // Proto type definitions
23 // -------------------------------------------
24 void sc1602_1ms_handler(void);
25 int sc1602_initialize(void);
26 int sc1602_process(void);
27 int sc1602_set_buffer(unsigned char buf, char *data);
28 int sc1602_set_buffer_cursol(unsigned char buf, char *data);
29 int sc1602_set_buffer_uint8(unsigned char buf, char *data, unsigned char uint8);
30 int sc1602_set_buffer_ulong(unsigned char buf, char *data, unsigned long val);
31 int sc1602_set_buffer_dump (unsigned char buf, unsigned char *data);
32 int sc1602_set_buffer_variable1 (unsigned char buf, unsigned char *data);
33 int sc1602_set_buffer_variable2 (unsigned char buf, unsigned short *data);
34 int sc1602_set_buffer_variable3 (unsigned char buf, unsigned long *data);
35 int sc1602_set_buffer_progress_kb (unsigned char buf, unsigned long val1, unsigned long val2);
36 int sc1602_set_buffer_filename (unsigned char buf, unsigned char dir, char *data);
37 int sc1602_set_buffer_filename_cursol (unsigned char buf, unsigned char dir, char *data);
38
39 int sc1602_set_buffer_version (unsigned char buf, unsigned char major, unsigned char minor, unsigned char build);
40
41 // Locals
42 void sc1602_command_output4(char cmd);
43 void sc1602_command_output8(char cmd);
44 void sc1602_character_put(char data);
45 void sc1602_clear_screen( void );
46 void sc1602_locate_screen( unsigned int x, unsigned int y );
47
48
49 // -------------------------------------------
50 // Variables
51 // -------------------------------------------
52 char sc1602_buffer[MAX_LINE][MAX_COLUMN];
53 int sc1602_buffer_updates[MAX_LINE];
54
55 // Locals
56 volatile int lcd_wait_timer;
57 volatile int lcd_proc;
58 volatile int lcd_disable_timer;
59 static const char hex2ascii[] = "0123456789ABCDEF";
60
61 enum lcd_process_mode {
62 LCD_00_INIT,
63 LCD_01_INIT_START1,
64 LCD_02_INIT_WAIT1,
65 LCD_03_INIT_START2,
66 LCD_04_INIT_WAIT2,
67 LCD_05_INIT_START3,
68 LCD_06_INIT_WAIT3,
69 LCD_07_4BIT_SET,
70 LCD_08_DUTY_SET,
71 LCD_09_DISPLAY_SET,
72 LCD_10_MODE_SET,
73 LCD_11_CLEAR_DISPLAY,
74 LCD_12_CHECK1,
75 LCD_13_OUTPUT1,
76 LCD_14_CHECK2,
77 LCD_15_OUTPUT2,
78
79 };
80
81 // -------------------------------------------
82 // Interrupt handlers
83 // -------------------------------------------
84 void sc1602_1ms_handler(void) {
85 if( lcd_wait_timer ) lcd_wait_timer--;
86 if( lcd_disable_timer ) lcd_disable_timer--;
87 }
88
89
90 // -------------------------------------------
91 // Initialize
92 // -------------------------------------------
93 int sc1602_initialize(void) {
94 lcd_wait_timer = 0;
95 lcd_proc = LCD_00_INIT;
96 lcd_disable_timer = 500;
97
98 #if 0
99 sc1602_set_buffer(0, " NCTX-BOX Rev.0 ");
100 sc1602_set_buffer(1, " KAZ.Imamura ");
101 #endif
102 }
103
104 // -------------------------------------------
105 // Main process
106 // -------------------------------------------
107 int sc1602_process(void) {
108 static int data_pos;
109 if( lcd_disable_timer ) return -1;
110
111 switch( lcd_proc ) {
112 case LCD_00_INIT:
113 _RS = 0;
114 lcd_wait_timer = 20; // 20ms wait timer set
115 lcd_proc++;
116 break;
117
118 case LCD_01_INIT_START1:
119 case LCD_03_INIT_START2:
120 case LCD_05_INIT_START3:
121 if( !lcd_wait_timer ) {
122 sc1602_command_output4(0x03);
123 lcd_proc++;
124 }
125 break;
126
127 case LCD_02_INIT_WAIT1:
128 case LCD_04_INIT_WAIT2:
129 case LCD_06_INIT_WAIT3:
130 lcd_proc++;
131 lcd_wait_timer = 5; // 5ms wait timer set
132 _E = 0;
133 break;
134
135 case LCD_07_4BIT_SET:
136 if( !lcd_wait_timer ) {
137 sc1602_command_output4(0x02);
138 lcd_proc++;
139 lcd_wait_timer = 5; // 5ms wait timer set
140 }
141 break;
142
143 case LCD_08_DUTY_SET:
144 if( !lcd_wait_timer ) {
145 sc1602_command_output8(0x28);
146 lcd_proc++;
147 lcd_wait_timer = 5; // 5ms wait timer set
148 }
149 break;
150
151 case LCD_09_DISPLAY_SET:
152 if( !lcd_wait_timer ) {
153 sc1602_command_output8(0x0C); // display on,cursor off,blink off
154 lcd_proc++;
155 lcd_wait_timer = 5; // 5ms wait timer set
156 }
157 break;
158
159 case LCD_10_MODE_SET:
160 if( !lcd_wait_timer ) {
161 sc1602_command_output8(0x06); // address:auto increment,cursor shift:right
162 lcd_proc++;
163 lcd_wait_timer = 5; // 5ms wait timer set
164 }
165 break;
166
167 case LCD_11_CLEAR_DISPLAY:
168 if( !lcd_wait_timer ) {
169 sc1602_command_output8(0x01); // clear display
170 lcd_proc++;
171 lcd_wait_timer = 5; // 5ms wait timer set
172 }
173 break;
174 case LCD_12_CHECK1:
175 if( sc1602_buffer_updates[0] ) {
176 sc1602_buffer_updates[0] = 0;
177 sc1602_locate_screen(0,0);
178 data_pos=0;
179 lcd_proc++;
180 } else {
181 lcd_proc = LCD_14_CHECK2;
182 }
183 break;
184
185 case LCD_13_OUTPUT1:
186 sc1602_character_put( sc1602_buffer[0][data_pos++] );
187 if( data_pos >= 16 ) {
188 lcd_proc++;
189 }
190 break;
191
192 case LCD_14_CHECK2:
193 if( sc1602_buffer_updates[1] ) {
194 sc1602_buffer_updates[1] = 0;
195 sc1602_locate_screen(0,1);
196 data_pos=0;
197 lcd_proc++;
198 } else {
199 lcd_proc = LCD_12_CHECK1;
200 }
201 break;
202
203 case LCD_15_OUTPUT2:
204 sc1602_character_put( sc1602_buffer[1][data_pos++] );
205 if( data_pos >= 16 ) {
206 lcd_proc = LCD_12_CHECK1;
207 }
208 break;
209
210 default:
211 lcd_proc = LCD_00_INIT;
212 break;
213 }
214 return 0;
215 }
216
217 // -------------------------------------------
218 // Buffer set service function
219 // -------------------------------------------
220 int sc1602_set_buffer(unsigned char buf, char *data) {
221 unsigned char rp;
222
223 if( buf >= MAX_LINE ) return -1;
224
225 for(rp=0; rp<MAX_COLUMN; rp++) {
226 sc1602_buffer[buf][rp] = data[rp];
227 }
228 sc1602_buffer_updates[buf] = 1;
229
230 return 0;
231 }
232
233 // -------------------------------------------
234 // Buffer set service function W/ cursol
235 // -------------------------------------------
236 int sc1602_set_buffer_cursol(unsigned char buf, char *data) {
237 sc1602_set_buffer(buf,data);
238 sc1602_buffer[buf][0] = '>';
239 }
240
241 // -------------------------------------------
242 // Buffer set service function W/ uint8 3digit
243 // -------------------------------------------
244 int sc1602_set_buffer_uint8(unsigned char buf, char *data, unsigned char uint8) {
245 sc1602_set_buffer(buf,data);
246 sc1602_buffer[buf][13] = uint8/100+0x30;
247 uint8 %= 100;
248 sc1602_buffer[buf][14] = uint8/10+0x30;
249 sc1602_buffer[buf][15] = uint8%10+0x30;
250 }
251
252 // -------------------------------------------
253 // Buffer set service function W/ ulong 8 digit
254 // -------------------------------------------
255 int sc1602_set_buffer_ulong(unsigned char buf, char *data, unsigned long val) {
256 sc1602_set_buffer(buf,data);
257
258 sc1602_buffer[buf][ 8] = hex2ascii[(val >>28) & 0x0F ];
259 sc1602_buffer[buf][ 9] = hex2ascii[(val >>24) & 0x0F ];
260 sc1602_buffer[buf][10] = hex2ascii[(val >>20) & 0x0F ];
261 sc1602_buffer[buf][11] = hex2ascii[(val >>16) & 0x0F ];
262 sc1602_buffer[buf][12] = hex2ascii[(val >>12) & 0x0F ];
263 sc1602_buffer[buf][13] = hex2ascii[(val >> 8) & 0x0F ];
264 sc1602_buffer[buf][14] = hex2ascii[(val >> 4) & 0x0F ];
265 sc1602_buffer[buf][15] = hex2ascii[(val >> 0) & 0x0F ];
266 }
267
268 // -------------------------------------------
269 // Buffer set service function (mem dump 8byte)
270 // -------------------------------------------
271 int sc1602_set_buffer_dump (unsigned char buf, unsigned char *data) {
272 sc1602_set_buffer(buf," ");
273
274 sc1602_buffer[buf][ 0] = hex2ascii[(*(data + 0) >> 4) & 0x0F ];
275 sc1602_buffer[buf][ 1] = hex2ascii[(*(data + 0) ) & 0x0F ];
276 sc1602_buffer[buf][ 2] = hex2ascii[(*(data + 1) >> 4) & 0x0F ];
277 sc1602_buffer[buf][ 3] = hex2ascii[(*(data + 1) ) & 0x0F ];
278 sc1602_buffer[buf][ 4] = hex2ascii[(*(data + 2) >> 4) & 0x0F ];
279 sc1602_buffer[buf][ 5] = hex2ascii[(*(data + 2) ) & 0x0F ];
280 sc1602_buffer[buf][ 6] = hex2ascii[(*(data + 3) >> 4) & 0x0F ];
281 sc1602_buffer[buf][ 7] = hex2ascii[(*(data + 3) ) & 0x0F ];
282 sc1602_buffer[buf][ 8] = hex2ascii[(*(data + 4) >> 4) & 0x0F ];
283 sc1602_buffer[buf][ 9] = hex2ascii[(*(data + 4) ) & 0x0F ];
284 sc1602_buffer[buf][10] = hex2ascii[(*(data + 5) >> 4) & 0x0F ];
285 sc1602_buffer[buf][11] = hex2ascii[(*(data + 5) ) & 0x0F ];
286 sc1602_buffer[buf][12] = hex2ascii[(*(data + 6) >> 4) & 0x0F ];
287 sc1602_buffer[buf][13] = hex2ascii[(*(data + 6) ) & 0x0F ];
288 sc1602_buffer[buf][14] = hex2ascii[(*(data + 7) >> 4) & 0x0F ];
289 sc1602_buffer[buf][15] = hex2ascii[(*(data + 7) ) & 0x0F ];
290 }
291
292 // -------------------------------------------
293 // Buffer set service function (variable view 1byte)
294 // -------------------------------------------
295 int sc1602_set_buffer_variable1 (unsigned char buf, unsigned char *data) {
296 // 0123456789ABCDEF
297 sc1602_set_buffer(buf," 0x ( )");
298
299 // Hex
300 sc1602_buffer[buf][ 7] = hex2ascii[(*data >> 4) & 0x0F ];
301 sc1602_buffer[buf][ 8] = hex2ascii[(*data ) & 0x0F ];
302 // Decimal
303 sc1602_buffer[buf][12] = hex2ascii[(*data/100) ];
304 sc1602_buffer[buf][13] = hex2ascii[(*data/10) % 10 ];
305 sc1602_buffer[buf][14] = hex2ascii[(*data) % 10 ];
306 }
307
308 // -------------------------------------------
309 // Buffer set service function (variable view 2byte)
310 // -------------------------------------------
311 int sc1602_set_buffer_variable2 (unsigned char buf, unsigned short *data) {
312 // 0123456789ABCDEF
313 sc1602_set_buffer(buf," 0x ( )");
314
315 // Hex
316 sc1602_buffer[buf][ 3] = hex2ascii[(*data >> 12) & 0x0F ];
317 sc1602_buffer[buf][ 4] = hex2ascii[(*data >> 8) & 0x0F ];
318 sc1602_buffer[buf][ 5] = hex2ascii[(*data >> 4) & 0x0F ];
319 sc1602_buffer[buf][ 6] = hex2ascii[(*data ) & 0x0F ];
320 // Decimal
321 sc1602_buffer[buf][10] = hex2ascii[(*data/10000) ];
322 sc1602_buffer[buf][11] = hex2ascii[(*data/1000) % 10 ];
323 sc1602_buffer[buf][12] = hex2ascii[(*data/100) % 10 ];
324 sc1602_buffer[buf][13] = hex2ascii[(*data/10) % 10 ];
325 sc1602_buffer[buf][14] = hex2ascii[(*data) % 10 ];
326 }
327
328 // -------------------------------------------
329 // Buffer set service function (variable view 4byte)
330 // -------------------------------------------
331 int sc1602_set_buffer_variable3 (unsigned char buf, unsigned long *data) {
332 // 0123456789ABCDEF
333 sc1602_set_buffer(buf," 0x ");
334
335 // Hex
336 sc1602_buffer[buf][ 8] = hex2ascii[(*data >> 28) & 0x0F ];
337 sc1602_buffer[buf][ 9] = hex2ascii[(*data >> 24) & 0x0F ];
338 sc1602_buffer[buf][10] = hex2ascii[(*data >> 20) & 0x0F ];
339 sc1602_buffer[buf][11] = hex2ascii[(*data >> 16) & 0x0F ];
340 sc1602_buffer[buf][12] = hex2ascii[(*data >> 12) & 0x0F ];
341 sc1602_buffer[buf][13] = hex2ascii[(*data >> 8) & 0x0F ];
342 sc1602_buffer[buf][14] = hex2ascii[(*data >> 4) & 0x0F ];
343 sc1602_buffer[buf][15] = hex2ascii[(*data ) & 0x0F ];
344 }
345
346 // -------------------------------------------
347 // Buffer set service function (Progress with KB))
348 // -------------------------------------------
349 int sc1602_set_buffer_progress_kb (unsigned char buf, unsigned long val1, unsigned long val2) {
350 unsigned int val3;
351 // 0123456789ABCDEF
352 sc1602_set_buffer(buf," K/ K %");
353
354 val1 /= 1024;
355 sc1602_buffer[buf][ 0] = hex2ascii[(val1/1000) ];
356 sc1602_buffer[buf][ 1] = hex2ascii[(val1/100) % 10 ];
357 sc1602_buffer[buf][ 2] = hex2ascii[(val1/10) % 10 ];
358 sc1602_buffer[buf][ 3] = hex2ascii[(val1) % 10 ];
359 val2 /= 1024;
360 sc1602_buffer[buf][ 6] = hex2ascii[(val2/1000) ];
361 sc1602_buffer[buf][ 7] = hex2ascii[(val2/100) % 10 ];
362 sc1602_buffer[buf][ 8] = hex2ascii[(val2/10) % 10 ];
363 sc1602_buffer[buf][ 9] = hex2ascii[(val2) % 10 ];
364
365 val3 = (unsigned int) (val1*100/val2);
366 sc1602_buffer[buf][12] = hex2ascii[(val3/100) % 10 ];
367 sc1602_buffer[buf][13] = hex2ascii[(val3/10) % 10 ];
368 sc1602_buffer[buf][14] = hex2ascii[(val3) % 10 ];
369 }
370
371 // -------------------------------------------
372 // Buffer set service function (version)
373 // -------------------------------------------
374 int sc1602_set_buffer_version (unsigned char buf, unsigned char major, unsigned char minor, unsigned char build) {
375 // 0123456789ABCDEF
376 sc1602_set_buffer(buf," Ver: . . ");
377
378 // Major
379 sc1602_buffer[buf][ 5] = hex2ascii[(major/100) % 10 ];
380 sc1602_buffer[buf][ 6] = hex2ascii[(major/10) % 10 ];
381 sc1602_buffer[buf][ 7] = hex2ascii[(major) % 10 ];
382 // Minor
383 sc1602_buffer[buf][ 9] = hex2ascii[(minor/100) % 10 ];
384 sc1602_buffer[buf][10] = hex2ascii[(minor/10) % 10 ];
385 sc1602_buffer[buf][11] = hex2ascii[(minor) % 10 ];
386 // Build
387 sc1602_buffer[buf][13] = hex2ascii[(build/100) % 10 ];
388 sc1602_buffer[buf][14] = hex2ascii[(build/10) % 10 ];
389 sc1602_buffer[buf][15] = hex2ascii[(build) % 10 ];
390 }
391
392 // -------------------------------------------
393 // Buffer set service function (file/dir name w/o cursol)
394 // -------------------------------------------
395 int sc1602_set_buffer_filename (unsigned char buf, unsigned char dir, char *data) {
396 unsigned char pos, i;
397
398 // 0123456789ABCDEF
399 if( dir == 0 ) sc1602_set_buffer(buf," ");
400 else sc1602_set_buffer(buf," [ ]");
401
402 pos = 2;
403 for(i=0;i<12;i++)
404 if(data[i]!=0x20) sc1602_buffer[buf][pos++]=data[i];
405 }
406
407
408 // -------------------------------------------
409 // Buffer set service function (file/dir name w/ cursol)
410 // -------------------------------------------
411 int sc1602_set_buffer_filename_cursol (unsigned char buf, unsigned char dir, char *data) {
412 sc1602_set_buffer_filename(buf, dir, data);
413 sc1602_buffer[buf][0] = '>';
414 }
415
416 // -------------------------------------------
417 // Local functions
418 // -------------------------------------------
419 void sc1602_command_output4(char cmd) {
420 _DB4 = (cmd & 0x01) ? 1 : 0;
421 _DB5 = (cmd & 0x02) ? 1 : 0;
422 _DB6 = (cmd & 0x04) ? 1 : 0;
423 _DB7 = (cmd & 0x08) ? 1 : 0;
424 _E = 1;
425 wait_100us();
426 _E = 0;
427 wait_100us();
428 }
429
430 void sc1602_command_output8(char cmd) {
431 sc1602_command_output4((cmd>>4) & 0x0F);
432 sc1602_command_output4((cmd ) & 0x0F);
433 }
434
435 void sc1602_character_put(char data) {
436 _RS = 1;
437 sc1602_command_output4((data>>4) & 0x0F);
438 sc1602_command_output4((data ) & 0x0F);
439 _RS = 0;
440 }
441
442 void sc1602_clear_screen( void ) {
443 sc1602_command_output8(0x01);
444 lcd_disable_timer = 1640;
445 }
446
447 void sc1602_locate_screen( unsigned int x, unsigned int y ) {
448 sc1602_command_output8(0x80|x|((y&0x01)<<6));
449 // sc1602_command_output8(0x80+x+0x40*y);
450 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26