OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ARM7_LPC2368_Rowley/] [LCD/] [portlcd.c] - Blame information for rev 585

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

powered by: WebSVN 2.1.0

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