LaunchPad实验四——12864并行显示

2019-07-25 16:32发布

本帖最后由 nwx8899 于 2012-7-21 14:30 编辑

1 液晶介绍
12864.jpg
2 电路连接
12864-2.jpg
3 取字模
12864-4.jpg
3 project

4 效果预览
IMG_20120627_161344.jpg


IMG_20120627_163020.jpg

5 源代码


复制代码
  1. /***********************************************
  2. **** LAUNCH PAD 学习之LCD 12864***
  3. **** MCU: MSP430 ***
  4. **** 作者: nwx***
  5. **** ***
  6. **** ***
  7. **** 实验现象:LCD显示 LOG ***
  8. **** *** 2012.6.27
  9. ****P1.0~P1.7 数据口 P2.0 P2.1 P2.2 en rs Psb***
  10. ***********************************************/
  11. #include <msp430g2452.h>
  12. #define uchar unsigned char
  13. #define uint unsigned int
  14. #define BUTTON BIT3 //P1.3为板上按键S2


  15. const uchar table[]="欢迎参加TI在线培训!";
  16. const uchar table1[]="LaunchPad ";
  17. const uchar table2[]=" 点火开始!";
  18. uchar num;
  19. void delay_1ms(void)
  20. {
  21. uint i;
  22. for (i=0;i<1140;i++);
  23. }

  24. /*-- 调入了一幅图像:C:UsersAdministratorDesktoplaunchpad.bmp --*/
  25. /*-- 宽度x高度=128x64 --*/
  26. const uchar image[]=
  27. {
  28. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  29. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x03,0xFF,0xFE,0x7F,0xFF,
  33. 0x01,0xF8,0x00,0x00,0x00,0x00,0x01,0xFC,0x00,0x3F,0xFF,0xE3,0x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xC7,0xF8,0x7F,0xFF,0xE3,0x1E,0x00,0x1C,0x78,0x1F,0x0F,0x0C,
  60. 0x7F,0xFF,0xC0,0x3F,0xC7,0xF8,0x3F,0xFF,0xC3,0x8F,0x00,0x1F,0xF8,0x1F,0x0E,0x0F,
  61. 0x7F,0xFF,0xC0,0x3F,0xC7,0xF8,0x1F,0xFF,0x87,0x8F,0xFF,0x8F,0xF0,0x3E,0x1C,0x0F,
  62. 0x7F,0xFF,0xC0,0x3F,0xC7,0xF8,0x0F,0xFF,0x03,0x87,0xFF,0xC7,0xE0,0x3C,0x18,0x0F,
  63. 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFC,0x00,0x01,0xFF,0xC0,0x00,0x00,0x00,0x00,
  64. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  65. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  66. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  67. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  70. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  75. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  76. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  77. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  78. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  79. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  80. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  81. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  82. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  83. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  84. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  85. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  86. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  87. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  88. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  89. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  90. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  91. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  92. }; //第一幅图像数据
  93. const uchar image1[]=
  94. {
  95. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  97. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  98. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  99. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  100. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  101. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  102. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xE0,
  103. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFC,
  104. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0x87,0xFE,
  105. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xF0,0x00,0x0E,
  106. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x80,0x1F,0xFF,0xF0,0x00,0x06,
  107. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE1,0xF0,0xFF,0xFF,0xF0,0x00,0x02,
  108. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x3F,0xFF,0xFF,0xF8,0x00,0x02,
  109. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xF0,0x00,0x1F,0xEF,0xFF,0xF8,0x00,0x06,
  110. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x7F,0x07,0xFF,0xFC,0x00,0x0E,
  111. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x01,0xF8,0x03,0xFF,0xFC,0x00,0x0E,
  112. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF8,0x03,0xE0,0x03,0xFF,0xFE,0x00,0x3C,
  113. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x1C,0x0F,0x80,0x01,0xFF,0xFE,0x00,0x78,
  114. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x3E,0x00,0x01,0xFF,0xFE,0x00,0xF0,
  115. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x7C,0x00,0x00,0xFF,0xFE,0x03,0xE0,
  116. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xF0,0x00,0x00,0xFF,0xFE,0x07,0xC0,
  117. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x03,0xC0,0xFF,0xFE,0x1F,0x00,
  118. 0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xC0,0x03,0x80,0x0F,0xE0,0x7F,0xFF,0x7E,0x00,
  119. 0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xC0,0x03,0x00,0xFF,0xE0,0x7F,0xFF,0xF8,0x00,
  120. 0x00,0x00,0x00,0x00,0x03,0xFE,0x00,0x00,0x01,0x03,0xFF,0xC0,0x7F,0xFF,0xE0,0x00,
  121. 0x00,0x00,0x00,0x00,0x1F,0xC0,0x00,0x00,0x41,0x9F,0xFC,0x00,0x7F,0xFF,0x80,0x00,
  122. 0x00,0x00,0x00,0x00,0x7C,0x00,0x00,0x1F,0xC1,0xFF,0xE0,0x00,0x7F,0xFF,0x00,0x00,
  123. 0x00,0x00,0x00,0x03,0xE0,0x00,0x03,0xFE,0x07,0xFE,0x00,0x00,0x7F,0xF8,0x00,0x00,
  124. 0x00,0x00,0x00,0x0F,0x00,0x00,0xFF,0xC0,0x3F,0xF0,0x00,0x00,0x7F,0xE0,0x00,0x00,
  125. 0x00,0x00,0x00,0x3C,0x00,0x07,0xF8,0x00,0xFF,0xC0,0x00,0x00,0xFF,0x80,0x00,0x00,
  126. 0x00,0x00,0x00,0xF0,0x00,0x7E,0x00,0x01,0xF0,0xC0,0x00,0x1F,0xFC,0x00,0x00,0x00,
  127. 0x00,0x00,0x03,0x80,0x03,0xF0,0x00,0x01,0x80,0x40,0x03,0xFF,0xE0,0x00,0x00,0x00,
  128. 0x00,0x00,0x0E,0x00,0x1F,0x80,0x00,0x00,0x00,0x7F,0xFF,0xFE,0x00,0x00,0x00,0x00,
  129. 0x00,0x00,0x18,0x00,0x7C,0x00,0x00,0x00,0x00,0x7F,0xFF,0xF0,0x00,0x00,0x00,0x00,
  130. 0x00,0x00,0x70,0x01,0xE0,0x00,0x00,0x0C,0x00,0x3F,0xF8,0x60,0x00,0x00,0x00,0x00,
  131. 0x00,0x01,0xE0,0x07,0x80,0x00,0x00,0x38,0x00,0x30,0x00,0xC0,0x00,0x00,0x00,0x00,
  132. 0x00,0x03,0x80,0x3C,0x00,0x00,0x00,0xF0,0x38,0x30,0x01,0xC0,0x00,0x00,0x00,0x00,
  133. 0x00,0x0E,0x00,0x70,0x00,0x00,0x01,0xC0,0x70,0x30,0x03,0x80,0x00,0x00,0x00,0x00,
  134. 0x00,0x1C,0x01,0xC0,0x00,0x00,0x07,0x00,0xE0,0x30,0x07,0x00,0x00,0x00,0x00,0x00,
  135. 0x00,0x70,0x07,0x00,0x00,0x00,0x1C,0x01,0x80,0x60,0x1E,0x00,0x00,0x00,0x00,0x00,
  136. 0x00,0xE0,0x0C,0x00,0x00,0x00,0xF8,0x03,0x00,0xE0,0x78,0x00,0x00,0x00,0x00,0x00,
  137. 0x03,0x80,0x38,0x00,0x00,0x01,0xC0,0x0E,0x01,0xC1,0xE0,0x00,0x00,0x00,0x00,0x00,
  138. 0x07,0x00,0xF0,0x00,0x00,0x0F,0x00,0x1C,0x07,0x0F,0x80,0x00,0x00,0x00,0x00,0x00,
  139. 0x0E,0x01,0xC0,0x00,0x00,0xFC,0x00,0x70,0x1F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,
  140. 0x18,0x01,0x00,0x00,0x0F,0xE0,0x01,0xE0,0x3F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
  141. 0x70,0x00,0x00,0x01,0xFE,0x00,0x03,0x80,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  142. 0xE0,0x00,0x00,0x03,0xE0,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  143. 0xC0,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  144. 0x00,0x00,0x18,0x00,0x00,0x01,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  145. 0x00,0x1F,0xF8,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  146. 0xFF,0xFF,0xF0,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  147. 0x00,0x00,0xE0,0x00,0x01,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  148. 0x00,0x00,0xC0,0x00,0x7F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  149. 0x00,0x01,0x80,0x1F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  150. 0x00,0x01,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  151. 0x00,0x03,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  152. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  153. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  154. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  155. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  156. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  157. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  158. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  159. }; //第二幅图像数据

  160. /*****************************************
  161. *
  162. * N ms延时函数
  163. *
  164. ****************************************/
  165. void delay_nms(uint n)
  166. {
  167. uint i=0;
  168. for (i=0;i<n;i++)
  169. delay_1ms();
  170. }


  171. void write_com(uint com)
  172. {
  173. //lcdrs = 0;
  174. P2OUT&= 0xfd; //P2.1 RS =0
  175. P1OUT = com;
  176. delay_nms(5);
  177. //lcden = 1;
  178. P2OUT|= 0x01;
  179. delay_nms(5);
  180. P2OUT&= 0xfe;
  181. }

  182. void write_dat(uint dat)
  183. {
  184. //lcdrs = 1;
  185. P2OUT |= 0x02;
  186. P1OUT = dat;
  187. delay_nms(5);
  188. //lcden=1;
  189. P2OUT|= 0x01;
  190. delay_nms(5);
  191. // lcden=0;
  192. P2OUT&= 0xfe;

  193. }
  194. void disp_str(uchar addr,const uchar *pt,uchar num)
  195. {
  196. uchar i;
  197. write_com(addr);
  198. for(i=0;i<(num*2);i++)
  199. write_dat(*(pt++));
  200. }
  201. void init()
  202. {
  203. //PSB=1;//并口模式
  204. P2OUT |= BIT2;
  205. delay_nms(15);
  206. //EN=0;
  207. P2OUT&= 0xfe;
  208. delay_nms(5);
  209. write_com(0x30);
  210. delay_nms(1);
  211. write_com(0x08);//清屏
  212. delay_nms(1);
  213. write_com(0x0c);//开显示,关光标
  214. delay_nms(1);
  215. write_com(0x01);
  216. delay_nms(1);
  217. write_com(0x06);//第一行显示位置
  218. delay_nms(1);
  219. }

  220. void lcd12864_image(const uchar *p)
  221. {
  222. int x,y;
  223. write_com(0x34); //扩展指令集动作,绘图显示OFF
  224. for (y=0;y<32;y++) //送上半屏显示数据
  225. {
  226. write_com(0x80|y); //送显示Y坐标0x80-0x9f
  227. write_com(0x80); //送显示X坐标0x80
  228. for (x=0;x<16;x++)
  229. {
  230. write_dat(*p);
  231. p++;
  232. }
  233. }

  234. for (y=0;y<32;y++) //送下半屏显示数据
  235. {
  236. write_com(0x80|y); //送显示Y坐标0x80-0x9f
  237. write_com(0x88); //送显示X坐标0x88
  238. for (x=0;x<16;x++)
  239. {
  240. write_dat(*p);
  241. p++;
  242. }
  243. }
  244. write_com(0x36); //扩展指令集动作,绘图显示ON
  245. }
  246. void displayfirst()//显示第一个界面
  247. {
  248. write_com(0x01); //清除显示(清零DDRAM)


  249. disp_str(0x98,table,18);
  250. lcd12864_image(image);//送图像显示数据
  251. delay_nms(5000);

  252. }
  253. void displaysecond()//显示第二个界面
  254. {
  255. write_com(0x01); //清除显示(清零DDRAM)

  256. disp_str(0x80,table1,18);
  257. disp_str(0x98,table2,18);
  258. lcd12864_image(image1);//送图像显示数据
  259. delay_nms(5000);
  260. }

  261. void main(void)
  262. {
  263. WDTCTL = WDTPW + WDTHOLD; // Stop WDT
  264. P1DIR |= 0xff; // P1.2 output
  265. P2DIR |= 0xff;
  266. init();
  267. while(1)
  268. {
  269. if(BUTTON==0x00)

  270. {displayfirst();}
  271. else
  272. {displaysecond();}
  273. }

  274. }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。