OpenCores
URL https://opencores.org/ocsvn/Aquarius/Aquarius/trunk

Subversion Repositories Aquarius

[/] [Aquarius/] [trunk/] [application/] [shc_clock/] [main.c] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 thorn_aitc
//===============================
2
// Degital Clock using IRQ Timer
3
//-------------------------------
4
// for VirtexE Evaluation Board
5
// Apr.30 2003 Ver.1
6
//===============================
7
 
8
//======================================================
9
// Address Map
10
//======================================================
11
// address           sz  wt wd device
12
// 00000000-00001FFF  8K 0  32 ROM (code)
13
// 00002000-00003DFF  6K 0  32 RAM (data)
14
// 00003E00-00003FFF 512 0  32 RAM (stack)
15
//
16
// 00000000-0000FFFF 64K 0  32 RAM (shadow every 16KB)
17
// 00010000-0001FFFF 64K 3  32 RAM (shadow every 16KB)
18
// 00020000-0002FFFF 64K 0  16 RAM (shadow every 16KB)
19
// 00030000-0003FFFF 64K 3  16 RAM (shadow every 16KB)
20
// 00040000-ABCCFFFF (shadow RAM)
21
// ABCD0000-ABCD00FF 256 3  32 PIO (shadow every 4B)
22
// ABCD0100-ABCD01FF 256 3  32 UART(shadow every 4B)
23
// ABCD0200-ABCD02FF 256 3  32 SYS (shadow every 8B)
24
// ABCD0300-FFFBFFFF (shadow RAM)
25
// FFFC0000-FFFCFFFF 64K 0  32 RAM (shadow every 16KB)
26
// FFFD0000-FFFDFFFF 64K 3  32 RAM (shadow every 16KB)
27
// FFFE0000-FFFEFFFF 64K 0  16 RAM (shadow every 16KB)
28
// FFFF0000-FFFFFFFF 64K 3  16 RAM (shadow every 16KB)
29
// 
30
//======================================================
31
// PORT OUTPUT
32
//======================================================
33
// ABCD0000 : reserved
34
//   31    30    29    28    27    26    25    24
35
//    7     6     5     4     3     2     1     0
36
//  -----------------------------------------------
37
// |     |     |     |     |     |     |     |     |
38
//  -----------------------------------------------;
39
// 
40
// ABCD0001 : KEYYO (Key SCAN Y-axis out)
41
//   23    22    21    20    19    18    17    16
42
//    7     6     5     4     3     2     1     0
43
//  -----------------------------------------------
44
// |     |     |     | KY4 | KY3 | KY2 | KY1 | KY0 |
45
//  -----------------------------------------------
46
// 
47
// ABCD0002 : LCDCON (LCD Control Signal)
48
//   15    14    13    12    11    10     9     8
49
//    7     6     5     4     3     2     1     0
50
//  -----------------------------------------------
51
// |     |     |     |     |     |  E  | R/W |  RS |
52
//  -----------------------------------------------
53
// 
54
// ABCD0003 : LCDOUT (Write Data to LCD)
55
//    7     6     5     4     3     2     1     0
56
//    7     6     5     4     3     2     1     0
57
//  -----------------------------------------------
58
// | DW7 | DW6 | DW5 | DW4 | DW3 | DW2 | DW1 | DW0 |
59
//  -----------------------------------------------
60
// 
61
//======================================================
62
// PORT INPUT
63
//======================================================
64
// ABCD0000 : reserved
65
//   31    30    29    28    27    26    25    24
66
//    7     6     5     4     3     2     1     0
67
//  -----------------------------------------------
68
// |     |     |     |     |     |     |     |     |
69
//  -----------------------------------------------;
70
// 
71
// ABCD0001 : KEYXI (Key SCAN X-axis in)
72
//   23    22    21    20    19    18    17    16
73
//    7     6     5     4     3     2     1     0
74
//  -----------------------------------------------
75
// |     |     |     | KX4 | KX3 | KX2 | KX1 | KX0 |
76
//  -----------------------------------------------
77
// 
78
// ABCD0002 : reserved
79
//  15    14    13    12    11    10     9     8
80
//    7     6     5     4     3     2     1     0
81
//  -----------------------------------------------
82
// |     |     |     |     |     |     |     |    |
83
//  -----------------------------------------------
84
// 
85
// ABCD0003 : LCDIN (Read Data from LCD)
86
//    7     6     5     4     3     2     1     0
87
//    7     6     5     4     3     2     1     0
88
//  -----------------------------------------------
89
// | DR7 | DR6 | DR5 | DR4 | DR3 | DR2 | DR1 | DR0 |
90
//  -----------------------------------------------
91
// 
92
//======================================================
93
// UART: SASC (www.opencores.com)
94
// Simple Asynchronous Serial Communication Device
95
//======================================================
96
// ABCD0100 : UARTBG0 Baud Rate Generator Div0 (R/W)
97
//   31    30    29    28    27    26    25    24
98
//    7     6     5     4     3     2     1     0
99
//  -----------------------------------------------
100
// | B07 | B06 | B05 | B04 | B03 | B02 | B01 | B00 |
101
//  -----------------------------------------------
102
// 
103
// ABCD0101 : UARTBG1 Baud Rate Generator Div1 (R/W)
104
//   23    22    21    20    19    18    17    16
105
//    7     6     5     4     3     2     1     0
106
//  -----------------------------------------------
107
// | B17 | B16 | B15 | B14 | B13 | B12 | B11 | B10 |
108
//  -----------------------------------------------
109
// 
110
// ABCD0102 : UARTCON (TXF=full_o, RXE=empty_o) (R only)
111
//   15    14    13    12    11    10     9      8
112
//    7     6     5     4     3     2     1      0
113
//  -----------------------------------------------
114
// |     |     |     |     |     |     | TXF | RXE |
115
//  -----------------------------------------------
116
// 
117
// ABCD0103 : UARTTXD(W only)/UARTRXD(R only)
118
//    7     6     5     4     3     2     1     0
119
//    7     6     5     4     3     2     1     0
120
//  -----------------------------------------------
121
// | TR7 | TR6 | TR5 | TR4 | TR3 | TR2 | TR1 | TR0 |
122
//  -----------------------------------------------
123
// 
124
//======================================================
125
// System Controller
126
// Interrupt and Exception Controller
127
//======================================================
128
// ABCD0200 : INTCTL Interrupt Control (32bit R/W only)
129
//   31    30    29    28    27    26    25    24
130
//  -----------------------------------------------
131
// |E_NMI|E_IRQ|E_CER|E_DER|E_MRS|     |TMRON|BRKON|
132
//  -----------------------------------------------
133
//   23    22    21    20    19    18    17    16
134
//  -----------------------------------------------
135
// |ILVL3|ILVL2|ILVL1|ILVL0|IVEC7|IVEC6|IVEC5|IVEC4|
136
//  ----------------------------------------------- 
137
//   15    14    13    12    11    10     9     8
138
//  -----------------------------------------------
139
// |IVEC3|IVEC2|IVEC1|IVEC0|TMR11|TMR10|TMR09|TMR08|
140
//  -----------------------------------------------  
141
//    7     6     5     4     3     2     1     0
142
//  -----------------------------------------------
143
// |TMR07|TMR06|TMR05|TMR04|TMR03|TMR02|TMR01|TMR00|
144
//  ----------------------------------------------- 
145
//     bit31: E_NMI Emulate NMI Interrupt     (W only)
146
//     bit30: E_IRQ Emulate IRQ Interrupt     (W only)
147
//     bit29: E_CER Emulate CPU Address Error (W only)
148
//     bit28: E_DER Emulate DMA Address Error (W only)
149
//     bit27: E_MRS Emulate Manual Reset      (W only)                               
150
//     bit26: reserved
151
//     bit25: TMRON INTTMR OFF/ON             (0:OFF, 1:ON)
152
//     bit24: BRKON Address Break(NMI) OFF/ON (0:OFF, 1:ON)
153
//     bit23: ILVL3 IRQ ILevel 3
154
//     bit22: ILVL2 IRQ ILevel 2
155
//     bit21: ILVL1 IRQ ILevel 1
156
//     bit20: ILVL0 IRQ ILevel 0
157
//     bit19: IVEC7 IRQ Vector 7
158
//     bit18: IVEC6 IRQ Vector 6
159
//     bit17: IVEC5 IRQ Vector 5
160
//     bit16: IVEC4 IRQ Vector 4
161
//     bit15: IVEC3 IRQ Vector 3
162
//     bit14: IVEC2 IRQ Vector 2
163
//     bit13: IVEC1 IRQ Vector 1
164
//     bit12: IVEC0 IRQ Vector 0
165
//     bit11: TMR11 (12 bit interval timer to generate IRQ)
166
//     ...
167
//     bit 0: TMR00 (12 bit interval timer to generate IRQ)
168
// 
169
// ABCD0204 : BRKADR Break Address (16bit R/W only)
170
//   15    14    13    12    11    10     9     8
171
//  -----------------------------------------------
172
// |ADR15|ADR14|ADR13|ADR12|ADR11|ADR10|ADR09|ADR08|
173
//  -----------------------------------------------  
174
//    7     6     5     4     3     2     1     0
175
//  -----------------------------------------------
176
// |ADR07|ADR06|ADR05|ADR04|ADR03|ADR02|ADR01|ADR00|
177
//  ----------------------------------------------- 
178
//     bit15: ADR15 Break Address15
179
//     ...
180
//     bit00: ADR00 Break Address00
181
// 
182
 
183
#include "common.h"
184
 
185
//=================
186
// Define Functions
187
//=================
188
void          disp_time(void);
189
void          int_timer(int onoff);
190
unsigned char command(unsigned char *data);
191
unsigned char hex2asc(unsigned char hex);
192
unsigned char asc2hex(unsigned char asc);
193
 
194
void          waitNms(unsigned char n);
195
unsigned char key_scan();
196
unsigned char key_wait_on(void);
197
void          key_wait_off(void);
198
 
199
void          lcd_disp_char(unsigned char data);
200
void          lcd_disp_long(unsigned long data);
201
void          lcd_cursor(unsigned char con);
202
void          lcd_erase(unsigned char pos);
203
void          lcd_message(unsigned char pos, unsigned char *pstr);
204
void          lcd_disp(unsigned char chr);
205
void          lcd_pos(unsigned char pos);
206
void          lcd_ready(void);
207
unsigned char lcd_rd(int);
208
void          lcd_wr(int, unsigned char);
209
void          lcd_init(void);
210
 
211
//----------------
212
// Global Variables
213
//----------------
214
unsigned char mes_welcome[] = "Interrupt! Clock";
215
unsigned char mes_time[]    = "Time----";
216
unsigned char mes_hour[]    = "Input Hour =?   ";
217
unsigned char mes_min[]     = "Input Min  =?   ";
218
unsigned char mes_sec[]     = "Input Sec  =?   ";
219
unsigned char hour;
220
unsigned char min;
221
unsigned char sec;
222
unsigned long clock;
223
unsigned long onesec;
224
int countup;
225
 
226
//============
227
// IRQ Handler
228
//============
229
void irq_handler(void)
230
{
231
    // Timer Interval = 50ns * 2^12 = 50ns * 4096
232
    // 1sec = 50ns * 2E+07 (0x01312d00)
233
 
234
    // clock      onesec
235
    // 00000000   00000000
236
    // 00000000   01312d00
237
    // ...
238
    // 01313000 > 01312d00
239
    // 01313000   01312d00 + 01312d00
240
    // 01313000   02625A00
241
    // 00000000   01312A00
242
    // ....
243
 
244
    if (clock >= onesec)
245
    {
246
        onesec = onesec + 20000000 - clock;
247
        clock = 0;
248
        countup = 1;
249
    }
250
    clock = clock + 4096;
251
}
252
 
253
//============
254
// NMI Handler
255
//============
256
void nmi_handler(void)
257
{
258
}
259
 
260
//=============
261
// TRAP Handler
262
//=============
263
void trap_handler(void)
264
{
265
}
266
 
267
//====================
268
// Illegal Instruction
269
//====================
270
void illegal(void)
271
{
272
}
273
 
274
//==============
275
// Address Error
276
//==============
277
void error(void)
278
{
279
}
280
 
281
//=============
282
// Main Routine
283
//=============
284
void main_sh(void)
285
{
286
    unsigned char key;
287
 
288
    //-----------
289
    // Initialize
290
    //-----------
291
    key_wait_off();
292
    lcd_init();
293
    lcd_message(0, mes_welcome);
294
 
295
    hour    = 0;
296
    min     = 0;
297
    sec     = 0;
298
    clock   = 0;
299
    onesec  = 20000000;
300
    countup = 0;
301
 
302
    disp_time();
303
    int_timer(1);
304
 
305
    //----------------
306
    // Main Event Loop
307
    //----------------
308
    while(1)
309
    {
310
        if (countup)
311
        {
312
            countup = 0;
313
 
314
            sec = sec + 1;
315
            if ((sec % 16) >= 10) sec = sec + 6;
316
            if (sec >= 0x60) sec = 0;
317
 
318
            if (sec == 0) min = min + 1;
319
            if ((min % 16) >= 10) min = min + 6;
320
            if (min >= 0x60) min = 0;
321
 
322
            if ((sec == 0) & (min == 0)) hour = hour + 1;
323
            if ((hour % 16) >= 10) hour = hour + 6;
324
            if (hour >= 0x24) hour = 0;
325
 
326
            disp_time();
327
        }
328
 
329
        //----------------
330
        // Adjust Function
331
        //----------------
332
        if (key_scan() == KEYDAT)
333
        {
334
            waitNms(4);
335
            int_timer(0);
336
 
337
            lcd_message(0, mes_hour);
338
            do
339
            {
340
                key = command(&hour);
341
            } while (hour >= 0x24);
342
            disp_time();
343
 
344
            lcd_message(0, mes_min);
345
            do
346
            {
347
                key = command(&min);
348
            } while (min >= 0x60);
349
            disp_time();
350
 
351
            lcd_message(0, mes_sec);
352
            do
353
            {
354
                key = command(&sec);
355
            } while (sec >= 0x60);
356
            disp_time();
357
 
358
            lcd_message(0, mes_welcome);
359
 
360
            key_wait_off();
361
 
362
            clock   = 0;
363
            onesec  = 20000000;
364
            countup = 0;
365
            int_timer(1);
366
        }
367
    }
368
}
369
 
370
//****************************************************
371
//*                                                  *
372
//*                Service Utilities                 *
373
//*                                                  *
374
//****************************************************
375
 
376
//==================
377
// Display Time
378
//------------------
379
//     Input  : none
380
//     Output : none
381
//==================
382
void disp_time(void)
383
{
384
    lcd_message(16, mes_time);
385
    lcd_disp_char(hour);
386
    lcd_disp(':');
387
    lcd_disp_char(min);
388
    lcd_disp(':');
389
    lcd_disp_char(sec);
390
}
391
 
392
//========================================
393
// Interrupt Timer ON/OFF
394
//----------------------------------------
395
//     Input  : onoff = timer on(1)/off(0)
396
//     Output : none
397
//========================================
398
void int_timer(int onoff)
399
{
400
    if (onoff)
401
        SYS.INTCTL = 0x02140fff;
402
    else
403
        SYS.INTCTL = 0x00040fff;
404
}
405
 
406
//=========================================
407
// Command Handler
408
//-----------------------------------------
409
//     Input  : data    = display char
410
//     Output : command = input command
411
//              data    = input integer
412
//=========================================
413
unsigned char command(unsigned char *data)
414
{
415
    unsigned char key;
416
    int i;
417
 
418
    lcd_pos(14);
419
    lcd_disp_char(*data);
420
 
421
    lcd_cursor(1);
422
    i = 0;
423
 
424
    do
425
    {
426
        if (i == 0) lcd_pos(14);
427
 
428
        key_wait_off();
429
        key = key_wait_on();
430
        if (key <= KEY9)
431
        {
432
            lcd_disp(hex2asc(key));
433
            *data = (*data & ~((0x0F) << ((1-i) * 4))) | (key << ((1-i) * 4));
434
            i = (i + 1) % 2;
435
        }
436
    } while (key != KEYDAT);
437
 
438
    lcd_cursor(0);
439
    return(key);
440
}
441
 
442
//=============================
443
// Convert Hex(nibble) to Ascii
444
//-----------------------------
445
//     Input  : hex (0x00-0x0F)
446
//     Output : hex2asc
447
//=============================
448
unsigned char hex2asc(unsigned char hex)
449
{
450
    hex = hex & 0x0f;
451
    if (hex <= 0x09)
452
        return(hex + '0');
453
    else
454
        return(hex - 0x0a + 'A');
455
}
456
 
457
//=============================
458
// Convert Ascii to Hex(nibble)
459
//-----------------------------
460
//     Input  : asc(0-9, A-F)
461
//     Output : asc2hex
462
//=============================
463
unsigned char asc2hex(unsigned char asc)
464
{
465
    if (asc <= '9')
466
        return((asc - '0') & 0x0f);
467
    else
468
        return((asc - 'A' + 0x0a) & 0x0f);
469
}
470
 
471
//****************************************************
472
//*                                                  *
473
//*                 Key Utilities                    *
474
//*                                                  *
475
//****************************************************
476
 
477
//===================================
478
// Wait until Key On
479
//-----------------------------------
480
//     Input  : none
481
//     Output : key = pushed key code
482
//===================================
483
unsigned char key_wait_on(void)
484
{
485
    unsigned char key;
486
 
487
    while((key = key_scan()) == KEYNONE) waitNms(4);
488
 
489
    return(key);
490
}
491
 
492
//===================
493
// Wait until Key Off
494
//-------------------
495
//     Input  : none
496
//     Output : none
497
//===================
498
void key_wait_off(void)
499
{
500
    while(key_scan() != KEYNONE) waitNms(4);
501
}
502
 
503
//===================================
504
// Key Scan
505
//-----------------------------------
506
//     Input  : none
507
//     Output : key = pushed key code
508
//===================================
509
unsigned char key_scan()
510
{
511
    unsigned char keyx4;
512
    unsigned char keyx3;
513
    unsigned char keyx2;
514
    unsigned char keyx1;
515
    unsigned char keyx0;
516
 
517
    PORTO.KEYYO.BYTE = 0xef; // KEYY4
518
    waitNms(1);
519
    keyx4 = PORTI.KEYXI.BYTE & 0x1f;
520
 
521
    PORTO.KEYYO.BYTE = 0xf7; // KEYY3
522
    waitNms(1);
523
    keyx3 = PORTI.KEYXI.BYTE & 0x1f;
524
 
525
    PORTO.KEYYO.BYTE = 0xfb; // KEYY2
526
    waitNms(1);
527
    keyx2 = PORTI.KEYXI.BYTE & 0x1f;
528
 
529
    PORTO.KEYYO.BYTE = 0xfd; // KEYY1
530
    waitNms(1);
531
    keyx1 = PORTI.KEYXI.BYTE & 0x1f;
532
 
533
    PORTO.KEYYO.BYTE = 0xfe; // KEYY0
534
    waitNms(1);
535
    keyx0 = PORTI.KEYXI.BYTE & 0x1f;
536
 
537
    switch(keyx4)
538
    {
539
        case 0x17 : return(KEYPUT);
540
        case 0x1b : return(KEYGET);
541
        case 0x1d : return(KEYRUN);
542
        case 0x1e : return(KEYUTL);
543
    }
544
    switch(keyx3)
545
    {
546
        case 0x0f : return(KEYADR);
547
        case 0x17 : return(KEYF);
548
        case 0x1b : return(KEYE);
549
        case 0x1d : return(KEYD);
550
        case 0x1e : return(KEYC);
551
    }
552
    switch(keyx2)
553
    {
554
        case 0x0f : return(KEYINC);
555
        case 0x17 : return(KEYB);
556
        case 0x1b : return(KEYA);
557
        case 0x1d : return(KEY9);
558
        case 0x1e : return(KEY8);
559
    }
560
    switch(keyx1)
561
    {
562
        case 0x0f : return(KEYDEC);
563
        case 0x17 : return(KEY7);
564
        case 0x1b : return(KEY6);
565
        case 0x1d : return(KEY5);
566
        case 0x1e : return(KEY4);
567
    }
568
    switch(keyx0)
569
    {
570
        case 0x0f : return(KEYDAT);
571
        case 0x17 : return(KEY3);
572
        case 0x1b : return(KEY2);
573
        case 0x1d : return(KEY1);
574
        case 0x1e : return(KEY0);
575
    }
576
    return(KEYNONE);
577
}
578
 
579
//==================
580
// Wait n ms
581
//------------------
582
//     Input  : n ms
583
//     Output : none
584
//==================
585
void waitNms(unsigned char n)
586
{
587
    int  i, j;
588
    unsigned char dummy;
589
 
590
    for (i = 0 ; i < n ; i++)
591
    {
592
        // 1ms = 20000 * 50ns (20MHz)
593
        for (j = 0 ; i <= 10000 ; i++) dummy = PORTI.RESERVED_0;
594
    }
595
}
596
 
597
//****************************************************
598
//*                                                  *
599
//*                 LCD Utilities                    *
600
//*                                                  *
601
//****************************************************
602
 
603
//======================================
604
// LCD Display Char Hex data (2 digit)
605
//--------------------------------------
606
//     Input  : data = display char data
607
//     Output : none
608
//======================================
609
void lcd_disp_char(unsigned char data)
610
{
611
    int i;
612
    unsigned char digit;
613
 
614
    for (i = 1 ; i >= 0 ; i--)
615
    {
616
        digit = (unsigned char) (data / (1 << i * 4)) % 0x10;
617
        lcd_disp(hex2asc(digit));
618
    }
619
}
620
 
621
//======================================
622
// LCD Display Long Hex data (8 digit)
623
//--------------------------------------
624
//     Input  : data = display long data
625
//     Output : none
626
//======================================
627
void lcd_disp_long(unsigned long data)
628
{
629
    int i;
630
    unsigned char digit;
631
 
632
    for (i = 7 ; i >= 0 ; i--)
633
    {
634
        digit = (unsigned char) (data / (1 << i * 4)) % 0x10;
635
        lcd_disp(hex2asc(digit));
636
    }
637
}
638
 
639
//================================
640
// Cursor On/Off
641
//--------------------------------
642
//     Input  : cur = off(0)/on(1)
643
//     Output : none
644
//================================
645
void lcd_cursor(unsigned char con)
646
{
647
    lcd_ready();
648
    if (con)
649
        lcd_wr(INST, 0x0d);
650
    else
651
        lcd_wr(INST, 0x0c);
652
}
653
 
654
 
655
//===============================
656
// Erase 1 line from the position
657
//-------------------------------
658
//     Input  : pos = position
659
//               1st line = 00-15
660
//               2nd line = 16-31
661
//     Ouput  : none
662
//===============================
663
void lcd_erase(unsigned char pos)
664
{
665
    int i;
666
 
667
    lcd_pos(pos);
668
    for (i = 0; i < 16; i++) lcd_disp(' ');
669
}
670
 
671
//========================================
672
// Print a Message from Current Position
673
//----------------------------------------
674
//     Input  : pstr = message top address
675
//     Outpur : none
676
//========================================
677
void lcd_message(unsigned char pos, unsigned char *pstr)
678
{
679
    unsigned char *pmessage;
680
 
681
    lcd_pos(pos);
682
    pmessage = pstr;
683
    while (*pmessage) lcd_disp(*pmessage++);
684
}
685
 
686
//==========================================
687
// Display One Character on Current Position
688
//------------------------------------------
689
//     Input  : chr = display charcter
690
//     Output : none
691
//==========================================
692
void lcd_disp(unsigned char chr)
693
{
694
    lcd_ready();
695
    lcd_wr(DATA, chr);
696
}
697
 
698
//================================
699
// Set LCD Display Position
700
//--------------------------------
701
//     Input  : pos = position
702
//                1st line = 00-15
703
//                2nd line = 16-31
704
//     Ouput  : none
705
//================================
706
void lcd_pos(unsigned char pos)
707
{
708
    unsigned char phypos;
709
 
710
    phypos = pos % 32;
711
    if (phypos >= 16)
712
        phypos = (phypos - 16) + 64;
713
    phypos = phypos | 0x80;
714
 
715
    lcd_ready();
716
    lcd_wr(INST, phypos);
717
}
718
 
719
//=====================
720
// Wait until LCD ready
721
//---------------------
722
//     Input  : none
723
//     Output : none 
724
//=====================
725
void lcd_ready(void)
726
{
727
    while ((lcd_rd(INST) & 0x80) == 0x80);
728
}
729
 
730
//=================================
731
// LCD Read
732
//---------------------------------
733
//     Input  : rs (0=Instr,1=Data)
734
//     Output : lcd_rd (Read Data) 
735
//=================================
736
unsigned char lcd_rd(int rs)
737
{
738
    int i;
739
    unsigned char dummy;
740
    unsigned char data;
741
 
742
    PORTO.LCDCON.BYTE = 0x02 | (rs & 0x01);
743
 
744
    // wait 60ns = 2cyc@20MHz
745
    dummy = PORTI.RESERVED_0;
746
    dummy = PORTI.RESERVED_0;
747
 
748
 
749
    PORTO.LCDCON.BYTE = 0x06 | (rs & 0x01);
750
 
751
    // wait 500ns = 10cyc@20MHz
752
    for (i = 0 ; i <= 10 ; i++) dummy = PORTI.RESERVED_0;
753
 
754
    data = PORTI.LCDIN;
755
 
756
    PORTO.LCDCON.BYTE = 0x02 | (rs & 0x01);
757
 
758
    // wait 500ns = 10cyc@20MHz
759
    for (i = 0 ; i <= 10 ; i++) dummy = PORTI.RESERVED_0;
760
 
761
    return(data);
762
}
763
 
764
//=================================
765
// LCD Write
766
//---------------------------------
767
//     Input  : rs (0=Instr,1=Data)
768
//              wd (Write Data)
769
//     Output : none
770
//=================================
771
void lcd_wr(int rs, unsigned char wd)
772
{
773
    int i;
774
    unsigned char dummy;
775
 
776
    PORTO.LCDOUT = wd;
777
 
778
    PORTO.LCDCON.BYTE = 0x00 | (rs & 0x01);
779
 
780
    // wait 60ns = 2cyc@20MHz
781
    dummy = PORTI.RESERVED_0;
782
    dummy = PORTI.RESERVED_0;
783
 
784
    PORTO.LCDCON.BYTE = 0x04 | (rs & 0x01);
785
 
786
    // wait 500ns = 10cyc@20MHz
787
    for (i = 0 ; i <= 10 ; i++) dummy = PORTI.RESERVED_0;
788
 
789
    PORTO.LCDCON.BYTE = 0x00 | (rs & 0x01);
790
 
791
    // wait 500ns = 10cyc@20MHz
792
    for (i = 0 ; i <= 10 ; i++) dummy = PORTI.RESERVED_0;
793
}
794
 
795
//==================
796
// LCD Initialize
797
//------------------
798
//     Input  : none
799
//     Output : none
800
//==================
801
void lcd_init(void)
802
{
803
    int i;
804
    unsigned char dummy;
805
 
806
    lcd_wr(INST, 0x30);
807
 
808
    // wait 4100us=82000cyc@20MHz
809
    for (i = 0 ; i < 82000 ; i++) dummy = PORTI.RESERVED_0;
810
 
811
    lcd_wr(INST, 0x30);
812
 
813
    // wait 100us=2000cyc@20MHz
814
    for (i = 0 ; i < 2000 ; i++) dummy = PORTI.RESERVED_0;
815
 
816
    lcd_wr(INST, 0x30);
817
 
818
    // set function (8bit, 2lines)
819
    lcd_ready();
820
    lcd_wr(INST, 0x38);
821
 
822
    // display (disp on, cursor off, blink off)
823
    lcd_ready();
824
    lcd_wr(INST, 0x0c);
825
 
826
    // clear
827
    lcd_ready();
828
    lcd_wr(INST, 0x01);
829
 
830
    // entry mode (increment, no-shift)
831
    lcd_ready();
832
    lcd_wr(INST, 0x06);
833
}
834
 
835
//===============
836
// End of Program
837
//===============

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.