lcd44780.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 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. {
  73. int i;
  74. for(i = 1; i < 2000; i++)
  75. lcd44780_wait();
  76. }
  77. #endif
  78. }
  79. void lcd44780_init(void)
  80. {
  81. // The display on the RockHopper is physically a single
  82. // 16 char line (two 8 char lines concatenated). bdl
  83. lcd44780_command(LCD44780_8BIT_2LINE);
  84. lcd44780_command(LCD44780_MODE_INC);
  85. lcd44780_command(LCD44780_CURSOR_BLOCK);
  86. lcd44780_command(LCD44780_CLEAR);
  87. }