/[H8]/trunk/docs/Microchip TCP_IP stack/TCPIP Stack/LCDBlocking.c
ViewVC logotype

Contents of /trunk/docs/Microchip TCP_IP stack/TCPIP Stack/LCDBlocking.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (show annotations) (download)
Thu Apr 19 09:01:15 2007 UTC (17 years, 1 month ago) by hedin
File MIME type: text/plain
File size: 7300 byte(s)
added the TCP/IP stack, source code.
1 /*********************************************************************
2 *
3 * LCD Access Routines
4 *
5 *********************************************************************
6 * FileName: LCDBlocking.c
7 * Dependencies: Compiler.h, HardwareProfile.h
8 * Processor: PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F
9 * Complier: Microchip C18 v3.02 or higher
10 * Microchip C30 v2.01 or higher
11 * Company: Microchip Technology, Inc.
12 *
13 * Software License Agreement
14 *
15 * Copyright © 2002-2007 Microchip Technology Inc. All rights
16 * reserved.
17 *
18 * Microchip licenses to you the right to use, modify, copy, and
19 * distribute:
20 * (i) the Software when embedded on a Microchip microcontroller or
21 * digital signal controller product (“Device”) which is
22 * integrated into Licensee’s product; or
23 * (ii) ONLY the Software driver source files ENC28J60.c and
24 * ENC28J60.h ported to a non-Microchip device used in
25 * conjunction with a Microchip ethernet controller for the
26 * sole purpose of interfacing with the ethernet controller.
27 *
28 * You should refer to the license agreement accompanying this
29 * Software for additional information regarding your rights and
30 * obligations.
31 *
32 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT
33 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
34 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
35 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
36 * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
37 * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
38 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
39 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
40 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
41 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
42 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
43 *
44 *
45 * Author Date Comment
46 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47 * Howard Schlunder 4/03/06 Original
48 * Howard Schlunder 4/12/06 Changed from using PMP to LCDWrite()
49 * Howard Schlunder 8/10/06 Fixed a delay being too short
50 * when CLOCK_FREQ was a smaller
51 * value, added FOUR_BIT_MODE
52 ********************************************************************/
53 #define __LCDBLOCKING_C
54
55 #include "TCPIP Stack/TCPIP.h"
56
57 #if defined(USE_LCD)
58
59
60 #if defined(PICDEMNET)
61 #define FOUR_BIT_MODE
62 #endif
63
64 // LCDText is a 32 byte shadow of the LCD text. Write to it and
65 // then call LCDUpdate() to copy the string into the LCD module.
66 BYTE LCDText[16*2+1];
67
68 /******************************************************************************
69 * Function: static void LCDWrite(BYTE RS, BYTE Data)
70 *
71 * PreCondition: None
72 *
73 * Input: RS - Register Select - 1:RAM, 0:Config registers
74 * Data - 8 bits of data to write
75 *
76 * Output: None
77 *
78 * Side Effects: None
79 *
80 * Overview: Controls the Port I/O pins to cause an LCD write
81 *
82 * Note: None
83 *****************************************************************************/
84 static void LCDWrite(BYTE RS, BYTE Data)
85 {
86 LCD_DATA_TRIS = 0x00;
87 LCD_RS_TRIS = 0;
88 LCD_RD_WR_TRIS = 0;
89 LCD_RD_WR_IO = 0;
90 LCD_RS_IO = RS;
91
92 #if defined(FOUR_BIT_MODE)
93 LCD_DATA_IO = Data>>4;
94 Nop(); // Wait Data setup time (min 40ns)
95 Nop();
96 LCD_E_IO = 1;
97 Nop(); // Wait E Pulse width time (min 230ns)
98 Nop();
99 Nop();
100 Nop();
101 Nop();
102 Nop();
103 Nop();
104 Nop();
105 Nop();
106 LCD_E_IO = 0;
107 #endif
108
109 LCD_DATA_IO = Data;
110 Nop(); // Wait Data setup time (min 40ns)
111 Nop();
112 LCD_E_IO = 1;
113 Nop(); // Wait E Pulse width time (min 230ns)
114 Nop();
115 Nop();
116 Nop();
117 Nop();
118 Nop();
119 Nop();
120 Nop();
121 Nop();
122 LCD_E_IO = 0;
123
124 LCD_DATA_TRIS = 0xFF;
125 LCD_RS_TRIS = 1;
126 LCD_RD_WR_TRIS = 1;
127 }
128
129
130 /******************************************************************************
131 * Function: void LCDInit(void)
132 *
133 * PreCondition: None
134 *
135 * Input: None
136 *
137 * Output: None
138 *
139 * Side Effects: None
140 *
141 * Overview: LCDText[] is blanked, port I/O pin TRIS registers are
142 * configured, and the LCD is placed in the default state
143 *
144 * Note: None
145 *****************************************************************************/
146 void LCDInit(void)
147 {
148 BYTE i;
149
150 for(i = 0; i < sizeof(LCDText)-1; i++)
151 {
152 LCDText[i] = ' ';
153 }
154 LCDText[sizeof(LCDText)-1] = 0;
155
156 // Setup the I/O pins
157 LCD_E_IO = 0;
158 LCD_RD_WR_IO = 0;
159
160 LCD_DATA_TRIS = 0x00;
161 LCD_RD_WR_TRIS = 0;
162 LCD_RS_TRIS = 0;
163 LCD_E_TRIS = 0;
164
165
166 // Wait the required time for the LCD to reset
167 DelayMs(30);
168
169 // Set the default function
170 #if defined(FOUR_BIT_MODE)
171 LCDWrite(0, 0x28);
172 #else
173 LCDWrite(0, 0x38);
174 #endif
175 Delay10us(5);
176
177 // Set the display control
178 LCDWrite(0, 0x0C);
179 Delay10us(5);
180
181 // Clear the display
182 LCDWrite(0, 0x01);
183 Delay10us(153);
184
185 // Set the entry mode
186 LCDWrite(0, 0x06);
187 Delay10us(5);
188 }
189
190
191 /******************************************************************************
192 * Function: void LCDUpdate(void)
193 *
194 * PreCondition: LCDInit() must have been called once
195 *
196 * Input: LCDText[]
197 *
198 * Output: None
199 *
200 * Side Effects: None
201 *
202 * Overview: Copies the contents of the local LCDText[] array into the
203 * LCD's internal display buffer. Null terminators in
204 * LCDText[] terminate the current line, so strings may be
205 * printed directly to LCDText[].
206 *
207 * Note: None
208 *****************************************************************************/
209 void LCDUpdate(void)
210 {
211 BYTE i, j;
212
213 // Go home
214 LCDWrite(0, 0x02);
215 DelayMs(1);
216 Delay10us(53);
217
218 // Output first line
219 for(i = 0; i < 16u; i++)
220 {
221 // Erase the rest of the line if a null char is
222 // encountered (good for printing strings directly)
223 if(LCDText[i] == 0u)
224 {
225 for(j=i; j < 16u; j++)
226 {
227 LCDText[j] = ' ';
228 }
229 }
230 LCDWrite(1, LCDText[i]);
231 Delay10us(5);
232 }
233
234 // Set the address to the second line
235 LCDWrite(0, 0xC0);
236 Delay10us(5);
237
238 // Output second line
239 for(i = 16; i < 32u; i++)
240 {
241 // Erase the rest of the line if a null char is
242 // encountered (good for printing strings directly)
243 if(LCDText[i] == 0u)
244 {
245 for(j=i; j < 32u; j++)
246 {
247 LCDText[j] = ' ';
248 }
249 }
250 LCDWrite(1, LCDText[i]);
251 Delay10us(5);
252 }
253 }
254
255 /******************************************************************************
256 * Function: void LCDErase(void)
257 *
258 * PreCondition: LCDInit() must have been called once
259 *
260 * Input: None
261 *
262 * Output: None
263 *
264 * Side Effects: None
265 *
266 * Overview: Clears LCDText[] and the LCD's internal display buffer
267 *
268 * Note: None
269 *****************************************************************************/
270 void LCDErase(void)
271 {
272 // Clear display
273 LCDWrite(0, 0x01);
274 Delay10us(153);
275
276 // Clear local copy
277 memset(LCDText, ' ', 32);
278 }
279
280 #endif //#if defined(USE_LCD)

  ViewVC Help
Powered by ViewVC 1.1.20