圣源电子制作

 找回密码
 立即注册
查看: 11091|回复: 1
打印 上一主题 下一主题

arduino学习笔记 - nokia 5110 LCD驱动实验

[复制链接]
跳转到指定楼层
楼主
发表于 2012-4-28 23:11:44 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
转载自互联网!!!仅供学习
arduino配套的显示器淘宝上大多是 1602 和  12864 屏其中1602价格便宜,但液晶屏幕很小,而且不能显示英文,12864可以显示中文甚至有自带字库的,但价格相对比较贵
这时,我们还有另外一个选择,nokia 5110 液晶

这款屏幕分辨率为84x48,最多可以显示4行汉字,而且价格便宜,10几元钱就可以买到了

淘宝上卖的一般是带背光的,控制芯片位pcd8554,每家店里出售的可能多少有点小不同
这是显示效果。
Nokia/诺基亚5110 LCD原理应用资料PH7366 是NOKIA 公司生产的可用于其5110、6150,6100 等系列移动电话的液晶显示模块,国内厂家也生产有类似的兼容产品。该产品除应用于移动电话外,也可广泛应用于各类便携式设备的显示系统。与其它类型的产品相比,该模块具有以下特点:
●84x48 的点阵LCD,可以显示4 行汉字,
●采用串行接口与主处理器进行通信,接口信号线数量大幅度减少,包括电源和地在内的信号线仅有9 条。支持多种串行通信协议(如AVR 单片机的SPI、MCS51 的串口模式0等),传输速率高达4Mbps,可全速写入显示数据,无等待时间。
●可通过导电胶连接模块与印制版,而不用连接电缆,用模块上的金属钩可将模块固定到印制板上,因而非常便于安装和更换。
●LCD 控制器/驱动器芯片已绑定到LCD 晶片上,模块的体积很小。
●采用低电压供电,正常显示时的工作电流在200μA 以下,且具有掉电模式。
LPH7366 的这些特点非常适合于电池供电的便携式通信设备和测试设备中

首先申明一下,我所使用的nokia 5110屏是8个引脚的。有些是9个脚的,方法相同,自己按照方法接就好了。

先上实物图和连接图!




下面就是把驱动代码给附上了,有什么问题欢迎大家提问发言!
  1. // The pins to use on the arduino
  2. #define PIN_SCE   7
  3. #define PIN_RESET 6
  4. #define PIN_DC    5
  5. #define PIN_SDIN  4
  6. #define PIN_SCLK  3

  7. // COnfiguration for the LCD
  8. #define LCD_C     LOW
  9. #define LCD_D     HIGH
  10. #define LCD_CMD   0

  11. // Size of the LCD
  12. #define LCD_X     84
  13. #define LCD_Y     48

  14. int scrollPosition = -10;

  15. static const byte ASCII[][5] =
  16. {
  17. {0x00, 0x00, 0x00, 0x00, 0x00} // 20
  18. ,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
  19. ,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
  20. ,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
  21. ,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
  22. ,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
  23. ,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
  24. ,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
  25. ,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
  26. ,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
  27. ,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
  28. ,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
  29. ,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
  30. ,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
  31. ,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
  32. ,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
  33. ,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
  34. ,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
  35. ,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
  36. ,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
  37. ,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
  38. ,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
  39. ,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
  40. ,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
  41. ,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
  42. ,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
  43. ,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
  44. ,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
  45. ,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
  46. ,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
  47. ,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
  48. ,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
  49. ,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
  50. ,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
  51. ,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
  52. ,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
  53. ,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
  54. ,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
  55. ,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
  56. ,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
  57. ,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
  58. ,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
  59. ,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
  60. ,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
  61. ,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
  62. ,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
  63. ,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
  64. ,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
  65. ,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
  66. ,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
  67. ,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
  68. ,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
  69. ,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
  70. ,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
  71. ,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
  72. ,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
  73. ,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
  74. ,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
  75. ,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
  76. ,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
  77. ,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c
  78. ,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
  79. ,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
  80. ,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
  81. ,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
  82. ,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
  83. ,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
  84. ,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
  85. ,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
  86. ,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
  87. ,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
  88. ,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
  89. ,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
  90. ,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
  91. ,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
  92. ,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
  93. ,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
  94. ,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
  95. ,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
  96. ,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
  97. ,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
  98. ,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
  99. ,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
  100. ,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
  101. ,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
  102. ,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
  103. ,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
  104. ,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
  105. ,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
  106. ,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
  107. ,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
  108. ,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
  109. ,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
  110. ,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
  111. ,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ←
  112. ,{0x00, 0x06, 0x09, 0x09, 0x06} // 7f →
  113. };

  114. void LcdCharacter(char character)
  115. {
  116.   LcdWrite(LCD_D, 0x00);
  117.   for (int index = 0; index < 5; index++)
  118.   {
  119.     LcdWrite(LCD_D, ASCII[character - 0x20][index]);
  120.   }
  121.   LcdWrite(LCD_D, 0x00);
  122. }

  123. void LcdClear(void)
  124. {
  125.   for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
  126.   {
  127.     LcdWrite(LCD_D, 0x00);
  128.   }
  129. }

  130. void LcdInitialise(void)
  131. {
  132.   pinMode(PIN_SCE,   OUTPUT);
  133.   pinMode(PIN_RESET, OUTPUT);
  134.   pinMode(PIN_DC,    OUTPUT);
  135.   pinMode(PIN_SDIN,  OUTPUT);
  136.   pinMode(PIN_SCLK,  OUTPUT);

  137.   digitalWrite(PIN_RESET, LOW);
  138.   digitalWrite(PIN_RESET, HIGH);

  139.   LcdWrite(LCD_CMD, 0x21);  // LCD Extended Commands.
  140.   LcdWrite(LCD_CMD, 0xBf);  // Set LCD Vop (Contrast). //B1
  141.   LcdWrite(LCD_CMD, 0x04);  // Set Temp coefficent. //0x04
  142.   LcdWrite(LCD_CMD, 0x14);  // LCD bias mode 1:48. //0x13
  143.   LcdWrite(LCD_CMD, 0x0C);  // LCD in normal mode. 0x0d for inverse
  144.   LcdWrite(LCD_C, 0x20);
  145.   LcdWrite(LCD_C, 0x0C);
  146. }

  147. void LcdString(char *characters)
  148. {
  149.   while (*characters)
  150.   {
  151.     LcdCharacter(*characters++);
  152.   }
  153. }

  154. void LcdWrite(byte dc, byte data)
  155. {
  156.   digitalWrite(PIN_DC, dc);
  157.   digitalWrite(PIN_SCE, LOW);
  158.   shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
  159.   digitalWrite(PIN_SCE, HIGH);
  160. }

  161. /**
  162. * gotoXY routine to position cursor
  163. * x - range: 0 to 84
  164. * y - range: 0 to 5
  165. */
  166. void gotoXY(int x, int y)
  167. {
  168.   LcdWrite( 0, 0x80 | x);  // Column.
  169.   LcdWrite( 0, 0x40 | y);  // Row.
  170. }

  171. void drawBox(void)
  172. {
  173.   int j;
  174.   for(j = 0; j < 84; j++) // top
  175.   {
  176.     gotoXY(j, 0);
  177.     LcdWrite(1, 0x01);
  178.   }

  179.   for(j = 0; j < 84; j++) //Bottom
  180.   {
  181.     gotoXY(j, 5);
  182.     LcdWrite(1, 0x80);
  183.   }

  184.   for(j = 0; j < 6; j++) // Right
  185.   {
  186.     gotoXY(83, j);
  187.     LcdWrite(1, 0xff);
  188.   }

  189.   for(j = 0; j < 6; j++) // Left
  190.   {
  191.     gotoXY(0, j);
  192.     LcdWrite(1, 0xff);
  193.   }
  194. }

  195. void Scroll(String message)
  196. {
  197.   for (int i = scrollPosition; i < scrollPosition + 11; i++)
  198.   {
  199.     if ((i >= message.length()) || (i < 0))
  200.     {
  201.       LcdCharacter(' ');
  202.     }
  203.     else
  204.     {
  205.       LcdCharacter(message.charAt(i));
  206.     }
  207.   }
  208.   scrollPosition++;
  209.   if ((scrollPosition >= message.length()) && (scrollPosition > 0))
  210.   {
  211.     scrollPosition = -10;
  212.   }
  213. }

  214. void setup(void)
  215. {
  216.   LcdInitialise();
  217.   LcdClear();
  218.   drawBox();

  219.   gotoXY(7,1);
  220.   LcdString("Nokia 5110");
  221.   gotoXY(4,2);
  222.   LcdString("Scroll Demo");
  223. }

  224. void loop(void)
  225. {
  226.   gotoXY(4,4);
  227.   Scroll("for maore products please visit www.geeetech.com");
  228.   delay(200);
  229. }  
复制代码
下载:
nokia5110_nokia3310中文数据手册.pdf (753.32 KB, 下载次数: 21)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|联系我们|闽公网安备 35012102000020号|闽ICP备11020110号-1|圣源电子

GMT+8, 2024-9-20 00:19 , Processed in 0.048025 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表