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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [PIC32MX_MPLAB/] [lcd.c] - Blame information for rev 797

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 614 jeremybenn
/*
2
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
3
 
4
    ***************************************************************************
5
    *                                                                         *
6
    * If you are:                                                             *
7
    *                                                                         *
8
    *    + New to FreeRTOS,                                                   *
9
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
10
    *    + Looking for basic training,                                        *
11
    *    + Wanting to improve your FreeRTOS skills and productivity           *
12
    *                                                                         *
13
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
14
    *                                                                         *
15
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
16
    *                  http://www.FreeRTOS.org/Documentation                  *
17
    *                                                                         *
18
    * A pdf reference manual is also available.  Both are usually delivered   *
19
    * to your inbox within 20 minutes to two hours when purchased between 8am *
20
    * and 8pm GMT (although please allow up to 24 hours in case of            *
21
    * exceptional circumstances).  Thank you for your support!                *
22
    *                                                                         *
23
    ***************************************************************************
24
 
25
    This file is part of the FreeRTOS distribution.
26
 
27
    FreeRTOS is free software; you can redistribute it and/or modify it under
28
    the terms of the GNU General Public License (version 2) as published by the
29
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30
    ***NOTE*** The exception to the GPL is included to allow you to distribute
31
    a combined work that includes FreeRTOS without being obliged to provide the
32
    source code for proprietary components outside of the FreeRTOS kernel.
33
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
34
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
36
    more details. You should have received a copy of the GNU General Public
37
    License and the FreeRTOS license exception along with FreeRTOS; if not it
38
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
39
    by writing to Richard Barry, contact details for whom are available on the
40
    FreeRTOS WEB site.
41
 
42
    1 tab == 4 spaces!
43
 
44
    http://www.FreeRTOS.org - Documentation, latest information, license and
45
    contact details.
46
 
47
    http://www.SafeRTOS.com - A version that is certified for use in safety
48
    critical systems.
49
 
50
    http://www.OpenRTOS.com - Commercial support, development, porting,
51
    licensing and training services.
52
*/
53
 
54
/* peripheral library include */
55
#include <plib.h>
56
 
57
/* Scheduler includes. */
58
#include "FreeRTOS.h"
59
#include "task.h"
60
#include "queue.h"
61
 
62
/* Demo includes. */
63
#include "lcd.h"
64
 
65
/*
66
 * The LCD is written to by more than one task so is controlled by this
67
 * 'gatekeeper' task.  This is the only task that is actually permitted to
68
 * access the LCD directly.  Other tasks wanting to display a message send
69
 * the message to the gatekeeper.
70
 */
71
static void vLCDTask( void *pvParameters );
72
 
73
/*
74
 * Setup the peripherals required to communicate with the LCD.
75
 */
76
static void prvSetupLCD( void );
77
 
78
/*
79
 * Move to the first (0) or second (1) row of the LCD.
80
 */
81
static void prvLCDGotoRow( unsigned portSHORT usRow );
82
 
83
/*
84
 * Write a string of text to the LCD.
85
 */
86
static void prvLCDPutString( portCHAR *pcString );
87
 
88
/*
89
 * Clear the LCD.
90
 */
91
static void prvLCDClear( void );
92
 
93
/*-----------------------------------------------------------*/
94
 
95
/* Brief delay to permit the LCD to catch up with commands. */
96
#define lcdVERY_SHORT_DELAY     ( 1 )
97
#define lcdSHORT_DELAY          ( 4 / portTICK_RATE_MS )
98
#define lcdLONG_DELAY           ( 15 / portTICK_RATE_MS )
99
 
100
/* LCD specific definitions. */
101
#define LCD_CLEAR_DISPLAY_CMD                   0x01
102
#define LCD_CURSOR_HOME_CMD                             0x02
103
#define LCD_ENTRY_MODE_CMD                              0x04
104
#define LCD_ENTRY_MODE_INCREASE                 0x02
105
#define LCD_DISPLAY_CTRL_CMD                    0x08
106
#define LCD_DISPLAY_CTRL_DISPLAY_ON             0x04
107
#define LCD_FUNCTION_SET_CMD                    0x20
108
#define LCD_FUNCTION_SET_8_BITS                 0x10
109
#define LCD_FUNCTION_SET_2_LINES                0x08
110
#define LCD_FUNCTION_SET_LRG_FONT               0x04
111
#define LCD_NEW_LINE                                    0xC0
112
#define LCD_COMMAND_ADDRESS                             0x00
113
#define LCD_DATA_ADDRESS                                0x01
114
 
115
/* The length of the queue used to send messages to the LCD gatekeeper task. */
116
#define lcdQUEUE_SIZE           3
117
 
118
/*-----------------------------------------------------------*/
119
 
120
/* The queue used to send messages to the LCD task. */
121
xQueueHandle xLCDQueue;
122
 
123
/* LCD access functions. */
124
static void prvLCDCommand( portCHAR cCommand );
125
static void prvLCDData( portCHAR cChar );
126
 
127
/*-----------------------------------------------------------*/
128
 
129
xQueueHandle xStartLCDTask( void )
130
{
131
        /* Create the queue used by the LCD task.  Messages for display on the LCD
132
        are received via this queue. */
133
        xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ));
134
 
135
        /* Start the task that will write to the LCD.  The LCD hardware is
136
        initialised from within the task itself so delays can be used. */
137
        xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
138
 
139
        return xLCDQueue;
140
}
141
/*-----------------------------------------------------------*/
142
 
143
static void prvLCDGotoRow( unsigned portSHORT usRow )
144
{
145
        if(usRow == 0)
146
        {
147
                prvLCDCommand( LCD_CURSOR_HOME_CMD );
148
        }
149
        else
150
        {
151
                prvLCDCommand( LCD_NEW_LINE );
152
        }
153
}
154
/*-----------------------------------------------------------*/
155
 
156
static void prvLCDCommand( portCHAR cCommand )
157
{
158
        PMPSetAddress( LCD_COMMAND_ADDRESS );
159
        PMPMasterWrite( cCommand );
160
        vTaskDelay( lcdSHORT_DELAY );
161
}
162
/*-----------------------------------------------------------*/
163
 
164
static void prvLCDData( portCHAR cChar )
165
{
166
        PMPSetAddress( LCD_DATA_ADDRESS );
167
        PMPMasterWrite( cChar );
168
        vTaskDelay( lcdVERY_SHORT_DELAY );
169
}
170
/*-----------------------------------------------------------*/
171
 
172
static void prvLCDPutString( portCHAR *pcString )
173
{
174
        /* Write out each character with appropriate delay between each. */
175
        while(*pcString)
176
        {
177
                prvLCDData(*pcString);
178
                pcString++;
179
                vTaskDelay(lcdSHORT_DELAY);
180
        }
181
}
182
/*-----------------------------------------------------------*/
183
 
184
static void prvLCDClear(void)
185
{
186
        prvLCDCommand(LCD_CLEAR_DISPLAY_CMD);
187
}
188
/*-----------------------------------------------------------*/
189
 
190
static void prvSetupLCD(void)
191
{
192
        /* Wait for proper power up. */
193
        vTaskDelay( lcdLONG_DELAY );
194
 
195
        /* Open the PMP port */
196
        mPMPOpen((PMP_ON | PMP_READ_WRITE_EN | PMP_CS2_CS1_EN |
197
                          PMP_LATCH_POL_HI | PMP_CS2_POL_HI | PMP_CS1_POL_HI |
198
                          PMP_WRITE_POL_HI | PMP_READ_POL_HI),
199
                         (PMP_MODE_MASTER1 | PMP_WAIT_BEG_4 | PMP_WAIT_MID_15 |
200
                          PMP_WAIT_END_4),
201
                          PMP_PEN_0, 0);
202
 
203
        /* Wait for the LCD to power up correctly. */
204
        vTaskDelay( lcdLONG_DELAY );
205
        vTaskDelay( lcdLONG_DELAY );
206
        vTaskDelay( lcdLONG_DELAY );
207
 
208
        /* Set up the LCD function. */
209
        prvLCDCommand( LCD_FUNCTION_SET_CMD | LCD_FUNCTION_SET_8_BITS | LCD_FUNCTION_SET_2_LINES | LCD_FUNCTION_SET_LRG_FONT );
210
 
211
        /* Turn the display on. */
212
        prvLCDCommand( LCD_DISPLAY_CTRL_CMD | LCD_DISPLAY_CTRL_DISPLAY_ON );
213
 
214
        /* Clear the display. */
215
        prvLCDCommand( LCD_CLEAR_DISPLAY_CMD );
216
        vTaskDelay( lcdLONG_DELAY );
217
 
218
        /* Increase the cursor. */
219
        prvLCDCommand( LCD_ENTRY_MODE_CMD | LCD_ENTRY_MODE_INCREASE );
220
        vTaskDelay( lcdLONG_DELAY );
221
        vTaskDelay( lcdLONG_DELAY );
222
        vTaskDelay( lcdLONG_DELAY );
223
}
224
/*-----------------------------------------------------------*/
225
 
226
static void vLCDTask(void *pvParameters)
227
{
228
xLCDMessage xMessage;
229
unsigned portSHORT usRow = 0;
230
 
231
        /* Initialise the hardware.  This uses delays so must not be called prior
232
        to the scheduler being started. */
233
        prvSetupLCD();
234
 
235
        /* Welcome message. */
236
        prvLCDPutString( "www.FreeRTOS.org" );
237
 
238
        for(;;)
239
        {
240
                /* Wait for a message to arrive that requires displaying. */
241
                while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
242
 
243
                /* Clear the current display value. */
244
                prvLCDClear();
245
 
246
                /* Switch rows each time so we can see that the display is still being
247
                updated. */
248
                prvLCDGotoRow( usRow & 0x01 );
249
                usRow++;
250
                prvLCDPutString( xMessage.pcMessage );
251
 
252
                /* Delay the requested amount of time to ensure the text just written
253
                to the LCD is not overwritten. */
254
                vTaskDelay( xMessage.xMinDisplayTime );
255
        }
256
}
257
 
258
 
259
 
260
 

powered by: WebSVN 2.1.0

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