5回答

2收藏

STM32F407学习之GPIO驱动NOKIA LCD5110

#竞赛 #竞赛 6985 人阅读 | 5 人回复 | 2013-08-15

本帖最后由 lungfei 于 2013-8-15 11:29 编辑

1、nokia5110显示器介绍
这款液晶显示屏是通过PCD8554驱动控制器来驱动的,主要的特征如下:
单芯片 LCD 控制/驱动
48 行,84 列输出
显示数据 RAM 48*84 位
芯片集成:
——LCD电压发生器(也可以使用外部电压供应)
——LCD偏置电压发生器
——振荡器不需要外接元件(也可以使用外部时钟)
外部 RES(复位)输入引脚
串行界面最高4.0Mbits/S
CMOS兼容输入
混合速率:48
逻辑电压范围VDD到 VSS:2.7V~3.3V
显示电压范围VLCD到 VSS:
——6.0~8.5V LCD内部电压发生器(充许电压发生器)
——6.0~9.0V LCD外部电压供应(电压发生器关闭)
低功耗,适用于电池供电系统
关于VLCD的温度补偿
使用温度范围:-25~70℃
PCD8544 是一块低功耗的CMOS LCD控制驱动器,设计为驱动48 行84 列的图形显示。所有必须的显示功能集成在一块芯片上,包括LCD 电压及偏置电压发生器,只须很少外部元件且功耗小。 PCD8544 与微控制器的接口使用串行总线。PCD8544 采用 CMOS工艺。
方框图:

引脚图:

2、STM32控制LCD_5110连接图
GPIOB5<======================>SCE
GPIOB6<======================>RES
GPIOB7<======================>DC
GPIOB8<======================>SDIN
GPIOB9<======================>SCLK
3、程序
    1. //main.c
    2. /*芯片:STM32F407*/
    3. #include "stm32f4xx.h"
    4. #include "lcd5110.h"
    5. #include "delay.h"

    6. int main(void)
    7. {
    8.                 GPIO_Configuration();
    9.                 LCD_init();           
    10.                 LCD_clear();
    11.                 LCD_write_chinese(10,0,0);
    12.                 LCD_write_chinese(22,0,1);
    13.                 LCD_write_chinese(34,0,2);
    14.                 LCD_write_chinese(46,0,3);
    15.                 LCD_write_chinese(58,0,4);
    16.                 LCD_write_chinese(70,0,5);
    17. //                LCD_write_Picture(tu);//display full screen picture.
    18. return 0;  
    19. }
    复制代码
    1. lcd5110.c
    2. /*
    3. file:lcd 5110 driver
    4. author:Allen
    5. 和大家分享,共同学习,一起进步。
    6. Share more,learn better.
    7. some code is referenced from network.
    8. */
    9. #include "lcd5110.h"
    10. #include "delay.h"
    11. unsigned char tu[]=
    12. {
    13. 0x00,0x00,0x00,0x80,0x80,0xC0,0xC0,0x60,0x60,0x60,0x20,0x30,0x20,0x20,0x20,0x62,
    14. 0x62,0x72,0xCC,0xF7,0xF2,0x23,0x02,0xC4,0x78,0x0C,0xE6,0xF2,0xE3,0x02,0x02,0x02,
    15. 0x07,0x0C,0x3C,0xC2,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    16. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    17. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    18. 0x00,0x00,0x00,0x00,0xF0,0xFC,0x0E,0x03,0x01,0x00,0x80,0x60,0x10,0x40,0x14,0x00,
    19. 0x00,0x00,0x00,0x00,0x20,0x38,0x18,0x58,0x19,0x59,0x23,0x03,0x07,0x0C,0x08,0x10,
    20. 0x30,0x30,0x30,0x90,0x38,0x5C,0x3F,0xF1,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
    21. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    22. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    23. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x1F,0x3C,0x70,0xE0,0xC0,0xC2,0x8D,
    24. 0xA2,0x08,0x21,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    25. 0x00,0x80,0x80,0xC0,0xE0,0x20,0x00,0x00,0x00,0x02,0x51,0x04,0xAB,0xFF,0xFE,0x00,
    26. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    27. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    28. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    29. 0x00,0x0A,0x3F,0xF3,0xD7,0xAF,0x5B,0x33,0xE3,0x42,0xDF,0xE6,0x86,0x82,0x82,0x82,
    30. 0xC3,0x7E,0x43,0x63,0x21,0x31,0x18,0x06,0x81,0x00,0x00,0xA0,0x80,0xC8,0xE1,0xF4,
    31. 0x7A,0x3F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    32. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    33. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    34. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x07,0x0E,0x0D,0x1C,0x1D,
    35. 0x3A,0x39,0xFA,0xF8,0x7A,0xB8,0x1A,0xB8,0x1C,0xAD,0x1C,0xBE,0x1E,0xBE,0x3F,0xF3,
    36. 0xE3,0xC1,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    37. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    38. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    39. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    40. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    41. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    42. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    43. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    44. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00  
    45. };   
    46. unsigned char tu1[]= {
    47. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0xF8,0xF0,0xE0,0xC0,
    48. 0x80,0x80,0x80,0x80,0xC0,0xE0,0xFE,0xFF,0xFE,0xF0,0xC0,0x80,0x80,0x80,0x80,0xC0,
    49. 0xE0,0xF0,0xF8,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    50. 0x00,0x00,0x10,0x30,0x70,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xF0,0xFF,0x7F,0x3F,0x1F,
    51. 0x0F,0x07,0x07,0x07,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x07,0x07,0x07,0x0F,
    52. 0x1F,0x1F,0x7F,0xF8,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0x78,0x38,0x18,0x08,0x00,0x00,
    53. 0x00,0x00,0x80,0x80,0xC0,0xC0,0xE3,0xFF,0xFF,0xFF,0x1F,0x03,0x00,0x00,0x00,0x00,
    54. 0x1E,0x3F,0x3F,0x3F,0x3F,0x1E,0x00,0x00,0x00,0x00,0x1E,0x3F,0x3F,0x3F,0x3F,0x1E,
    55. 0x00,0x00,0x00,0x00,0x03,0x0F,0xFF,0xFF,0xFF,0xF0,0xE0,0xE0,0xC0,0xC0,0xC0,0xC0,
    56. 0x03,0x03,0x03,0x03,0x07,0x07,0x0F,0xDF,0xFF,0xFF,0xF8,0xC0,0x00,0x00,0x00,0x1E,
    57. 0x7C,0xF0,0xE0,0xC0,0xC0,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0xE0,0xF0,0x7C,
    58. 0x3E,0x07,0x00,0x00,0x80,0xF0,0xFF,0xFF,0xFF,0x87,0x03,0x03,0x01,0x01,0x01,0x00,
    59. 0x00,0x00,0x00,0x38,0x18,0x1C,0x1F,0x0F,0x0F,0x0F,0x0F,0x0F,0x1F,0xFE,0xF8,0xF8,
    60. 0xF0,0xE0,0xE1,0xE1,0xC3,0xC7,0xC7,0xC7,0xC7,0xC7,0xC7,0xC3,0xC3,0xE1,0xE0,0xF0,
    61. 0xF8,0xF8,0xFC,0xFF,0x0F,0x07,0x07,0x07,0x07,0x07,0x0F,0x0E,0x0C,0x0C,0x00,0x00,
    62. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x1F,0x0F,0x07,
    63. 0x03,0x03,0x01,0x01,0x01,0x03,0x0F,0x7F,0xFF,0x7F,0x0F,0x03,0x01,0x01,0x01,0x01,
    64. 0x03,0x07,0x07,0x1F,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

    65. };

    66. unsigned char tu2[]={
    67. 0x00,0x00,0x80,0xC0,0xE0,0xF0,0x78,0xB8,0xBC,0xDC,0xDE,0xFF,0xEF,0xEF,0xEE,0xFE,
    68. 0xDE,0xDC,0xBC,0xB8,0x78,0xF0,0xE0,0xE0,0xE0,0xE0,0xF0,0x78,0xB8,0xBC,0xDC,0xDE,
    69. 0xEE,0xFF,0xEF,0xEF,0xFE,0xDE,0xDC,0xFC,0xB8,0x78,0xF0,0xE0,0xC0,0x80,0x00,0x00,
    70. 0xF0,0xFE,0xFF,0x0F,0xFB,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
    71. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFC,0xFB,0xFB,0xFD,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,
    72. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFB,0x9F,0xFF,0xFE,0xF0,
    73. 0x1F,0xFF,0xFF,0xC5,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
    74. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
    75. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0xE2,0xFF,0xFF,0x1F,
    76. 0x00,0x00,0x07,0x0F,0x3F,0x7C,0xF3,0xEF,0xDF,0xBF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
    77. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
    78. 0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xBF,0xDF,0xEF,0xF3,0x7C,0x3F,0x0F,0x03,0x00,0x00,
    79. 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x3E,0x7D,0xFB,0xF7,0xEF,
    80. 0xDF,0xBF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xBF,0xDF,
    81. 0xEF,0xF7,0xFB,0x7D,0x3E,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
    82. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,
    83. 0x03,0x07,0x0F,0x0E,0x1D,0x3B,0x77,0xEF,0xEF,0x77,0x3B,0x1D,0x0E,0x0F,0x07,0x03,
    84. 0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    85. };
    86. //中文字模
    87. const unsigned char chinese_character[][24]=
    88. {
    89. //hua
    90. {0x88,0x84,0xBE,0x91,0x90,0xC8,0xBF,0xA8,0xA4,0xA2,0xB8,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00},
    91. //dong
    92. {0x02,0x22,0x32,0xAA,0x26,0xFB,0x22,0x62,0xA2,0x22,0x02,0x00,0x02,0x02,0x01,0x00,0x04,0x07,0x00,0x00,0x00,0x01,0x02,0x00},
    93. //li
    94. {0x12,0x12,0xFE,0x12,0x3F,0xA5,0xA5,0xFF,0xA5,0xA5,0x3F,0x00,0x02,0x02,0x01,0x05,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x00},
    95. //gong
    96. {0x00,0x02,0x02,0x02,0x02,0xFE,0x02,0x02,0x03,0x02,0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x04,0x04,0x00},
    97. //da
    98. {0x08,0x08,0x08,0x08,0xC8,0x3F,0xC8,0x08,0x08,0x0C,0x08,0x00,0x04,0x04,0x02,0x01,0x00,0x00,0x00,0x01,0x02,0x04,0x04,0x00},
    99. //xue
    100. {0x9C,0x84,0x95,0x96,0x95,0xD6,0xB4,0x94,0x87,0x94,0x8C,0x00,0x00,0x00,0x00,0x04,0x04,0x07,0x00,0x00,0x00,0x00,0x00,0x00},
    101. //long
    102. {0x04,0x04,0x04,0xC4,0x3F,0x04,0xFC,0x45,0x26,0x14,0x04,0x00,0x04,0x02,0x01,0x02,0x02,0x01,0x07,0x04,0x04,0x04,0x07,0x00},
    103. //fei
    104. {0x01,0x01,0x01,0x01,0x01,0x7F,0x90,0x18,0x24,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x04,0x07,0x00},

    105. };


    106. //6X8字库
    107. unsigned char font6x8[][6] =
    108. {
    109. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },// sp
    110. { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 },// !
    111. { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 },// "
    112. { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 },// #
    113. { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 },// $
    114. { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 },// %
    115. { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 },// &
    116. { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 },// '
    117. { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 },// (
    118. { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 },// )
    119. { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 },// *
    120. { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 },// +
    121. { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 },// ,
    122. { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 },// -
    123. { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 },// .
    124. { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 },// /
    125. { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E },// 0
    126. { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 },// 1
    127. { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 },// 2
    128. { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 },// 3
    129. { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 },// 4
    130. { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 },// 5
    131. { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 },// 6
    132. { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 },// 7
    133. { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 },// 8
    134. { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E },// 9
    135. { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 },// :
    136. { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 },// ;
    137. { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 },// <
    138. { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 },// =
    139. { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 },// >
    140. { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 },// ?
    141. { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E },// @
    142. { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C },// A
    143. { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 },// B
    144. { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 },// C
    145. { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C },// D
    146. { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 },// E
    147. { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 },// F
    148. { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A },// G
    149. { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F },// H
    150. { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 },// I
    151. { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 },// J
    152. { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 },// K
    153. { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 },// L
    154. { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F },// M
    155. { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F },// N
    156. { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E },// O
    157. { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 },// P
    158. { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E },// Q
    159. { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 },// R
    160. { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 },// S
    161. { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 },// T
    162. { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F },// U
    163. { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F },// V
    164. { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F },// W
    165. { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 },// X
    166. { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 },// Y
    167. { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 },// Z
    168. { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 },// [
    169. { 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 },// 55
    170. { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 },// ]
    171. { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 },// ^
    172. { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 },// _
    173. { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 },// '
    174. { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 },// a
    175. { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 },// b
    176. { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 },// c
    177. { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F },// d
    178. { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 },// e
    179. { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 },// f
    180. { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C },// g
    181. { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 },// h
    182. { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 },// i
    183. { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 },// j
    184. { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 },// k
    185. { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 },// l
    186. { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 },// m
    187. { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 },// n
    188. { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 },// o
    189. { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 },// p
    190. { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC },// q
    191. { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 },// r
    192. { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 },// s
    193. { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 },// t
    194. { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C },// u
    195. { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C },// v
    196. { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C },// w
    197. { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 },// x
    198. { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C },// y
    199. { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 },// z
    200. { 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 }// horiz lines
    201. };

    202. /*
    203. @brief:set and clear the control bits of 5110 lcd.
    204. @usage:you can use funtion set_XXX() to set a bit and use funtion clear_XXX() to clear a bit.
    205. */
    206. void set_SCE(void)
    207. {
    208. GPIO_WriteBit(GPIOB, GPIO_Pin_5, Bit_SET);
    209. }
    210. void clear_SCE(void)
    211. {
    212. GPIO_WriteBit(GPIOB, GPIO_Pin_5, Bit_RESET);
    213. }
    214. void set_RES(void)
    215. {
    216. GPIO_WriteBit(GPIOB, GPIO_Pin_6, Bit_SET);
    217. }
    218. void clear_RES(void)
    219. {
    220. GPIO_WriteBit(GPIOB, GPIO_Pin_6, Bit_RESET);
    221. }
    222. void set_DC(void)
    223. {
    224. GPIO_WriteBit(GPIOB, GPIO_Pin_7, Bit_SET);
    225. }
    226. void clear_DC(void)
    227. {
    228. GPIO_WriteBit(GPIOB, GPIO_Pin_7, Bit_RESET);
    229. }
    230. void set_SDIN(void)
    231. {
    232. GPIO_WriteBit(GPIOB, GPIO_Pin_8, Bit_SET);
    233. }
    234. void clear_SDIN(void)
    235. {
    236.          GPIO_WriteBit(GPIOB, GPIO_Pin_8, Bit_RESET);
    237. }
    238. void set_SCLK(void)
    239. {
    240. GPIO_WriteBit(GPIOB, GPIO_Pin_9, Bit_SET);
    241. }
    242. void clear_SCLK(void)
    243. {
    244. GPIO_WriteBit(GPIOB, GPIO_Pin_9, Bit_RESET);
    245. }

    246. /************************************************
    247. *函数名: GPIO_Configuration      
    248. *参  数:无
    249. *功  能: 配置GPIO   
    250. *返回值:无                                    
    251. *备  注:无         
    252. *日  期:2013/07/23        
    253. *************************************************/
    254. GPIO_InitTypeDef GPIO_InitStructure;
    255. void GPIO_Configuration(void)
    256. {
    257.    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);         
    258.    GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
    259.    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    260.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    261.    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    262.    GPIO_Init(GPIOB, &GPIO_InitStructure);
    263. }
    264. /************************************************
    265. *函数名: LCD_write_byte       *
    266. *参  数:data:写入的数据          *
    267. *        cmd: 1-数据/0-命令     *
    268. *功  能: 向5110LCD写入数据      *
    269. *返回值:无                                     *
    270. *日  期:2013/07/23        *
    271. *************************************************/
    272. void LCD_write_byte(unsigned char data,unsigned char cmd)
    273. {
    274.           unsigned char i;   
    275.     clear_SCE();  
    276.           if(cmd)
    277.                   set_DC();
    278.           else
    279.                   clear_DC();         
    280.           for(i=0;i<8;i++)
    281.          {
    282.                    if(data&0x80) //如果一个字节的最高位是1
    283.                           set_SDIN(); //则设置SDIN=1
    284.                    else
    285.                            clear_SDIN();//否则设置SDIN=0;SDIN是即将写入数据DDRAM的值
    286.                           data = data<<1; //将传送的一个字节数据的每一位进行左移一位,等待下一次传输
    287.                           clear_SCLK();   //SDIN在SCLK的上升沿写入DDRAM
    288.                           set_SCLK();     //
    289.                           clear_SCLK();  //
    290.          }   
    291. }
    292. /************************************************
    293. *函数名: LCD_init           *
    294. *参  数:无                       *
    295. *功  能: 初始化LCD              *
    296. *返回值:无                                     *         *
    297. *日  期:2013/07/23        *
    298. *************************************************/
    299. void LCD_init(void)
    300. {
    301.         set_SCE();
    302.         set_RES();
    303.         delay_us(200);
    304.         clear_RES();   
    305.         delay_ms(20);
    306.         set_RES();  
    307.          delay_us(200);
    308.          LCD_write_byte(0x21,0);//LCD功能设置:芯片活动,水平寻址,使用扩展指令
    309.          LCD_write_byte(0xd0,0);//设置VOP值,室温下的编程范围为3.00-10.68
    310. //Vlcd=3.06+(VOP)*0.06,本例VOP为0B01010000为十进制的80,Vlcd=7.86V
    311.          LCD_write_byte(0x20,0);//LCD功能设置:芯片活动,水平寻址,使用基本指令
    312.          LCD_write_byte(0x0c,0);//设定显示配置:普通模式
    313.          set_SCE();//SCE为高电平时串行口被初始化,SCLK时钟不起作用,串行接口不消耗电力,所以最后都将SCE置高电平
    314. }
    315. /************************************************
    316. *函数名: LCD_set_XY           *
    317. *参  数:X:列                     *
    318. *        Y:行                            *
    319. *功  能: 选择写入液晶位置      *
    320. *返回值:无                                     *
    321. *日  期:2013/07/23        *
    322. *************************************************/
    323. void LCD_set_XY(unsigned char X, unsigned char Y)
    324. {
    325.          LCD_write_byte(0x40 | Y, 0);// 行
    326.          LCD_write_byte(0x80 | X, 0);// 列
    327.          set_SCE();
    328. }
    329. /************************************************
    330. *函数名: LCD_clear           *
    331. *参  数:无                            *
    332. *功  能: 清屏                    *
    333. *返回值:无                                     *
    334. *备  注:无          *
    335. *日  期:2013/07/23        *
    336. *************************************************/
    337. void LCD_clear(void)
    338. {
    339.           unsigned char t;
    340.           unsigned char k;
    341.          LCD_set_XY(0,0);
    342.           for(t=0;t<6;t++)
    343.          {
    344.                    for(k=0;k<84;k++)
    345.                   {
    346.                            LCD_write_byte(0x00,1);        
    347.                   }
    348.         }
    349.          set_SCE();
    350. }
    351. /************************************************
    352. *函数名: LCD_write_char       *
    353. *参  数:c:需写入的字符                *
    354. *功  能: 写入字符命令                  *
    355. *返回值:无                                     *
    356. *日  期:2013/07/23        *
    357. *************************************************/
    358. void LCD_write_char(unsigned char c)
    359. {
    360.           unsigned char c_line;
    361.                 c-=32;
    362.                 for (c_line=0; c_line<6; c_line++)
    363.                 LCD_write_byte(font6x8[c][c_line], 1);
    364. }
    365. /************************************************
    366. *函数名: LCD_write_String      *
    367. *参  数:X:设置写入字符串列位置           *
    368. *   Y:设置写入字符串行位置     *
    369. *   *s:写入字符串首地址                    *
    370. *功  能: LCD显示字符串                 *
    371. *返回值:无                                     *
    372. *日  期:2013/07/23       *
    373. *************************************************/
    374. void LCD_write_String(unsigned char X,unsigned char Y,char *s)
    375. {
    376.          LCD_set_XY(X,Y);
    377.           while (*s)
    378.         {
    379.                   LCD_write_char(*s);
    380.                   s++;
    381.          }
    382. }
    383. /************************************************
    384. *函数名: LCD_write_chinese   *
    385. *参  数:X:设置写入汉字列位置               *
    386. *   Y:设置写入汉字行位置     *
    387. *功  能: LCD显示汉字                 *
    388. *返回值:无                                     *
    389. *日  期:2013/07/23        *
    390. *************************************************/


    391. void LCD_write_chinese(unsigned char X, unsigned char Y,char n)
    392. {
    393.           int i;
    394.                 LCD_set_XY(X,Y);
    395.           for(i = 0;i < 12; i++)
    396.                 {
    397.                         LCD_write_byte(chinese_character[n][i],1);
    398.                 }
    399.                         LCD_set_XY(X,Y+1);
    400.           for(i = 12; i < 24; i++)
    401.                 {
    402.                         LCD_write_byte(chinese_character[n][i],1);
    403.                 }
    404. }

    405. /************************************************
    406. *函数名: LCD_write_Picture   *
    407. *功  能: 写整屏的图片                 *
    408. *返回值:无                                     *
    409. *日  期:2013/07/23        *
    410. *************************************************/
    411. void LCD_write_Picture(unsigned char *c)
    412. {
    413.         unsigned i,j;
    414.         for(i=0;i<6;i++)
    415.         {
    416.                 LCD_set_XY(0,i);
    417.                 for(j=0;j<84;j++)
    418.                 {
    419.                                 LCD_write_byte(c[i*84+j],1);
    420.                 }
    421.         }
    422. }
    复制代码
    1. delay.c
    2. #include "delay.h"

    3. __IO u16 ntime;                                                                    

    4. void delay_ms(u16 nms)
    5. {                                    
    6.         ntime=nms;
    7.         SysTick_Config(168000);//1ms产生一次中断
    8.         while(ntime);
    9.         SysTick->CTRL=0x00;                                      
    10. }   
    11.                                                                                        
    12. void delay_us(u32 nus)
    13. {               
    14.         ntime=nus;
    15.         SysTick_Config(168);//1us产生一次中断
    16.         while(ntime);
    17.         SysTick->CTRL=0x00;
    18. }

    19. void Delay(u32 count)
    20. {
    21.         while(count--);
    22. }
    复制代码
    1. /**
    2.   ************************************************************************************
    3.   * @file    LCD5110.h
    4.   * @author  Allen
    5.   * @version V1.0.0
    6.   * @date    22-July-2012,21:30 IN ECUST
    7.   * @brief   This file contains all the functions prototypes for the 5110 LCD driver
    8.   ************************************************************************************
    9.   @NOTE:
    10. *THIS FILE IS JUST FOR STUDY,CREATED BY LONGFEI WHICH HAS SOME REFERENCE FROM NETWORK
    11. */

    12. /* Define to prevent recursive inclusion -------------------------------------*/
    13. #ifndef __LCD5110_H
    14. #define __LCD5110_H
    15. extern unsigned char tu[];
    16. extern unsigned char tu1[];
    17. extern unsigned char tu2[];
    18. /* Exported functions --------------------------------------------------------*/
    19. /* Funtion used to Configuration GPIO ----------------------------------------*/
    20. void GPIO_Configuration(void);
    21. /* Funtion used to SET SCE----------------------------------------------------*/
    22. void set_SCE(void);
    23. /* Funtion used to CLEAR SCE--------------------------------------------------*/
    24. void clear_SCE(void);
    25. /* Funtion used to SET RES----------------------------------------------------*/
    26. void set_RES(void);
    27. /* Funtion used toCLEAR SCE--------------------------------------------------*/
    28. void clear_RES(void);
    29. /* Funtion used toSET DC-----------------------------------------------------*/
    30. void set_DC(void);
    31. /* Funtion used toCLEAR DC---------------------------------------------------*/
    32. void clear_DC(void);
    33. /* LCD_write_byte funtion---------------------------------------------------*/
    34. void LCD_write_byte(unsigned char data,unsigned char cmd);
    35. /* LCD_Init function--------------------------------------------------------*/
    36. void LCD_init(void);
    37. /* LCD_set_XY---------------------------------------------------------------*/
    38. void LCD_set_XY(unsigned char X,unsigned char Y);
    39. /* LCD_clear function-------------------------------------------------------*/
    40. void LCD_clear(void);
    41. /* LCD_write_char function--------------------------------------------------*/
    42. void LCD_write_char(unsigned char c);
    43. /* LCD_write_string function-----------------------------------------------*/
    44. void LCD_write_String(unsigned char X,unsigned char Y,char *s);
    45. /* LCD_write_chinese function------------------------------------------ ---*/
    46. void LCD_write_chinese(unsigned char X,unsigned char Y,char n);
    47. /* LCD_write_Picture function------------------------------------------ ---*/
    48. void LCD_write_Picture(unsigned char *c);
    49. #endif
    复制代码
    1. <div class="blockcode"><blockquote>//delay.h
    2. #ifndef __DELAY_H
    3. #define __DELAY_H

    4. #include "stm32f4xx_conf.h"

    5. void delay_ms(u16 nms);
    6. void delay_us(u32 nus);
    7. void Delay(u32 count);

    8. #endif
    复制代码
分享到:
回复

使用道具 举报

回答|共 5 个

倒序浏览

沙发

lungfei

发表于 2013-8-15 10:55:16 | 只看该作者

更多信息请参阅:http://write.blog.csdn.net/postlist
板凳

xiaopaohu123

发表于 2013-8-15 11:06:34 | 只看该作者

帮顶,嘿嘿
地板

xinlim

发表于 2013-8-15 23:49:51 | 只看该作者

不错,帮顶了
5#

abb200628

发表于 2013-8-21 19:12:48 | 只看该作者

调用延时函数就死循环,求解
6#

KING_LIGHT

发表于 2014-6-30 12:16:38 | 只看该作者

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条