树莓派论坛

 找回密码
 立即注册

pcDuino连结16 x 2 LCD屏 Shield

树老大 发表于 2013-5-16 22:42:58 | 显示全部楼层 |阅读模式
http://player.youku.com/player.php/sid/XNTIzNjE2NjA4/v.swf
360截图20130516223900128.jpg
  1. #include "core.h"

  2. #define RS 8
  3. #define EN 9
  4. #define backlight 10
  5. #define RS_L digitalWrite(RS,LOW)
  6. #define RS_H digitalWrite(RS,HIGH)
  7. #define EN_L digitalWrite(EN,LOW)
  8. #define EN_H digitalWrite(EN,HIGH)
  9. int DB[] = {7,6,5,4};
  10. /********************************************************************/
  11. void write_command(int command)
  12. {
  13. int i,temp;
  14. RS_L;
  15. EN_L;
  16. temp=command & 0xf0;
  17. for (i=0; i < 4; i++)
  18. {
  19. if(temp&0x80)
  20. digitalWrite(DB[i],HIGH);
  21. else digitalWrite(DB[i],LOW);
  22. temp <<= 1;
  23. }
  24. EN_H;
  25. delayMicroseconds(1);
  26. EN_L;
  27. temp=(command & 0x0f)<<4;
  28. for (i=0; i < 4; i++)
  29. {
  30. if(temp&0x80)
  31. digitalWrite(DB[i],HIGH);
  32. else digitalWrite(DB[i],LOW);
  33. temp <<= 1;
  34. }
  35. EN_H;
  36. delayMicroseconds(1);
  37. EN_L;
  38. }

  39. /********************************************************************/
  40. void write_data(int dat)
  41. {
  42. int i=0,temp;
  43. RS_H;
  44. EN_L;
  45. temp=dat & 0xf0;
  46. for (i=0; i < 4; i++)
  47. {
  48. if(temp&0x80)
  49. digitalWrite(DB[i],HIGH);
  50. else digitalWrite(DB[i],LOW);
  51. temp <<= 1;
  52. }
  53. EN_H;
  54. delayMicroseconds(1);
  55. EN_L;
  56. temp=(dat & 0x0f)<<4;
  57. for (i=0; i < 4; i++)
  58. {
  59. if(temp&0x80)
  60. digitalWrite(DB[i],HIGH);
  61. else digitalWrite(DB[i],LOW);
  62. temp <<= 1;

  63. }
  64. EN_H;
  65. delayMicroseconds(1);
  66. EN_L;
  67. }
  68. /********************************************************************/
  69. void LCD_write_char( int x,int y,int dat)
  70. {
  71. int address;
  72. if (x ==0) address = 0x80 + y;
  73. else address = 0xC0 + y;
  74. write_command(address);
  75. write_data(dat);
  76. delayMicroseconds(10);
  77. }
  78. /********************************************************************/
  79. void lcd1602_init()
  80. {
  81. int i = 0;
  82. pinMode(RS,OUTPUT);
  83. pinMode(EN,OUTPUT);
  84. pinMode(backlight,OUTPUT);
  85. digitalWrite(backlight,HIGH);
  86. for (i=0; i < 4; i++)
  87. {
  88. pinMode(DB[i],OUTPUT);
  89. }
  90. delay(100);
  91. write_command(0x28);
  92. delay(50);
  93. write_command(0x06);
  94. delay(50);
  95. write_command(0x0c);
  96. delay(50);
  97. write_command(0x80);
  98. delay(50);
  99. write_command(0x01);
  100. delay(100);
  101. }
  102. /********************************************************************/
  103. void setup (void)
  104. {
  105. lcd1602_init();
  106. }
  107. /********************************************************************/
  108. void loop (void)
  109. {
  110. write_command(0x02);
  111. delay(10);
  112. LCD_write_char(0,2,'W');
  113. LCD_write_char(0,3,'e');
  114. LCD_write_char(0,4,'l');
  115. LCD_write_char(0,5,'c');
  116. LCD_write_char(0,6,'o');
  117. LCD_write_char(0,7,'m');
  118. LCD_write_char(0,8,'e');

  119. LCD_write_char(0,10,'t');
  120. LCD_write_char(0,11,'o');

  121. LCD_write_char(1,4,'p');
  122. LCD_write_char(1,5,'c');
  123. LCD_write_char(1,6,'D');
  124. LCD_write_char(1,7,'u');
  125. LCD_write_char(1,8,'i');
  126. LCD_write_char(1,9,'n');
  127. LCD_write_char(1,10,'o');
  128. while(1);
  129. }
复制代码
joejoe 发表于 2013-12-15 13:35:31 | 显示全部楼层
请问楼主这块1602LCD Keypad怎么和树莓派相连
mouselt 发表于 2014-4-9 19:43:36 | 显示全部楼层
感谢楼主分享
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版 | Archiver | 树莓派论坛 ( 粤ICP备15075382号-1 )