Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * lcd.c:
  3. * Text-based LCD driver.
  4. * This is designed to drive the parallel interface LCD drivers
  5. * based in the Hitachi HD44780U controller and compatables.
  6. *
  7. * Copyright (c) 2012 Gordon Henderson.
  8. ***********************************************************************
  9. * This file is part of wiringPi:
  10. * https://projects.drogon.net/raspberry-pi/wiringpi/
  11. *
  12. * wiringPi is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * wiringPi is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
  24. ***********************************************************************
  25. */
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <stdint.h>
  29. #include <unistd.h>
  30. #include <string.h>
  31. #include <time.h>
  32. #include <wiringPi.h>
  33. #include <lcd.h>
  34. int main (void)
  35. {
  36. int i, j ;
  37. int fd1, fd2 ;
  38. char message1 [256] ;
  39. char message2 [256] ;
  40. char buf1 [30] ;
  41. char buf2 [30] ;
  42. struct tm *t ;
  43. time_t tim ;
  44. printf ("Raspberry Pi LCD test program\n") ;
  45. if (wiringPiSetup () == -1)
  46. exit (1) ;
  47. fd1 = lcdInit (4, 20, 4, 8, 9, 4,5,6,7,0,0,0,0) ;
  48. fd2 = lcdInit (2, 16, 4, 8, 10, 4,5,6,7,0,0,0,0) ;
  49. //fd1 = lcdInit (4, 20, 8, 8, 9, 0,1,2,3,4,5,6,7) ;
  50. //fd2 = lcdInit (2, 16, 8, 8, 10, 0,1,2,3,4,5,6,7) ;
  51. if (fd1 == -1)
  52. {
  53. printf ("lcdInit 1 failed\n") ;
  54. return 1 ;
  55. }
  56. if (fd2 == -1)
  57. {
  58. printf ("lcdInit 2 failed\n") ;
  59. return 1 ;
  60. }
  61. sleep (1) ;
  62. lcdPosition (fd1, 0, 0) ; lcdPuts (fd1, " Gordon Henderson") ;
  63. lcdPosition (fd1, 0, 1) ; lcdPuts (fd1, " --------------") ;
  64. /*
  65. lcdPosition (fd1, 0, 2) ; lcdPuts (fd1, " 00:00:00") ;
  66. lcdPosition (fd1, 0, 3) ; lcdPuts (fd1, " DD:MM:YY") ;
  67. */
  68. lcdPosition (fd2, 0, 0) ; lcdPuts (fd2, "Gordon Henderson") ;
  69. lcdPosition (fd2, 0, 1) ; lcdPuts (fd2, "----------------") ;
  70. sleep (2) ;
  71. sprintf (message1, "%s", " http://projects.drogon.net/ ") ;
  72. sprintf (message2, "%s", " This is a long message to go into the smaller display just for a demonstration of what we can do. ") ;
  73. for (;;)
  74. {
  75. i = 0 ;
  76. j = 0 ;
  77. for (;;)
  78. {
  79. strncpy (buf1, &message1 [i], 20) ;
  80. buf1 [20] = 0 ;
  81. lcdPosition (fd1, 0, 1) ;
  82. lcdPuts (fd1, buf1) ;
  83. ++i ;
  84. if (i == strlen (message1) - 20)
  85. i = 0 ;
  86. strncpy (buf2, &message2 [j], 16) ;
  87. buf2 [16] = 0 ;
  88. lcdPosition (fd2, 0, 1) ;
  89. lcdPuts (fd2, buf2) ;
  90. ++j ;
  91. if (j == strlen (message2) - 16)
  92. j = 0 ;
  93. tim = time (NULL) ;
  94. t = localtime (&tim) ;
  95. sprintf (buf1, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ;
  96. lcdPosition (fd1, 5, 2) ;
  97. lcdPuts (fd1, buf1) ;
  98. sprintf (buf1, "%02d/%02d/%02d", t->tm_mday, t->tm_mon + 1, t->tm_year+1900) ;
  99. lcdPosition (fd1, 4, 3) ;
  100. lcdPuts (fd1, buf1) ;
  101. delay (250) ;
  102. }
  103. }
  104. return 0 ;
  105. }