[环境传感器] [X-NUCLEO-IKS01A2测评] 连接串口黑白LCD测试

zhjb1   2017-9-18 16:33 楼主
查看X-NUCLEO-IKS01A2开发板的逻辑连接示意图,见图21。X-NUCLEO-IKS01A2占用了Arduino的A2、A3;D4、D5、D6、D14、D15以及D2工8个模拟数字口,串口就采用模拟串
口的方式,连接1块102X65的黑白LCD,可以设定为显示8行每行10个以上ASCII码。计划采用没有被占用的D13~D10-4个数据口+2根电源线构成6线LCD。
为了整洁好看,我们将LCD模块的设置函数单独创建一个incs文件夹,将6903.h文档放在里面,并且在工程项目中声明此默认文件夹的路径,将此文件夹加入到工程项目中
。6903.h的代码如下,因为有注释,解释省了:
  1. DigitalOut sdat(D13);
  2. DigitalOut sclk(D12);
  3. DigitalOut sreg(D11);
  4. DigitalOut sres(D10);
  5. //6903 102X64LCD
  6. const unsigned char asc2[][8]={//8x6 Dots 32-126[0-94]
  7. {0x00,0x3E,0x45,0x49,0x51,0x3E},//0
  8. {0x00,0x00,0x21,0x7F,0x01,0x00},//1
  9. {0x00,0x31,0x43,0x45,0x49,0x31},//2
  10. {0x00,0x22,0x49,0x49,0x49,0x36},//3
  11. {0x00,0x04,0x0C,0x14,0x7F,0x04},//4
  12. {0x00,0x72,0x51,0x51,0x51,0x4E},//5-5
  13. {0x00,0x3E,0x49,0x49,0x49,0x06},//6
  14. {0x00,0x40,0x43,0x4C,0x50,0x60},//7
  15. {0x00,0x36,0x49,0x49,0x49,0x36},//8
  16. {0x00,0x30,0x48,0x48,0x48,0x3F},//9
  17. {0x00,0x1F,0x24,0x64,0x24,0x1F},//A-10
  18. {0x00,0x41,0x7F,0x49,0x49,0x36},//B
  19. {0x00,0x3E,0x41,0x41,0x41,0x22},//C
  20. {0x00,0x41,0x7F,0x41,0x41,0x3E},//D
  21. {0x00,0x41,0x7F,0x49,0x49,0x63},//E
  22. {0x00,0x41,0x7F,0x49,0x5C,0x60},//F-15
  23. {0x00,0x3E,0x41,0x45,0x47,0x24},//G
  24. {0x41,0x7F,0x08,0x08,0x08,0x7F},//H
  25. {0x00,0x00,0x41,0x7F,0x41,0x00},//I
  26. {0x00,0x42,0x41,0x7F,0x40,0x40},//J
  27. {0x00,0x41,0x7F,0x59,0x24,0x43},//K-20
  28. {0x00,0x40,0x7F,0x41,0x01,0x03},//L
  29. {0x00,0x7F,0x20,0x1E,0x20,0x7F},//M
  30. {0x00,0x7F,0x30,0x18,0x06,0x7F},//N
  31. {0x00,0x3E,0x41,0x41,0x41,0x3E},//O
  32. {0x00,0x41,0x7F,0x49,0x48,0x30},//P-25
  33. {0x00,0x3E,0x41,0x47,0x42,0x3D},//Q
  34. {0x00,0x41,0x7F,0x49,0x4C,0x33},//R
  35. {0x00,0x32,0x49,0x49,0x49,0x26},//S
  36. {0x00,0x60,0x41,0x7F,0x41,0x60},//T
  37. {0x00,0x7E,0x01,0x01,0x01,0x7E},//U-30
  38. {0x00,0x7C,0x02,0x01,0x02,0x7C},//V
  39. {0x00,0x7C,0x03,0x3C,0x03,0x7C},//W
  40. {0x00,0x43,0x24,0x18,0x24,0x43},//X
  41. {0x00,0x60,0x18,0x07,0x18,0x60},//Y
  42. {0x00,0x63,0x45,0x49,0x51,0x63},//Z-35
  43. {0x00,0x00,0x00,0x01,0x00,0x00},//.
  44. {0x00,0x14,0x14,0x14,0x14,0x14},//=
  45. {0x00,0x08,0x08,0x3E,0x08,0x08},//+
  46. {0x00,0x08,0x08,0x08,0x08,0x08},//-
  47. {0x00,0x00,0x00,0x24,0x00,0x00},//:-40
  48. };
  49. //Write Plus
  50. void wri(void){sclk=0;sclk=1;}
  51. //Write a byte to lcd dt=data,com=reg/data
  52. void b2l(unsigned char dt,unsigned char com){
  53. unsigned char i;
  54. if(com)sreg=1;else sreg=0;
  55. for(i=0;i<8;i++){
  56.   if(dt&0x80){sdat=1;}else{sdat=0;};
  57.   dt=dt<<1;
  58.   wri();
  59. }
  60. }
  61. //Set lcd display X,Y
  62. void setXY(unsigned char X,unsigned char Y){
  63. b2l(0x40 | Y,0);//column
  64. b2l(0x80 | X,0);//row
  65. }
  66. //lcd Clear
  67. void lcdClear(void){
  68. unsigned char t,k;
  69. setXY(0,0);
  70. for(t=0;t<9;t++){for(k=0;k<102;k++){b2l(0x00,1);}}
  71. }
  72. //display a ASCII code
  73. void c2l(unsigned char x,unsigned char y,unsigned char c){
  74. unsigned char line;
  75. setXY(x*6,y);   
  76. for (line=0;line<6;line++) b2l(asc2[c][line],1);
  77. }
  78. //LCD6903 Initial 102x64
  79. void lcdInit(void){
  80. wait(0.050);
  81. sres=0;
  82. wait(0.050);
  83. sres=1;
  84. wait(0.050);
  85. b2l(0x25,0);//00100 PD=1dcOn|=0Dcoff V=0Up|=1Left H==1
  86. wait(0.0005);
  87. b2l(0x14,0);//Plus width L000~111=1/6-1/7-1/8-1/9//14=1/7
  88. wait(0.0005);
  89. b2l(0xB4,0);//SET VOP~8.96V
  90. wait(0.0005);
  91. b2l(0x20,0);//PD=0,H=0,V=0
  92. b2l(0x0C,0);//Set off
  93. wait(0.0005);
  94. }
  95. //Display ASCII Test
  96. void dispAsc(void){
  97. int i,j,k=0;
  98. for(i=0;i<8;i++){
  99.   for(j=0;j<17;j++){
  100.    c2l(j,i,k);
  101.    if(k>39){k=0;}else{k++;}
  102.   }
  103. }
  104. }
  105. //END Files//
  106. main.cpp主程序改为:
  107. #include "mbed.h"
  108. #include "6903.h"
  109. DigitalOut myled(PA_5);
  110. int main(){
  111. lcdInit();
  112. myled=1;
  113. while(true){
  114.   dispAsc();
  115.   myled=!myled;
  116.   wait(1);
  117.   lcdClear();
  118. }
  119. }

编译下载后的结果见照片22,硬件连接逻辑见照片23。由于设计的ASCII点阵为8X6的,因此一行可以显示17个ASCII码,一共可以显示8行,这样就足够了。
实际上此工程编译有5个警告,可以先不用理睬他。
  • 21
  • 22
  • 23
永远好心情

回复评论 (3)

zhjb1,代码嵌入的形式给你改了下,建议后面的发帖涉及到代码嵌入时,使用编辑器中的代码嵌入功能,方便网友查看
点赞  2017-9-25 10:38
引用: nmg 发表于 2017-9-25 10:38
zhjb1,代码嵌入的形式给你改了下,建议后面的发帖涉及到代码嵌入时,使用编辑器中的代码嵌入功能,方便网 ...

好的,还不会用,下次试试
永远好心情
点赞  2017-9-25 15:32
玩板看这里: https://bbs.eeworld.com.cn/elecplay.html EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!
点赞  2017-10-30 14:21
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复