]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PIC24_MPLAB/lcd.c
Update version number to V8.0.0 (without the release candidate number).
[freertos] / FreeRTOS / Demo / PIC24_MPLAB / lcd.c
1 /*\r
2     FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd. \r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
28     >>! a combined work that includes FreeRTOS without being obliged to provide\r
29     >>! the source code for proprietary components outside of the FreeRTOS\r
30     >>! kernel.\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /* Scheduler includes. */\r
67 #include "FreeRTOS.h"\r
68 #include "task.h"\r
69 #include "queue.h"\r
70 \r
71 /* Demo includes. */\r
72 #include "lcd.h"\r
73 \r
74 /*\r
75  * The LCD is written to by more than one task so is controlled by this\r
76  * 'gatekeeper' task.  This is the only task that is actually permitted to\r
77  * access the LCD directly.  Other tasks wanting to display a message send\r
78  * the message to the gatekeeper.\r
79  */\r
80 static void vLCDTask( void *pvParameters );\r
81 \r
82 /*\r
83  * Setup the peripherals required to communicate with the LCD.\r
84  */\r
85 static void prvSetupLCD( void );\r
86 \r
87 /* \r
88  * Move to the first (0) or second (1) row of the LCD. \r
89  */\r
90 static void prvLCDGotoRow( unsigned short usRow );\r
91 \r
92 /* \r
93  * Write a string of text to the LCD. \r
94  */\r
95 static void prvLCDPutString( char *pcString );\r
96 \r
97 /* \r
98  * Clear the LCD. \r
99  */\r
100 static void prvLCDClear( void );\r
101 \r
102 /*-----------------------------------------------------------*/\r
103 \r
104 /* Brief delay to permit the LCD to catch up with commands. */\r
105 #define lcdSHORT_DELAY          3\r
106 \r
107 /* SFR that seems to be missing from the standard header files. */\r
108 #define PMAEN                           *( ( unsigned short * ) 0x60c )\r
109 \r
110 /* LCD commands. */\r
111 #define lcdDEFAULT_FUNCTION     0x3c\r
112 #define lcdDISPLAY_CONTROL      0x0c\r
113 #define lcdCLEAR_DISPLAY        0x01\r
114 #define lcdENTRY_MODE           0x06\r
115 \r
116 /* The length of the queue used to send messages to the LCD gatekeeper task. */\r
117 #define lcdQUEUE_SIZE           3\r
118 /*-----------------------------------------------------------*/\r
119 \r
120 /* The queue used to send messages to the LCD task. */\r
121 QueueHandle_t xLCDQueue;\r
122 \r
123 \r
124 /*-----------------------------------------------------------*/\r
125 \r
126 QueueHandle_t xStartLCDTask( void )\r
127 {\r
128         /* Create the queue used by the LCD task.  Messages for display on the LCD\r
129         are received via this queue. */\r
130         xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ) );\r
131 \r
132         /* Start the task that will write to the LCD.  The LCD hardware is\r
133         initialised from within the task itself so delays can be used. */\r
134         xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );\r
135 \r
136         return xLCDQueue;\r
137 }\r
138 /*-----------------------------------------------------------*/\r
139 \r
140 static void prvLCDGotoRow( unsigned short usRow )\r
141 {\r
142         if( usRow == 0 )\r
143         {\r
144                 PMADDR = 0x0000;\r
145                 PMDIN1 = 0x02;\r
146         }\r
147         else\r
148         {\r
149                 PMADDR = 0x0000;\r
150                 PMDIN1 = 0xc0;\r
151         }\r
152 \r
153         vTaskDelay( lcdSHORT_DELAY );\r
154 }\r
155 /*-----------------------------------------------------------*/\r
156 \r
157 static void prvLCDPutString( char *pcString )\r
158 {\r
159         /* Write out each character with appropriate delay between each. */\r
160         while( *pcString )\r
161         {\r
162                 PMADDR = 0x0001;\r
163                 PMDIN1 = *pcString;\r
164                 pcString++;\r
165                 vTaskDelay( lcdSHORT_DELAY );\r
166         }\r
167 }\r
168 /*-----------------------------------------------------------*/\r
169 \r
170 static void prvLCDClear( void )\r
171 {\r
172         /* Clear the display. */\r
173         PMADDR = 0x0000;\r
174         PMDIN1 = lcdCLEAR_DISPLAY;\r
175         vTaskDelay( lcdSHORT_DELAY );   \r
176 }\r
177 /*-----------------------------------------------------------*/\r
178 \r
179 static void prvSetupLCD( void )\r
180 {\r
181         /* Setup the PMP. */\r
182         PMCON = 0x83BF;\r
183         PMMODE = 0x3FF;\r
184         PMAEN = 1;\r
185         PMADDR = 0x0000;\r
186         vTaskDelay( lcdSHORT_DELAY );\r
187 \r
188         /* Set the default function. */\r
189         PMDIN1 = lcdDEFAULT_FUNCTION;\r
190         vTaskDelay( lcdSHORT_DELAY );\r
191 \r
192         /* Set the display control. */\r
193         PMDIN1 = lcdDISPLAY_CONTROL;\r
194         vTaskDelay( lcdSHORT_DELAY );\r
195 \r
196         /* Clear the display. */\r
197         PMDIN1 = lcdCLEAR_DISPLAY;\r
198         vTaskDelay( lcdSHORT_DELAY );\r
199 \r
200         /* Set the entry mode. */\r
201         PMDIN1 = lcdENTRY_MODE;\r
202         vTaskDelay( lcdSHORT_DELAY );\r
203 }\r
204 /*-----------------------------------------------------------*/\r
205 \r
206 static void vLCDTask( void *pvParameters )\r
207 {\r
208 xLCDMessage xMessage;\r
209 unsigned short usRow = 0;\r
210 \r
211         /* Remove compiler warnigns. */\r
212         ( void ) pvParameters;\r
213 \r
214         /* Initialise the hardware.  This uses delays so must not be called prior\r
215         to the scheduler being started. */\r
216         prvSetupLCD();\r
217 \r
218         /* Welcome message. */\r
219         prvLCDPutString( "www.FreeRTOS.org" );\r
220 \r
221         for( ;; )\r
222         {\r
223                 /* Wait for a message to arrive that requires displaying. */\r
224                 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );\r
225 \r
226                 /* Clear the current display value. */\r
227                 prvLCDClear();\r
228 \r
229                 /* Switch rows each time so we can see that the display is still being\r
230                 updated. */\r
231                 prvLCDGotoRow( usRow & 0x01 );\r
232                 usRow++;\r
233                 prvLCDPutString( xMessage.pcMessage );\r
234 \r
235                 /* Delay the requested amount of time to ensure the text just written \r
236                 to the LCD is not overwritten. */\r
237                 vTaskDelay( xMessage.xMinDisplayTime );         \r
238         }\r
239 }\r
240 \r
241 \r
242 \r
243 \r