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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 587 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
/* Scheduler includes. */
55
#include "FreeRTOS.h"
56
#include "task.h"
57
#include "queue.h"
58
 
59
/* Demo includes. */
60
#include "lcd.h"
61
 
62
/*
63
 * The LCD is written to by more than one task so is controlled by this
64
 * 'gatekeeper' task.  This is the only task that is actually permitted to
65
 * access the LCD directly.  Other tasks wanting to display a message send
66
 * the message to the gatekeeper.
67
 */
68
static void vLCDTask( void *pvParameters );
69
 
70
/*
71
 * Setup the peripherals required to communicate with the LCD.
72
 */
73
static void prvSetupLCD( void );
74
 
75
/*
76
 * Move to the first (0) or second (1) row of the LCD.
77
 */
78
static void prvLCDGotoRow( unsigned portSHORT usRow );
79
 
80
/*
81
 * Write a string of text to the LCD.
82
 */
83
static void prvLCDPutString( portCHAR *pcString );
84
 
85
/*
86
 * Clear the LCD.
87
 */
88
static void prvLCDClear( void );
89
 
90
/*-----------------------------------------------------------*/
91
 
92
/* Brief delay to permit the LCD to catch up with commands. */
93
#define lcdSHORT_DELAY          3
94
 
95
/* SFR that seems to be missing from the standard header files. */
96
#define PMAEN                           *( ( unsigned short * ) 0x60c )
97
 
98
/* LCD commands. */
99
#define lcdDEFAULT_FUNCTION     0x3c
100
#define lcdDISPLAY_CONTROL      0x0c
101
#define lcdCLEAR_DISPLAY        0x01
102
#define lcdENTRY_MODE           0x06
103
 
104
/* The length of the queue used to send messages to the LCD gatekeeper task. */
105
#define lcdQUEUE_SIZE           3
106
/*-----------------------------------------------------------*/
107
 
108
/* The queue used to send messages to the LCD task. */
109
xQueueHandle xLCDQueue;
110
 
111
 
112
/*-----------------------------------------------------------*/
113
 
114
xQueueHandle xStartLCDTask( void )
115
{
116
        /* Create the queue used by the LCD task.  Messages for display on the LCD
117
        are received via this queue. */
118
        xLCDQueue = xQueueCreate( lcdQUEUE_SIZE, sizeof( xLCDMessage ) );
119
 
120
        /* Start the task that will write to the LCD.  The LCD hardware is
121
        initialised from within the task itself so delays can be used. */
122
        xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
123
 
124
        return xLCDQueue;
125
}
126
/*-----------------------------------------------------------*/
127
 
128
static void prvLCDGotoRow( unsigned portSHORT usRow )
129
{
130
        if( usRow == 0 )
131
        {
132
                PMADDR = 0x0000;
133
                PMDIN1 = 0x02;
134
        }
135
        else
136
        {
137
                PMADDR = 0x0000;
138
                PMDIN1 = 0xc0;
139
        }
140
 
141
        vTaskDelay( lcdSHORT_DELAY );
142
}
143
/*-----------------------------------------------------------*/
144
 
145
static void prvLCDPutString( portCHAR *pcString )
146
{
147
        /* Write out each character with appropriate delay between each. */
148
        while( *pcString )
149
        {
150
                PMADDR = 0x0001;
151
                PMDIN1 = *pcString;
152
                pcString++;
153
                vTaskDelay( lcdSHORT_DELAY );
154
        }
155
}
156
/*-----------------------------------------------------------*/
157
 
158
static void prvLCDClear( void )
159
{
160
        /* Clear the display. */
161
        PMADDR = 0x0000;
162
        PMDIN1 = lcdCLEAR_DISPLAY;
163
        vTaskDelay( lcdSHORT_DELAY );
164
}
165
/*-----------------------------------------------------------*/
166
 
167
static void prvSetupLCD( void )
168
{
169
        /* Setup the PMP. */
170
        PMCON = 0x83BF;
171
        PMMODE = 0x3FF;
172
        PMAEN = 1;
173
        PMADDR = 0x0000;
174
        vTaskDelay( lcdSHORT_DELAY );
175
 
176
        /* Set the default function. */
177
        PMDIN1 = lcdDEFAULT_FUNCTION;
178
        vTaskDelay( lcdSHORT_DELAY );
179
 
180
        /* Set the display control. */
181
        PMDIN1 = lcdDISPLAY_CONTROL;
182
        vTaskDelay( lcdSHORT_DELAY );
183
 
184
        /* Clear the display. */
185
        PMDIN1 = lcdCLEAR_DISPLAY;
186
        vTaskDelay( lcdSHORT_DELAY );
187
 
188
        /* Set the entry mode. */
189
        PMDIN1 = lcdENTRY_MODE;
190
        vTaskDelay( lcdSHORT_DELAY );
191
}
192
/*-----------------------------------------------------------*/
193
 
194
static void vLCDTask( void *pvParameters )
195
{
196
xLCDMessage xMessage;
197
unsigned portSHORT usRow = 0;
198
 
199
        /* Initialise the hardware.  This uses delays so must not be called prior
200
        to the scheduler being started. */
201
        prvSetupLCD();
202
 
203
        /* Welcome message. */
204
        prvLCDPutString( "www.FreeRTOS.org" );
205
 
206
        for( ;; )
207
        {
208
                /* Wait for a message to arrive that requires displaying. */
209
                while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
210
 
211
                /* Clear the current display value. */
212
                prvLCDClear();
213
 
214
                /* Switch rows each time so we can see that the display is still being
215
                updated. */
216
                prvLCDGotoRow( usRow & 0x01 );
217
                usRow++;
218
                prvLCDPutString( xMessage.pcMessage );
219
 
220
                /* Delay the requested amount of time to ensure the text just written
221
                to the LCD is not overwritten. */
222
                vTaskDelay( xMessage.xMinDisplayTime );
223
        }
224
}
225
 
226
 
227
 
228
 

powered by: WebSVN 2.1.0

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