?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik /*********************************************************************
2 *
3 * LCD Access Routines
4 *
5 *********************************************************************
6 * FileName: LCDBlocking.c
7 * Dependencies: None
8 * Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F, PIC32
9 * Compiler: Microchip C32 v1.05 or higher
10 * Microchip C30 v3.12 or higher
11 * Microchip C18 v3.30 or higher
12 * HI-TECH PICC-18 PRO 9.63PL2 or higher
13 * Company: Microchip Technology, Inc.
14 *
15 * Software License Agreement
16 *
17 * Copyright (C) 2002-2009 Microchip Technology Inc. All rights
18 * reserved.
19 *
20 * Microchip licenses to you the right to use, modify, copy, and
21 * distribute:
22 * (i) the Software when embedded on a Microchip microcontroller or
23 * digital signal controller product ("Device") which is
24 * integrated into Licensee's product; or
25 * (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h,
26 * ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device
27 * used in conjunction with a Microchip ethernet controller for
28 * the sole purpose of interfacing with the ethernet controller.
29 *
30 * You should refer to the license agreement accompanying this
31 * Software for additional information regarding your rights and
32 * obligations.
33 *
34 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
35 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
36 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
37 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
38 * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
39 * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
40 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
41 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
42 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
43 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
44 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
45 *
46 *
47 * Author Date Comment
48 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49 * Howard Schlunder 4/03/06 Original
50 * Howard Schlunder 4/12/06 Changed from using PMP to LCDWrite()
51 * Howard Schlunder 8/10/06 Fixed a delay being too short
52 * when CLOCK_FREQ was a smaller
53 * value, added FOUR_BIT_MODE
54 ********************************************************************/
55 #define __LCDBLOCKING_C
56  
57 #include "TCPIP Stack/TCPIP.h"
58  
59 #if defined(USE_LCD)
60  
61  
62 //#define FOUR_BIT_MODE
63 #define SAMSUNG_S6A0032 // This LCD driver chip has a different means of entering 4-bit mode.
64  
65 // LCDText is a 32 byte shadow of the LCD text. Write to it and
66 // then call LCDUpdate() to copy the string into the LCD module.
67 BYTE LCDText[16*2+1];
68  
69 /******************************************************************************
70 * Function: static void LCDWrite(BYTE RS, BYTE Data)
71 *
72 * PreCondition: None
73 *
74 * Input: RS - Register Select - 1:RAM, 0:Config registers
75 * Data - 8 bits of data to write
76 *
77 * Output: None
78 *
79 * Side Effects: None
80 *
81 * Overview: Controls the Port I/O pins to cause an LCD write
82 *
83 * Note: None
84 *****************************************************************************/
85 static void LCDWrite(BYTE RS, BYTE Data)
86 {
87 #if defined(LCD_DATA_TRIS)
88 LCD_DATA_TRIS = 0x00;
89 #else
90 LCD_DATA0_TRIS = 0;
91 LCD_DATA1_TRIS = 0;
92 LCD_DATA2_TRIS = 0;
93 LCD_DATA3_TRIS = 0;
94 #if !defined(FOUR_BIT_MODE)
95 LCD_DATA4_TRIS = 0;
96 LCD_DATA5_TRIS = 0;
97 LCD_DATA6_TRIS = 0;
98 LCD_DATA7_TRIS = 0;
99 #endif
100 #endif
101 LCD_RS_TRIS = 0;
102 LCD_RD_WR_TRIS = 0;
103 LCD_RD_WR_IO = 0;
104 LCD_RS_IO = RS;
105  
106 #if defined(FOUR_BIT_MODE)
107 #if defined(LCD_DATA_IO)
108 LCD_DATA_IO = Data>>4;
109 #else
110 LCD_DATA0_IO = ((Data & 0x10) == 0x10);
111 LCD_DATA1_IO = ((Data & 0x20) == 0x20);
112 LCD_DATA2_IO = ((Data & 0x40) == 0x40);
113 LCD_DATA3_IO = ((Data & 0x80) == 0x80);
114 #endif
115 Nop(); // Wait Data setup time (min 40ns)
116 Nop();
117 LCD_E_IO = 1;
118 Nop(); // Wait E Pulse width time (min 230ns)
119 Nop();
120 Nop();
121 Nop();
122 Nop();
123 Nop();
124 Nop();
125 Nop();
126 Nop();
127 LCD_E_IO = 0;
128 #endif
129  
130 #if defined(LCD_DATA_IO)
131 LCD_DATA_IO = Data;
132 #else
133 LCD_DATA0_IO = ((Data & 0x01) == 0x01);
134 LCD_DATA1_IO = ((Data & 0x02) == 0x02);
135 LCD_DATA2_IO = ((Data & 0x04) == 0x04);
136 LCD_DATA3_IO = ((Data & 0x08) == 0x08);
137 #if !defined(FOUR_BIT_MODE)
138 LCD_DATA4_IO = ((Data & 0x10) == 0x10);
139 LCD_DATA5_IO = ((Data & 0x20) == 0x20);
140 LCD_DATA6_IO = ((Data & 0x40) == 0x40);
141 LCD_DATA7_IO = ((Data & 0x80) == 0x80);
142 #endif
143 #endif
144 Nop(); // Wait Data setup time (min 40ns)
145 Nop();
146 LCD_E_IO = 1;
147 Nop(); // Wait E Pulse width time (min 230ns)
148 Nop();
149 Nop();
150 Nop();
151 Nop();
152 Nop();
153 Nop();
154 Nop();
155 Nop();
156 LCD_E_IO = 0;
157  
158 // // Uncomment if you want the data bus to go High-Z when idle
159 // // Note that this may make analog functions work poorly when using
160 // // Explorer 16 revision 5 boards with a 5V LCD on it. The 5V LCDs have
161 // // internal weak pull ups to 5V on each of the I/O pins, which will
162 // // backfeed 5V weekly onto non-5V tolerant PIC I/O pins.
163 // #if defined(LCD_DATA_TRIS)
164 // LCD_DATA_TRIS = 0xFF;
165 // #else
166 // LCD_DATA0_TRIS = 1;
167 // LCD_DATA1_TRIS = 1;
168 // LCD_DATA2_TRIS = 1;
169 // LCD_DATA3_TRIS = 1;
170 // #if !defined(FOUR_BIT_MODE)
171 // LCD_DATA4_TRIS = 1;
172 // LCD_DATA5_TRIS = 1;
173 // LCD_DATA6_TRIS = 1;
174 // LCD_DATA7_TRIS = 1;
175 // #endif
176 // #endif
177 // LCD_RS_TRIS = 1;
178 // LCD_RD_WR_TRIS = 1;
179 }
180  
181  
182 /******************************************************************************
183 * Function: void LCDInit(void)
184 *
185 * PreCondition: None
186 *
187 * Input: None
188 *
189 * Output: None
190 *
191 * Side Effects: None
192 *
193 * Overview: LCDText[] is blanked, port I/O pin TRIS registers are
194 * configured, and the LCD is placed in the default state
195 *
196 * Note: None
197 *****************************************************************************/
198 void LCDInit(void)
199 {
200 BYTE i;
201  
202 memset(LCDText, ' ', sizeof(LCDText)-1);
203 LCDText[sizeof(LCDText)-1] = 0;
204  
205 // Setup the I/O pins
206 LCD_E_IO = 0;
207 LCD_RD_WR_IO = 0;
208  
209  
210 #if defined(LCD_DATA_TRIS)
211 LCD_DATA_TRIS = 0x00;
212 #else
213 LCD_DATA0_TRIS = 0;
214 LCD_DATA1_TRIS = 0;
215 LCD_DATA2_TRIS = 0;
216 LCD_DATA3_TRIS = 0;
217 #if !defined(FOUR_BIT_MODE)
218 LCD_DATA4_TRIS = 0;
219 LCD_DATA5_TRIS = 0;
220 LCD_DATA6_TRIS = 0;
221 LCD_DATA7_TRIS = 0;
222 #endif
223 #endif
224 LCD_RD_WR_TRIS = 0;
225 LCD_RS_TRIS = 0;
226 LCD_E_TRIS = 0;
227  
228  
229 // Wait the required time for the LCD to reset
230 DelayMs(40);
231  
232 // Set the default function
233 // Go to 8-bit mode first to reset the instruction state machine
234 // This is done in a loop 3 times to absolutely ensure that we get
235 // to 8-bit mode in case if the device was previously booted into
236 // 4-bit mode and our PIC got reset in the middle of the LCD
237 // receiving half (4-bits) of an 8-bit instruction
238 LCD_RS_IO = 0;
239 #if defined(LCD_DATA_IO)
240 LCD_DATA_IO = 0x03;
241 #else
242 LCD_DATA0_IO = 1;
243 LCD_DATA1_IO = 1;
244 LCD_DATA2_IO = 0;
245 LCD_DATA3_IO = 0;
246 #if !defined(FOUR_BIT_MODE)
247 LCD_DATA4_IO = 0;
248 LCD_DATA5_IO = 0;
249 LCD_DATA6_IO = 0;
250 LCD_DATA7_IO = 0;
251 #endif
252 #endif
253 Nop(); // Wait Data setup time (min 40ns)
254 Nop();
255 for(i = 0; i < 3u; i++)
256 {
257 LCD_E_IO = 1;
258 Delay10us(1); // Wait E Pulse width time (min 230ns)
259 LCD_E_IO = 0;
260 DelayMs(2);
261 }
262  
263 #if defined(FOUR_BIT_MODE)
264 #if defined(SAMSUNG_S6A0032)
265 // Enter 4-bit mode (requires only 4-bits on the S6A0032)
266 #if defined(LCD_DATA_IO)
267 LCD_DATA_IO = 0x02;
268 #else
269 LCD_DATA0_IO = 0;
270 LCD_DATA1_IO = 1;
271 LCD_DATA2_IO = 0;
272 LCD_DATA3_IO = 0;
273 #endif
274 Nop(); // Wait Data setup time (min 40ns)
275 Nop();
276 LCD_E_IO = 1;
277 Delay10us(1); // Wait E Pulse width time (min 230ns)
278 LCD_E_IO = 0;
279 #else
280 // Enter 4-bit mode with two lines (requires 8-bits on most LCD controllers)
281 LCDWrite(0, 0x28);
282 #endif
283 #else
284 // Use 8-bit mode with two lines
285 LCDWrite(0, 0x38);
286 #endif
287 Delay10us(5);
288  
289 // Set the entry mode
290 LCDWrite(0, 0x06); // Increment after each write, do not shift
291 Delay10us(5);
292  
293 // Set the display control
294 LCDWrite(0, 0x0C); // Turn display on, no cusor, no cursor blink
295 Delay10us(5);
296  
297 // Clear the display
298 LCDWrite(0, 0x01);
299 DelayMs(2);
300  
301 }
302  
303  
304 /******************************************************************************
305 * Function: void LCDUpdate(void)
306 *
307 * PreCondition: LCDInit() must have been called once
308 *
309 * Input: LCDText[]
310 *
311 * Output: None
312 *
313 * Side Effects: None
314 *
315 * Overview: Copies the contents of the local LCDText[] array into the
316 * LCD's internal display buffer. Null terminators in
317 * LCDText[] terminate the current line, so strings may be
318 * printed directly to LCDText[].
319 *
320 * Note: None
321 *****************************************************************************/
322 void LCDUpdate(void)
323 {
324 BYTE i, j;
325  
326 // Go home
327 LCDWrite(0, 0x02);
328 DelayMs(2);
329  
330 // Output first line
331 for(i = 0; i < 16u; i++)
332 {
333 // Erase the rest of the line if a null char is
334 // encountered (good for printing strings directly)
335 if(LCDText[i] == 0u)
336 {
337 for(j=i; j < 16u; j++)
338 {
339 LCDText[j] = ' ';
340 }
341 }
342 LCDWrite(1, LCDText[i]);
343 Delay10us(5);
344 }
345  
346 // Set the address to the second line
347 LCDWrite(0, 0xC0);
348 Delay10us(5);
349  
350 // Output second line
351 for(i = 16; i < 32u; i++)
352 {
353 // Erase the rest of the line if a null char is
354 // encountered (good for printing strings directly)
355 if(LCDText[i] == 0u)
356 {
357 for(j=i; j < 32u; j++)
358 {
359 LCDText[j] = ' ';
360 }
361 }
362 LCDWrite(1, LCDText[i]);
363 Delay10us(5);
364 }
365 }
366  
367 /******************************************************************************
368 * Function: void LCDErase(void)
369 *
370 * PreCondition: LCDInit() must have been called once
371 *
372 * Input: None
373 *
374 * Output: None
375 *
376 * Side Effects: None
377 *
378 * Overview: Clears LCDText[] and the LCD's internal display buffer
379 *
380 * Note: None
381 *****************************************************************************/
382 void LCDErase(void)
383 {
384 // Clear display
385 LCDWrite(0, 0x01);
386 DelayMs(2);
387  
388 // Clear local copy
389 memset(LCDText, ' ', 32);
390 }
391  
392 #endif //#if defined(USE_LCD)
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3