lcd44780.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * lcd44780.c
  3.  * Simple "driver" for a memory-mapped 44780-style LCD display.
  4.  *
  5.  * Copyright 2001 Bradley D. LaRonde <brad@ltc.com>
  6.  *
  7.  * This program is free software; you can redistribute  it and/or modify it
  8.  * under  the terms of  the GNU General  Public License as published by the
  9.  * Free Software Foundation;  either version 2 of the  License, or (at your
  10.  * option) any later version.
  11.  *
  12.  */
  13. #define LCD44780_COMMAND   ((volatile unsigned char *)0xbe020000)
  14. #define LCD44780_DATA      ((volatile unsigned char *)0xbe020001)
  15. #define LCD44780_4BIT_1LINE        0x20
  16. #define LCD44780_4BIT_2LINE        0x28
  17. #define LCD44780_8BIT_1LINE        0x30
  18. #define LCD44780_8BIT_2LINE        0x38
  19. #define LCD44780_MODE_DEC          0x04
  20. #define LCD44780_MODE_DEC_SHIFT    0x05
  21. #define LCD44780_MODE_INC          0x06
  22. #define LCD44780_MODE_INC_SHIFT    0x07
  23. #define LCD44780_SCROLL_LEFT       0x18
  24. #define LCD44780_SCROLL_RIGHT      0x1e
  25. #define LCD44780_CURSOR_UNDERLINE  0x0e
  26. #define LCD44780_CURSOR_BLOCK      0x0f
  27. #define LCD44780_CURSOR_OFF        0x0c
  28. #define LCD44780_CLEAR             0x01
  29. #define LCD44780_BLANK             0x08
  30. #define LCD44780_RESTORE           0x0c  // Same as CURSOR_OFF
  31. #define LCD44780_HOME              0x02
  32. #define LCD44780_LEFT              0x10
  33. #define LCD44780_RIGHT             0x14
  34. void lcd44780_wait(void)
  35. {
  36. int i, j;
  37. for(i=0; i < 400; i++)
  38. for(j=0; j < 10000; j++);
  39. }
  40. void lcd44780_command(unsigned char c)
  41. {
  42. *LCD44780_COMMAND = c;
  43. lcd44780_wait();
  44. }
  45. void lcd44780_data(unsigned char c)
  46. {
  47. *LCD44780_DATA = c;
  48. lcd44780_wait();
  49. }
  50. void lcd44780_puts(const char* s)
  51. {
  52. int i,j;
  53. int pos = 0;
  54. lcd44780_command(LCD44780_CLEAR);
  55. while(*s) {
  56. lcd44780_data(*s);
  57. s++;
  58. pos++;
  59. if (pos == 8) {
  60.   /* We must write 32 of spaces to get cursor to 2nd line */
  61.   for (j=0; j<32; j++) {
  62.     lcd44780_data(' ');
  63.   }
  64. }
  65. if (pos == 16) {
  66.   /* We have filled all 16 character positions, so stop
  67.      outputing data */
  68.   break;
  69. }
  70. }
  71. #ifdef LCD44780_PUTS_PAUSE
  72. for(i = 1; i < 2000; i++)
  73. lcd44780_wait();
  74. #endif
  75. }
  76. void lcd44780_init(void)
  77. {
  78. // The display on the RockHopper is physically a single
  79. // 16 char line (two 8 char lines concatenated).  bdl
  80. lcd44780_command(LCD44780_8BIT_2LINE);
  81. lcd44780_command(LCD44780_MODE_INC);
  82. lcd44780_command(LCD44780_CURSOR_BLOCK);
  83. lcd44780_command(LCD44780_CLEAR);
  84. }