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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ARM7_LPC2368_Eclipse/] [RTOSDemo/] [LCD/] [portlcd.c] - Blame information for rev 577

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 577 jeremybenn
/*****************************************************************************
2
 *
3
 * Project          : lwIP Web
4
 * Subproject       :
5
 * Name             : portlcd.c
6
 * Function         : Routines for LCD
7
 * Designer         : K. Sterckx
8
 * Creation date    : 22/01/2007
9
 * Compiler         : GNU ARM
10
 * Processor        : LPC2368
11
 * Last update      :
12
 * Last updated by  :
13
 * History          :
14
 *  based on example code from NXP
15
 *
16
 ************************************************************************
17
 *
18
 *  This code is used to place text on the LCD.
19
 *
20
 ************************************************************************/
21
 
22
#include "portlcd.h"
23
#include "FreeRTOS.h"
24
#include "task.h"
25
 
26
/* Please note, on old MCB2300 board, the LCD_E bit is p1.30, on the new board
27
it's p1.31, please check the schematic carefully, and change LCD_CTRL and LCD_E
28
accordingly if you have a different board. */
29
 
30
/* LCD IO definitions */
31
#define LCD_E     0x80000000            /* Enable control pin                */
32
#define LCD_RW    0x20000000            /* Read/Write control pin            */
33
#define LCD_RS    0x10000000            /* Data/Instruction control          */
34
#define LCD_CTRL  0xB0000000            /* Control lines mask                */
35
#define LCD_DATA  0x0F000000            /* Data lines mask                   */
36
 
37
/* Local variables */
38
static unsigned int lcd_ptr;
39
 
40
/* 8 user defined characters to be loaded into CGRAM (used for bargraph) */
41
static const unsigned char UserFont[8][8] = {
42
        { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
43
        { 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10 },
44
        { 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18 },
45
        { 0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C },
46
        { 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E },
47
        { 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F },
48
        { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
49
        { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }
50
};
51
 
52
/* Local Function Prototypes */
53
static void     lcd_write( unsigned int c );
54
static void     lcd_write_4bit( unsigned int c );
55
static unsigned int lcd_read_stat( void );
56
static void     lcd_write_cmd( unsigned int c );
57
static void     lcd_write_data( unsigned int d );
58
static void     lcd_wait_busy( void );
59
 
60
 
61
/******************************************************************************
62
** Function name:  lcd_write_4bit
63
**
64
** Descriptions:
65
**
66
** parameters:     four bits to write
67
** Returned value: None
68
**
69
******************************************************************************/
70
static void lcd_write_4bit(unsigned int c)
71
{
72
        /* Write a 4-bit command to LCD controller. */
73
        FIO1DIR |= LCD_DATA | LCD_CTRL;
74
        FIO1CLR  = LCD_RW   | LCD_DATA;
75
        FIO1SET  = (c & 0xF) << 24;
76
        FIO1SET  = LCD_E;
77
        vTaskDelay(0);
78
        FIO1CLR  = LCD_E;
79
        vTaskDelay(0);
80
        return;
81
}
82
 
83
/******************************************************************************
84
** Function name: lcd_write
85
**
86
** Descriptions:
87
**
88
** parameters:     word to write
89
** Returned value: None
90
**
91
******************************************************************************/
92
static void lcd_write(unsigned int c)
93
{
94
        /* Write data/command to LCD controller. */
95
        lcd_write_4bit (c >> 4);
96
        lcd_write_4bit (c);
97
        return;
98
}
99
 
100
/******************************************************************************
101
** Function name: lcd_read_stat
102
**
103
** Descriptions:
104
**
105
** parameters:     None
106
** Returned value: status
107
**
108
******************************************************************************/
109
static unsigned int lcd_read_stat(void)
110
{
111
        /* Read status of LCD controller (ST7066) */
112
        unsigned int stat;
113
 
114
        FIO1DIR &= ~LCD_DATA;
115
        FIO1CLR  = LCD_RS;
116
        FIO1SET  = LCD_RW;
117
        vTaskDelay( 0 );
118
        FIO1SET  = LCD_E;
119
        vTaskDelay( 0 );
120
        stat    = (FIO1PIN >> 20) & 0xF0;
121
        FIO1CLR  = LCD_E;
122
        vTaskDelay( 0 );
123
        FIO1SET  = LCD_E;
124
        vTaskDelay( 0 );
125
        stat   |= (FIO1PIN >> 24) & 0xF;
126
        FIO1CLR  = LCD_E;
127
        return (stat);
128
}
129
 
130
/******************************************************************************
131
** Function name: lcd_wait_busy
132
**
133
** Descriptions:
134
**
135
** parameters:     None
136
** Returned value: None
137
**
138
******************************************************************************/
139
static void lcd_wait_busy(void)
140
{
141
        /* Wait until LCD controller (ST7066) is busy. */
142
        unsigned int stat;
143
 
144
        do
145
        {
146
                stat = lcd_read_stat();
147
        }
148
        while (stat & 0x80); /* Wait for busy flag */
149
 
150
        return;
151
}
152
 
153
/******************************************************************************
154
** Function name: lcd_write_cmd
155
**
156
** Descriptions:
157
**
158
** parameters:     command word
159
** Returned value: None
160
**
161
******************************************************************************/
162
static void lcd_write_cmd(unsigned int c)
163
{
164
        /* Write command to LCD controller. */
165
        lcd_wait_busy();
166
        FIO1CLR = LCD_RS;
167
        lcd_write(c);
168
        return;
169
}
170
 
171
/******************************************************************************
172
** Function name: lcd_write_data
173
**
174
** Descriptions:
175
**
176
** parameters:     data word
177
** Returned value: None
178
**
179
******************************************************************************/
180
static void lcd_write_data(unsigned int d)
181
{
182
        /* Write data to LCD controller. */
183
        lcd_wait_busy();
184
        FIO1SET = LCD_RS;
185
        lcd_write(d);
186
        return;
187
}
188
 
189
/******************************************************************************
190
** Function name: LCD_init
191
**
192
** Descriptions:
193
**
194
** parameters:     None
195
** Returned value: None
196
**
197
******************************************************************************/
198
void LCD_init(void)
199
{
200
        /* Initialize the ST7066 LCD controller to 4-bit mode. */
201
        PINSEL3 = 0x00000000;
202
#if USE_FIO
203
        SCS |= 0x00000001;/* set GPIOx to use Fast I/O */
204
#endif
205
        FIO1DIR |= LCD_CTRL | LCD_DATA;
206
        FIO1CLR  = LCD_RW   | LCD_RS   | LCD_DATA;
207
 
208
        lcd_write_4bit(0x3);                /* Select 4-bit interface            */
209
        vTaskDelay(100);
210
        lcd_write_4bit(0x3);
211
        vTaskDelay(100);
212
        lcd_write_4bit(0x3);
213
        lcd_write_4bit(0x2);
214
 
215
        lcd_write_cmd(0x28);                /* 2 lines, 5x8 character matrix     */
216
        lcd_write_cmd(0x0e);                /* Display ctrl:Disp/Curs/Blnk=ON    */
217
        lcd_write_cmd(0x06);                /* Entry mode: Move right, no shift  */
218
 
219
        LCD_load( (unsigned char *)&UserFont, sizeof (UserFont) );
220
        LCD_cls();
221
        return;
222
}
223
 
224
/******************************************************************************
225
** Function name: LCD_load
226
**
227
** Descriptions:
228
**
229
** parameters:     pointer to the buffer and counter
230
** Returned value: None
231
**
232
******************************************************************************/
233
void LCD_load(unsigned char *fp, unsigned int cnt)
234
{
235
        /* Load user-specific characters into CGRAM */
236
        unsigned int i;
237
 
238
        lcd_write_cmd( 0x40 );                /* Set CGRAM address counter to 0    */
239
        for (i = 0; i < cnt; i++, fp++)
240
        {
241
                lcd_write_data( *fp );
242
        }
243
        return;
244
}
245
 
246
/******************************************************************************
247
** Function name: LCD_gotoxy
248
**
249
** Descriptions:
250
**
251
** parameters:     pixel X and Y
252
** Returned value: None
253
**
254
******************************************************************************/
255
void LCD_gotoxy(unsigned int x, unsigned int y)
256
{
257
        /* Set cursor position on LCD display. Left corner: 1,1, right: 16,2 */
258
        unsigned int c;
259
 
260
        c = --x;
261
        if (--y)
262
        {
263
                c |= 0x40;
264
        }
265
        lcd_write_cmd (c | 0x80);
266
        lcd_ptr = y*16 + x;
267
        return;
268
}
269
 
270
/******************************************************************************
271
** Function name: LCD_cls
272
**
273
** Descriptions:
274
**
275
** parameters:     None
276
** Returned value: None
277
**
278
******************************************************************************/
279
void LCD_cls(void)
280
{
281
        /* Clear LCD display, move cursor to home position. */
282
        lcd_write_cmd (0x01);
283
        LCD_gotoxy (1,1);
284
        return;
285
}
286
 
287
/******************************************************************************
288
** Function name: LCD_cur_off
289
**
290
** Descriptions:
291
**
292
** parameters:     None
293
** Returned value: None
294
**
295
******************************************************************************/
296
void LCD_cur_off(void)
297
{
298
        /* Switch off LCD cursor. */
299
        lcd_write_cmd(0x0c);
300
        return;
301
}
302
 
303
 
304
/******************************************************************************
305
** Function name: LCD_on
306
**
307
** Descriptions:
308
**
309
** parameters:     None
310
** Returned value: None
311
**
312
******************************************************************************/
313
void LCD_on(void)
314
{
315
        /* Switch on LCD and enable cursor. */
316
        lcd_write_cmd (0x0e);
317
        return;
318
}
319
 
320
/******************************************************************************
321
** Function name: LCD_putc
322
**
323
** Descriptions:
324
**
325
** parameters:     unsigned char character
326
** Returned value: None
327
**
328
******************************************************************************/
329
void LCD_putc(unsigned char c)
330
{
331
        /* Print a character to LCD at current cursor position. */
332
        if (lcd_ptr == 16)
333
        {
334
                lcd_write_cmd (0xc0);
335
        }
336
        lcd_write_data(c);
337
        lcd_ptr++;
338
        return;
339
}
340
 
341
/******************************************************************************
342
** Function name: LCD_puts
343
**
344
** Descriptions:
345
**
346
** parameters:     pointer to the buffer
347
** Returned value: None
348
**
349
******************************************************************************/
350
void LCD_puts(char *sp)
351
{
352
        /* Print a string to LCD display. */
353
        while (*sp)
354
        {
355
                LCD_putc (*sp++);
356
        }
357
        return;
358
}
359
 
360
/******************************************************************************
361
** Function name: LCD_bargraph
362
**
363
** Descriptions:
364
**
365
** parameters:     value and size
366
** Returned value: None
367
**
368
******************************************************************************/
369
void LCD_bargraph(unsigned int val, unsigned int size)
370
{
371
        /* Print a bargraph to LCD display.  */
372
        /* - val:  value 0..100 %            */
373
        /* - size: size of bargraph 1..16    */
374
        unsigned int i;
375
 
376
        val = val * size / 20;               /* Display matrix 5 x 8 pixels       */
377
        for (i = 0; i < size; i++)
378
        {
379
                if (val > 5)
380
                {
381
                        LCD_putc(5);
382
                        val -= 5;
383
                }
384
                else
385
                {
386
                        LCD_putc(val);
387
                        break;
388
                }
389
        }
390
        return;
391
}

powered by: WebSVN 2.1.0

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