📄 lcd_a.lst
字号:
228 1 if (!Update_required)
229 1 {
230 2 return; // No data in LCD requires updating
231 2 }
232 1
233 1 // Set DDRAM address which character is to be written to
234 1 // - Assumes 2 line display (or 16x1)
235 1 // - See text for adjustments needed for other display sizes
236 1 if (Line == 0)
237 1 {
238 2 LCD_SetDDRAM(0x00 + Character); // First line
239 2 }
240 1 else
241 1 {
C51 COMPILER V6.10 LCD_A 04/18/2001 16:29:05 PAGE 5
242 2 LCD_SetDDRAM(0x40 + Character); // Second line
243 2 }
244 1
245 1 // This is the data for updating
246 1 Data = LCD_data_G[Line][Character];
247 1
248 1 // New
249 1 LCD_Send_Byte(Data,1);
250 1
251 1 // Once data has been written to LCD
252 1 LCD_data_G[Line][Character] = '\0';
253 1 }
254
255 /*------------------------------------------------------------------*-
256
257 LCD_Send_Byte()
258
259 This function writes a byte to the LCD panel.
260
261 Duration < 0.1 ms .
262
263 Parameters: Data
264 The byte to be written to the display.
265
266 DATA_FLAG:
267 If DATA_FLAG == 1, a data byte is sent
268 If DATA_FLAG == 0, a command byte is sent
269
270
271 -*------------------------------------------------------------------*/
272 void LCD_Send_Byte(const tByte DATA, const bit DATA_FLAG)
273 {
274 1 // Delays *are* needed
275 1 // [you may find it possible to reduce them on
276 1 // on some displays]
277 1 LCD_D4 = 0;
278 1 LCD_D5 = 0;
279 1 LCD_D6 = 0;
280 1 LCD_D7 = 0;
281 1 LCD_RS = DATA_FLAG; // Data register
282 1 LCD_EN = 0;
283 1 LCD_Delay();
284 1
285 1 // Write the data (high nybble)
286 1 LCD_D4 = ((DATA & 0x10) == 0x10);
287 1 LCD_D5 = ((DATA & 0x20) == 0x20);
288 1 LCD_D6 = ((DATA & 0x40) == 0x40);
289 1 LCD_D7 = ((DATA & 0x80) == 0x80);
290 1
291 1 LCD_Delay();
292 1 LCD_EN = 1; // Latch the high nybble
293 1 LCD_Delay();
294 1 LCD_EN = 0;
295 1 LCD_Delay();
296 1 LCD_D4 = 0;
297 1 LCD_D5 = 0;
298 1 LCD_D6 = 0;
299 1 LCD_D7 = 0;
300 1 LCD_RS = DATA_FLAG;
301 1 LCD_EN = 0;
302 1 LCD_Delay();
303 1
C51 COMPILER V6.10 LCD_A 04/18/2001 16:29:05 PAGE 6
304 1 // Write the data (low nybble)
305 1 LCD_D4 = ((DATA & 0x01) == 0x01);
306 1 LCD_D5 = ((DATA & 0x02) == 0x02);
307 1 LCD_D6 = ((DATA & 0x04) == 0x04);
308 1 LCD_D7 = ((DATA & 0x08) == 0x08);
309 1
310 1 LCD_Delay();
311 1 LCD_EN = 1; // Latch the low nybble
312 1 LCD_Delay();
313 1 LCD_EN = 0;
314 1 LCD_Delay();
315 1 }
316
317
318 /*------------------------------------------------------------------*-
319
320 LCD_Control_Cursor()
321
322 This function enables or clears the cursor and moves
323 it to a specified point.
324
325 Params: Visible - Set if the cursor should be visible.
326 Blinking - Set if character should be blinking
327 Address - Address (DDRAM) we want to adjust.
328
329 -*------------------------------------------------------------------*/
330 void LCD_Control_Cursor(const bit VISIBLE, const bit BLINKING,
331 const tByte ADDRESS)
332 {
333 1 // Cursor / blinking appears at current DDRAM address
334 1 // - use SetDDRAM() to alter the cursor position
335 1 tByte Command = 0x0C;
336 1
337 1 if (VISIBLE)
338 1 {
339 2 Command |= 0x02;
340 2 }
341 1
342 1 if (BLINKING)
343 1 {
344 2 Command |= 0x01;
345 2 }
346 1
347 1 LCD_Send_Byte(Command,0);
348 1 LCD_SetDDRAM(ADDRESS);
349 1 }
350
351 /*------------------------------------------------------------------*-
352
353 LCD_SetDDRAM()
354
355 Set the DDRAM to a particular address.
356
357 Used to determine where we write to in the LCD RAM and - thus -
358 whether the text appears on Line 0, Line 1, etc.
359
360 See text for details.
361
362 Params: The DDRAM address we wish to write to.
363
364 -*------------------------------------------------------------------*/
365 void LCD_SetDDRAM(tByte ADDRESS)
C51 COMPILER V6.10 LCD_A 04/18/2001 16:29:05 PAGE 7
366 {
367 1 ADDRESS &= 0x7f;
368 1 ADDRESS |= 0x80;
369 1 LCD_Send_Byte(ADDRESS,0);
370 1 }
371
372
373 /*------------------------------------------------------------------*-
374
375 LCD_SetCGRAM
376
377 Set the CGRAM to a particular address.
378
379 Used to determine where we write to in the LCD RAM
380
381 See text for details.
382
383 Params: The CGRAM address we wish to write to
384
385 -*------------------------------------------------------------------*/
386 void LCD_SetCGRAM(tByte Address)
387 {
388 1 Address &= 0x3f;
389 1 Address |= 0x40;
390 1 LCD_Send_Byte(Address,0);
391 1 }
392
393
394 /*------------------------------------------------------------------*-
395
396 LCD_Create_Character()
397
398 Stores a user-defined character in the CG RAM. Up to 8 characters
399 may be stored in this way. Note: characters are assumed to be
400 5x8 in size: if you need 5x11 characters you will need to adapt
401 this code.
402
403 Parameters: The character data (see start of file)
404
405 -*------------------------------------------------------------------*/
406 void LCD_Create_Character(const tByte UDC_ID,
407 const tByte* const pUDC_PAT)
408 {
409 1 tByte Row;
410 1
411 1 LCD_SetCGRAM(UDC_ID << 3);
412 1
413 1 // Now write the data
414 1 for (Row = 0; Row < 8; Row++)
415 1 {
416 2 LCD_Send_Byte(pUDC_PAT[Row], 1);
417 2 }
418 1
419 1
420 1 // Make sure we next write to DD RAM
421 1 LCD_SetDDRAM(0x00);
422 1 }
423
424
425 /*------------------------------------------------------------------*-
426
427 LCD_Delay()
C51 COMPILER V6.10 LCD_A 04/18/2001 16:29:05 PAGE 8
428
429 This function provides a short delay for the LCD library.
430
431 -*------------------------------------------------------------------*/
432 void LCD_Delay(void)
433 {
434 1 int x;
435 1
436 1 x++;
437 1 x++;
438 1 x++;
439 1 }
440
441 /*------------------------------------------------------------------*-
442 ---- END OF FILE -------------------------------------------------
443 -*------------------------------------------------------------------*/
444
445
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 625 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 60 11
IDATA SIZE = ---- ----
BIT SIZE = ---- 5
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -