查看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的代码如下,因为有注释,解释省了:
- DigitalOut sdat(D13);
- DigitalOut sclk(D12);
- DigitalOut sreg(D11);
- DigitalOut sres(D10);
- //6903 102X64LCD
- const unsigned char asc2[][8]={//8x6 Dots 32-126[0-94]
- {0x00,0x3E,0x45,0x49,0x51,0x3E},//0
- {0x00,0x00,0x21,0x7F,0x01,0x00},//1
- {0x00,0x31,0x43,0x45,0x49,0x31},//2
- {0x00,0x22,0x49,0x49,0x49,0x36},//3
- {0x00,0x04,0x0C,0x14,0x7F,0x04},//4
- {0x00,0x72,0x51,0x51,0x51,0x4E},//5-5
- {0x00,0x3E,0x49,0x49,0x49,0x06},//6
- {0x00,0x40,0x43,0x4C,0x50,0x60},//7
- {0x00,0x36,0x49,0x49,0x49,0x36},//8
- {0x00,0x30,0x48,0x48,0x48,0x3F},//9
- {0x00,0x1F,0x24,0x64,0x24,0x1F},//A-10
- {0x00,0x41,0x7F,0x49,0x49,0x36},//B
- {0x00,0x3E,0x41,0x41,0x41,0x22},//C
- {0x00,0x41,0x7F,0x41,0x41,0x3E},//D
- {0x00,0x41,0x7F,0x49,0x49,0x63},//E
- {0x00,0x41,0x7F,0x49,0x5C,0x60},//F-15
- {0x00,0x3E,0x41,0x45,0x47,0x24},//G
- {0x41,0x7F,0x08,0x08,0x08,0x7F},//H
- {0x00,0x00,0x41,0x7F,0x41,0x00},//I
- {0x00,0x42,0x41,0x7F,0x40,0x40},//J
- {0x00,0x41,0x7F,0x59,0x24,0x43},//K-20
- {0x00,0x40,0x7F,0x41,0x01,0x03},//L
- {0x00,0x7F,0x20,0x1E,0x20,0x7F},//M
- {0x00,0x7F,0x30,0x18,0x06,0x7F},//N
- {0x00,0x3E,0x41,0x41,0x41,0x3E},//O
- {0x00,0x41,0x7F,0x49,0x48,0x30},//P-25
- {0x00,0x3E,0x41,0x47,0x42,0x3D},//Q
- {0x00,0x41,0x7F,0x49,0x4C,0x33},//R
- {0x00,0x32,0x49,0x49,0x49,0x26},//S
- {0x00,0x60,0x41,0x7F,0x41,0x60},//T
- {0x00,0x7E,0x01,0x01,0x01,0x7E},//U-30
- {0x00,0x7C,0x02,0x01,0x02,0x7C},//V
- {0x00,0x7C,0x03,0x3C,0x03,0x7C},//W
- {0x00,0x43,0x24,0x18,0x24,0x43},//X
- {0x00,0x60,0x18,0x07,0x18,0x60},//Y
- {0x00,0x63,0x45,0x49,0x51,0x63},//Z-35
- {0x00,0x00,0x00,0x01,0x00,0x00},//.
- {0x00,0x14,0x14,0x14,0x14,0x14},//=
- {0x00,0x08,0x08,0x3E,0x08,0x08},//+
- {0x00,0x08,0x08,0x08,0x08,0x08},//-
- {0x00,0x00,0x00,0x24,0x00,0x00},//:-40
- };
- //Write Plus
- void wri(void){sclk=0;sclk=1;}
- //Write a byte to lcd dt=data,com=reg/data
- void b2l(unsigned char dt,unsigned char com){
- unsigned char i;
- if(com)sreg=1;else sreg=0;
- for(i=0;i<8;i++){
- if(dt&0x80){sdat=1;}else{sdat=0;};
- dt=dt<<1;
- wri();
- }
- }
- //Set lcd display X,Y
- void setXY(unsigned char X,unsigned char Y){
- b2l(0x40 | Y,0);//column
- b2l(0x80 | X,0);//row
- }
- //lcd Clear
- void lcdClear(void){
- unsigned char t,k;
- setXY(0,0);
- for(t=0;t<9;t++){for(k=0;k<102;k++){b2l(0x00,1);}}
- }
- //display a ASCII code
- void c2l(unsigned char x,unsigned char y,unsigned char c){
- unsigned char line;
- setXY(x*6,y);
- for (line=0;line<6;line++) b2l(asc2[c][line],1);
- }
- //LCD6903 Initial 102x64
- void lcdInit(void){
- wait(0.050);
- sres=0;
- wait(0.050);
- sres=1;
- wait(0.050);
- b2l(0x25,0);//00100 PD=1dcOn|=0Dcoff V=0Up|=1Left H==1
- wait(0.0005);
- b2l(0x14,0);//Plus width L000~111=1/6-1/7-1/8-1/9//14=1/7
- wait(0.0005);
- b2l(0xB4,0);//SET VOP~8.96V
- wait(0.0005);
- b2l(0x20,0);//PD=0,H=0,V=0
- b2l(0x0C,0);//Set off
- wait(0.0005);
- }
- //Display ASCII Test
- void dispAsc(void){
- int i,j,k=0;
- for(i=0;i<8;i++){
- for(j=0;j<17;j++){
- c2l(j,i,k);
- if(k>39){k=0;}else{k++;}
- }
- }
- }
- //END Files//
- main.cpp主程序改为:
- #include "mbed.h"
- #include "6903.h"
- DigitalOut myled(PA_5);
- int main(){
- lcdInit();
- myled=1;
- while(true){
- dispAsc();
- myled=!myled;
- wait(1);
- lcdClear();
- }
- }
编译下载后的结果见照片22,硬件连接逻辑见照片23。由于设计的ASCII点阵为8X6的,因此一行可以显示17个ASCII码,一共可以显示8行,这样就足够了。
实际上此工程编译有5个警告,可以先不用理睬他。