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

Subversion Repositories Aquarius

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 thorn_aitc
//===============================
2
// LCD Test Program
3
//-------------------------------
4
// for VirtexE Evaluation Board
5
// May.1 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          lcd_message(unsigned char pos, unsigned char *pstr);
189
void          lcd_disp(unsigned char chr);
190
void          lcd_pos(unsigned char pos);
191
void          lcd_ready(void);
192
unsigned char lcd_rd(int);
193
void          lcd_wr(int, unsigned char);
194
void          lcd_init(void);
195
 
196
//=============
197
// Main Routine
198
//=============
199
void main_sh(void)
200
{
201
    unsigned char mes_welcome[]   = "<SuperH in FPGA>";
202
    char data;
203
    int i;
204
 
205
    //-----------
206
    // Initialize
207
    //-----------
208
    lcd_init();
209
    lcd_message(0, mes_welcome);
210
    data = 0;
211
 
212
    //----------
213
    // Main Loop
214
    //----------
215
    while(1)
216
    {
217
        if ((data % 16) == 0) lcd_pos(16);
218
        lcd_disp(data);
219
        data++;
220
 
221
        for (i = 0 ; i < 100000 ; i++);
222
    }
223
}
224
 
225
//****************************************************
226
//*                                                  *
227
//*                 LCD Utilities                    *
228
//*                                                  *
229
//****************************************************
230
 
231
//========================================
232
// Print a Message from Current Position
233
//----------------------------------------
234
//     Input  : pstr = message top address
235
//     Outpur : none
236
//========================================
237
void lcd_message(unsigned char pos, unsigned char *pstr)
238
{
239
    unsigned char *pmessage;
240
 
241
    lcd_pos(pos);
242
    pmessage = pstr;
243
    while (*pmessage) lcd_disp(*pmessage++);
244
}
245
 
246
//==========================================
247
// Display One Character on Current Position
248
//------------------------------------------
249
//     Input  : chr = display charcter
250
//     Output : none
251
//==========================================
252
void lcd_disp(unsigned char chr)
253
{
254
    lcd_ready();
255
    lcd_wr(DATA, chr);
256
}
257
 
258
//================================
259
// Set LCD Display Position
260
//--------------------------------
261
//     Input  : pos = position
262
//                1st line = 00-15
263
//                2nd line = 16-31
264
//     Ouput  : none
265
//================================
266
void lcd_pos(unsigned char pos)
267
{
268
    unsigned char phypos;
269
 
270
    phypos = pos % 32;
271
    if (phypos >= 16)
272
        phypos = (phypos - 16) + 64;
273
    phypos = phypos | 0x80;
274
 
275
    lcd_ready();
276
    lcd_wr(INST, phypos);
277
}
278
 
279
//=====================
280
// Wait until LCD ready
281
//---------------------
282
//     Input  : none
283
//     Output : none 
284
//=====================
285
void lcd_ready(void)
286
{
287
    while ((lcd_rd(INST) & 0x80) == 0x80);
288
}
289
 
290
//=================================
291
// LCD Read
292
//---------------------------------
293
//     Input  : rs (0=Instr,1=Data)
294
//     Output : lcd_rd (Read Data) 
295
//=================================
296
unsigned char lcd_rd(int rs)
297
{
298
    int i;
299
    unsigned char dummy;
300
    unsigned char data;
301
 
302
    PORTO.LCDCON.BYTE = 0x02 | (rs & 0x01);
303
 
304
    // wait 60ns = 2cyc@20MHz
305
    dummy = PORTI.RESERVED_0;
306
    dummy = PORTI.RESERVED_0;
307
 
308
 
309
    PORTO.LCDCON.BYTE = 0x06 | (rs & 0x01);
310
 
311
    // wait 500ns = 10cyc@20MHz
312
    for (i = 0 ; i <= 10 ; i++) dummy = PORTI.RESERVED_0;
313
 
314
    data = PORTI.LCDIN;
315
 
316
    PORTO.LCDCON.BYTE = 0x02 | (rs & 0x01);
317
 
318
    // wait 500ns = 10cyc@20MHz
319
    for (i = 0 ; i <= 10 ; i++) dummy = PORTI.RESERVED_0;
320
 
321
    return(data);
322
}
323
 
324
//=================================
325
// LCD Write
326
//---------------------------------
327
//     Input  : rs (0=Instr,1=Data)
328
//              wd (Write Data)
329
//     Output : none
330
//=================================
331
void lcd_wr(int rs, unsigned char wd)
332
{
333
    int i;
334
    unsigned char dummy;
335
 
336
    PORTO.LCDOUT = wd;
337
 
338
    PORTO.LCDCON.BYTE = 0x00 | (rs & 0x01);
339
 
340
    // wait 60ns = 2cyc@20MHz
341
    dummy = PORTI.RESERVED_0;
342
    dummy = PORTI.RESERVED_0;
343
 
344
    PORTO.LCDCON.BYTE = 0x04 | (rs & 0x01);
345
 
346
    // wait 500ns = 10cyc@20MHz
347
    for (i = 0 ; i <= 10 ; i++) dummy = PORTI.RESERVED_0;
348
 
349
    PORTO.LCDCON.BYTE = 0x00 | (rs & 0x01);
350
 
351
    // wait 500ns = 10cyc@20MHz
352
    for (i = 0 ; i <= 10 ; i++) dummy = PORTI.RESERVED_0;
353
}
354
 
355
//==================
356
// LCD Initialize
357
//------------------
358
//     Input  : none
359
//     Output : none
360
//==================
361
void lcd_init(void)
362
{
363
    int i;
364
    unsigned char dummy;
365
 
366
    lcd_wr(INST, 0x30);
367
 
368
    // wait 4100us=82000cyc@20MHz
369
    for (i = 0 ; i < 82000 ; i++) dummy = PORTI.RESERVED_0;
370
 
371
    lcd_wr(INST, 0x30);
372
 
373
    // wait 100us=2000cyc@20MHz
374
    for (i = 0 ; i < 2000 ; i++) dummy = PORTI.RESERVED_0;
375
 
376
    lcd_wr(INST, 0x30);
377
 
378
    // set function (8bit, 2lines)
379
    lcd_ready();
380
    lcd_wr(INST, 0x38);
381
 
382
    // display (disp on, cursor off, blink off)
383
    lcd_ready();
384
    lcd_wr(INST, 0x0c);
385
 
386
    // clear
387
    lcd_ready();
388
    lcd_wr(INST, 0x01);
389
 
390
    // entry mode (increment, no-shift)
391
    lcd_ready();
392
    lcd_wr(INST, 0x06);
393
}
394
 
395
//===============
396
// End of Program
397
//===============

powered by: WebSVN 2.1.0

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