2 FreeRTOS.org V4.6.1 - Copyright (C) 2003-2007 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
31 Also see http://www.SafeRTOS.com a version that has been certified for use
\r
32 in safety critical systems, plus commercial licensing, development and
\r
34 ***************************************************************************
\r
37 /* Scheduler includes. */
\r
38 #include "FreeRTOS.h"
\r
42 /* Demo includes. */
\r
46 * The LCD is written to by more than one task so is controlled by this
\r
47 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
48 * access the LCD directly. Other tasks wanting to display a message send
\r
49 * the message to the gatekeeper.
\r
51 static void vLCDTask( void *pvParameters );
\r
54 * Setup the peripherals required to communicate with the LCD.
\r
56 static void prvSetupLCD( void );
\r
59 * Move to the first (0) or second (1) row of the LCD.
\r
61 static void prvLCDGotoRow( unsigned portSHORT usRow );
\r
64 * Write a string of text to the LCD.
\r
66 static void prvLCDPutString( portCHAR *pcString );
\r
71 static void prvLCDClear( void );
\r
73 /*-----------------------------------------------------------*/
\r
75 /* Brief delay to permit the LCD to catch up with commands. */
\r
76 #define lcdSHORT_DELAY 3
\r
78 /* SFR that seems to be missing from the standard header files. */
\r
79 #define PMAEN *( ( unsigned short * ) 0x60c )
\r
82 #define lcdDEFAULT_FUNCTION 0x3c
\r
83 #define lcdDISPLAY_CONTROL 0x0c
\r
84 #define lcdCLEAR_DISPLAY 0x01
\r
85 #define lcdENTRY_MODE 0x06
\r
87 /* The length of the queue used to send messages to the LCD gatekeeper task. */
\r
88 #define lcdQUEUE_SIZE 3
\r
89 /*-----------------------------------------------------------*/
\r
91 /* The queue used to send messages to the LCD task. */
\r
92 xQueueHandle xLCDQueue;
\r
95 /*-----------------------------------------------------------*/
\r
97 xQueueHandle xStartLCDTask( void )
\r
99 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
100 are received via this queue. */
\r
101 xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ) );
\r
103 /* Start the task that will write to the LCD. The LCD hardware is
\r
104 initialised from within the task itself so delays can be used. */
\r
105 xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
\r
109 /*-----------------------------------------------------------*/
\r
111 static void prvLCDGotoRow( unsigned portSHORT usRow )
\r
124 vTaskDelay( lcdSHORT_DELAY );
\r
126 /*-----------------------------------------------------------*/
\r
128 static void prvLCDPutString( portCHAR *pcString )
\r
130 /* Write out each character with appropriate delay between each. */
\r
134 PMDIN1 = *pcString;
\r
136 vTaskDelay( lcdSHORT_DELAY );
\r
139 /*-----------------------------------------------------------*/
\r
141 static void prvLCDClear( void )
\r
143 /* Clear the display. */
\r
145 PMDIN1 = lcdCLEAR_DISPLAY;
\r
146 vTaskDelay( lcdSHORT_DELAY );
\r
148 /*-----------------------------------------------------------*/
\r
150 static void prvSetupLCD( void )
\r
152 /* Setup the PMP. */
\r
157 vTaskDelay( lcdSHORT_DELAY );
\r
159 /* Set the default function. */
\r
160 PMDIN1 = lcdDEFAULT_FUNCTION;
\r
161 vTaskDelay( lcdSHORT_DELAY );
\r
163 /* Set the display control. */
\r
164 PMDIN1 = lcdDISPLAY_CONTROL;
\r
165 vTaskDelay( lcdSHORT_DELAY );
\r
167 /* Clear the display. */
\r
168 PMDIN1 = lcdCLEAR_DISPLAY;
\r
169 vTaskDelay( lcdSHORT_DELAY );
\r
171 /* Set the entry mode. */
\r
172 PMDIN1 = lcdENTRY_MODE;
\r
173 vTaskDelay( lcdSHORT_DELAY );
\r
175 /*-----------------------------------------------------------*/
\r
177 static void vLCDTask( void *pvParameters )
\r
179 xLCDMessage xMessage;
\r
180 unsigned portSHORT usRow = 0;
\r
182 /* Initialise the hardware. This uses delays so must not be called prior
\r
183 to the scheduler being started. */
\r
186 /* Welcome message. */
\r
187 prvLCDPutString( "www.FreeRTOS.org" );
\r
191 /* Wait for a message to arrive that requires displaying. */
\r
192 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
194 /* Clear the current display value. */
\r
197 /* Switch rows each time so we can see that the display is still being
\r
199 prvLCDGotoRow( usRow & 0x01 );
\r
201 prvLCDPutString( xMessage.pcMessage );
\r
203 /* Delay the requested amount of time to ensure the text just written
\r
204 to the LCD is not overwritten. */
\r
205 vTaskDelay( xMessage.xMinDisplayTime );
\r