打印
[STM32F4]

【Nucleo-F413ZH创想】实验三 驱显128X64黑白LCD

[复制链接]
862|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zhjb1|  楼主 | 2017-1-16 17:35 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zhjb1 于 2017-2-16 14:39 编辑

实验三 驱显128X64黑白LCD
实验二已经完成GPIO的定义和测试,应该对GPIO的操作有了认识。实验三进行的就是GPIO的LCD驱显实验。驱显个中显示器本来就是最爱,因为当单片机有了自己的显示器是,所有的信息就可以不依赖像串口、LED显示表明了,直接从LCD上显示出测试的结果,况且几乎绝大多数的开发,有个显示屏也是必备的。
串口显示具有相对最少的IO开销,如果仅仅用于显示切只有1块,只需要4根信号线和2根电源线——6线就够了;如果需要片选也就多1根——Chip Select。
为了更好的开展以后的工作,我们将做一些规约,主要是针对main.cpp这个文档:
文档的最前部位Include区域,至少有#include "mbed.h"文档了,以后再增加接着罗列
接着是mbed的对象定义区,起名为
//Define Objects
以下罗列定义的对象名称
接着是变量定义区,其名为
//Define Variable
以下罗列自定义的变量
以后是自己定义的各个函数模块
最后是main主函数

本实验需要做的工作不多,所有代码直接给出,为了遵循模块化的编程方法,我们做一些变通:
首先创建1个文件夹,命名为:incs;并且在项目选项中将此文件夹增加进项目中,将里面的所有文件追加到项目中。本例中,此文件夹中只有1个文件:12864.h,这是一款用的较多的黑白[黄绿、蓝白、...]LCD显示屏,因此具有一定的代表性。此文件的内容如下:
//Define ISP LCD GPIO
DigitalOut dat(PC_8);
DigitalOut clk(PC_9);
DigitalOut reg(PC_10);
DigitalOut res(PC_11);

//128x64 LCD models
const unsigned char asc2[][8]={//8x6 Dots 32 to 127 + caratteri alfa_omega a seguire
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//space
{0x00,0x1c,0x22,0x24,0x18,0x16,0x00,0x00},//!-1=32
{0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},//"
{0x00,0x02,0x04,0x78,0x10,0x0c,0x02,0x00},//#
{0x00,0x7e,0x15,0x15,0x15,0x0a,0x00,0x00},//$
{0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},//%
{0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},//&
{0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},//'
{0x00,0x00,0x1C,0x22,0x41,0x00,0x00,0x00},//(
{0x00,0x00,0x41,0x22,0x1C,0x00,0x00,0x00},//)
{0x00,0x14,0x08,0x3E,0x08,0x14,0x00,0x00},//  /-10=42
{0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},//+
{0x00,0x00,0x50,0x30,0x00,0x00,0x00,0x00},//;
{0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},//-
{0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00},//.
{0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},///
{0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},//0
{0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},//1
{0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00},//2
{0x00,0x21,0x41,0x45,0x4B,0x31,0x00,0x00},//3
{0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},//4-20
{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},//5
{0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},//6
{0x00,0x01,0x01,0x79,0x05,0x03,0x00,0x00},//7
{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},//8
{0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},//9
{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},//:
{0x00,0x00,0x56,0x36,0x00,0x00,0x00,0x00},//;
{0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},//<
{0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},//=
{0x00,0x00,0x41,0x22,0x14,0x08,0x00,0x00},//>-30
{0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},//?
{0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},//@
{0x00,0x7E,0x11,0x11,0x11,0x7E,0x00,0x00},//A
{0x00,0x41,0x7F,0x49,0x49,0x36,0x00,0x00},//B
{0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},//C
{0x00,0x41,0x7F,0x41,0x41,0x3E,0x00,0x00},//D
{0x00,0x7F,0x49,0x49,0x49,0x49,0x00,0x00},//E
{0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},//F
{0x00,0x3E,0x41,0x41,0x49,0x7A,0x00,0x00},//G
{0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},//H-40
{0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00},//I
{0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},//J
{0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},//K
{0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},//L
{0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},//M
{0x00,0x7F,0x06,0x08,0x30,0x7F,0x00,0x00},//N
{0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},//O
{0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},//P
{0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},//Q
{0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},//R-50
{0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},//S
{0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},//T
{0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},//U
{0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},//V
{0x00,0x7F,0x20,0x18,0x20,0x7F,0x00,0x00},//W
{0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},//X
{0x00,0x07,0x08,0x70,0x08,0x07,0x00,0x00},//Y
{0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},//Z
{0x00,0x00,0x7F,0x41,0x41,0x00,0x00,0x00},//[
{0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},//\//-60
{0x00,0x00,0x41,0x41,0x7F,0x00,0x00,0x00},//]
{0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},//^
{0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00},//_
{0x00,0x00,0x00,0x07,0x05,0x07,0x00,0x00},//' Insty
{0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},//a
{0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},//b
{0x00,0x38,0x44,0x44,0x44,0x28,0x00,0x00},//c
{0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},//d
{0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},//e
{0x00,0x00,0x08,0x7E,0x09,0x02,0x00,0x00},//f-70
{0x00,0x0C,0x52,0x52,0x4C,0x3E,0x00,0x00},//g
{0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},//h
{0x00,0x00,0x44,0x7D,0x40,0x00,0x00,0x00},//i
{0x00,0x20,0x40,0x44,0x3D,0x00,0x00,0x00},//j
{0x00,0x00,0x7F,0x10,0x28,0x44,0x00,0x00},//k
{0x00,0x00,0x41,0x7F,0x40,0x00,0x00,0x00},//l
{0x00,0x7C,0x04,0x78,0x04,0x78,0x00,0x00},//m
{0x00,0x7C,0x08,0x04,0x04,0x78,0x00,0x00},//n
{0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00},//o
{0x00,0x7E,0x0C,0x12,0x12,0x0C,0x00,0x00},//p-80
{0x00,0x0C,0x12,0x12,0x0C,0x7E,0x00,0x00},//q
{0x00,0x7C,0x08,0x04,0x04,0x08,0x00,0x00},//r
{0x00,0x58,0x54,0x54,0x54,0x64,0x00,0x00},//s
{0x00,0x04,0x3F,0x44,0x40,0x20,0x00,0x00},//t
{0x00,0x3C,0x40,0x40,0x3C,0x40,0x00,0x00},//u
{0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},//v
{0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},//w
{0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},//x
{0x00,0x1C,0xA0,0xA0,0x90,0x7C,0x00,0x00},//y
{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},//z-90
{0x00,0x00,0x08,0x36,0x41,0x00,0x00,0x00},//{
{0x00,0x00,0x00,0x77,0x00,0x00,0x00,0x00},//|
{0x00,0x00,0x41,0x36,0x08,0x00,0x00,0x00},//}
{0x00,0x08,0x04,0x08,0x10,0x08,0x00,0x00},//~
{0x00,0x5c,0x62,0x02,0x62,0x5c,0x00,0x00},//OM
{0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14},//horiz lines-96
};
//Delayer
void delay0(int counter){
int i,j;
for(i=0;i<counter;i++){for(j=0;j<i;j++){;}}
}
//Write Plus
void wri(void){clk=0;clk=1;}
//a B Data to LCD,dt:data,com:1-dat/0-com//1=clk,2=dat,3=reg,4=res
void b2l(unsigned char dt,unsigned char com){
unsigned char i;
if(com)reg=1;else reg=0;
for(i=0;i<8;i++){
  if(dt&0x80){dat=1;}else{dat=0;};
  dt=dt<<1;
  wri();
}
}
//Set LCD X,Y
void setXY(unsigned char pag,unsigned char col){
b2l(0xB0+pag,0);//page3~0μú1~μú3DD
//col+=4;
b2l(0x10+((col&0xF0)>>4),0);//row-H4
b2l(col&0x0F,0);//row-L4
}
//Send a ASCII to LCD
void c2l(unsigned char pag,unsigned char col,unsigned char c){
unsigned char line;
setXY(pag,col*6);               
for(line=0;line<6;line++) b2l(asc2[c][line],1);
}
//Clear LCD
void lcdClear(void){
unsigned char pag,col;
for(pag=0xB8;pag>=0xB0;pag--){
  b2l(pag,0);
  b2l(0x10,0);
  b2l(0x00,0);
  for(col=0;col<132;col++){b2l(0x00,1);}
}
}
//12864LCD Initial
void lcdInit(void){
res=0;
delay0(10000);
res=1;
delay0(10000);
b2l(0xAE,0);//AE=Disp Off/AF=Disp On
b2l(0xE2,0);//LCD Initial
b2l(0xA0,0);//Refresh Colum:A0=1-->132/A1=132-->1
b2l(0xC8,0);//Refresh COM:C0=1-->64/C8=64-->1||A0+C8:col--X-->4
b2l(0xA3,0);//A2=1/65=1/7||A3=1/65=1/9
delay0(2000);
b2l(0x2F,0);//Power Mode:28+VC+VR+VF
b2l(0x23,0);//20->27=1.9,2.19,2.55,3.02,3.61,4.35,5.29,6.48V/Bian Vol
delay0(2000);
b2l(0x81,0);//V0 Vol,After:Num
b2l(0x14,0);//000000~111111=0~63=8.83~11.17V/30=10V
delay0(2000);
b2l(0xA4,0);//A4-All Off/A5-All On
b2l(0x10,0);//Column High 4 start:0x10+0000->1111
b2l(0x00,0);//Column Low 4 start:0x10+0000->1111
b2l(0x40,0);//40+xxxxxx=Disp From 0->63
b2l(0x10,0);//10+xxxx=Disp Column Migh 4 bts
b2l(0x00,0);//00+xxxx=Disp Column low bits xxxxxxxx=0->131
b2l(0xAD,0);//AC=Corser Off/AD=Corser On/After Num
b2l(0x03,0);//00=OFF/01=1S/02=0.5S/03=All On
b2l(0xAF,0);//Start Display
delay0(10000);
}
//12864 Display ASCII Test
void dispAsc(void){
int i,j,k=0;
for(i=0;i<8;i++){
  for(j=0;j<21;j++){
   c2l(i,j,k);
   //delay(1000);
   if(k>94){k=0;}else{k++;}
  }
}
}

//END Files//

main.cpp的代码如下,由于此例中没有其他定义的东西,所以很空。本例试将ASCII码罗列在LCD上,延时LED后清屏,重新来过。
#include "mbed.h"
#include "12864.h"

//Define Objects
DigitalOut led1(PB_0);
DigitalOut led2(PB_7);
DigitalOut led3(PB_14);

//Define Variable


//main Program
int main(){
lcdInit();
lcdClear();
while(true){
  led1=1;led2=0;led3=1;
  wait(0.2);
  led1=0;led2=1;led3=0;
  wait(0.2);
  lcdClear();
  dispAsc();
}
}

结果见图片31。
以后的实验多为添加功能,只是在对应的位置增加语句或函数,因此比较简单。随着实验的进行,涉及到的内容将增多,因此需要考虑GPIO的位置和连接硬件方便。并且,随着现实的内容增加,LCD的布局也逐步提上日程,因为这种显示屏最多显示8X8点阵的ASCII码一行16个,可以显示8行。

DSCN0545.JPG (462.28 KB )

31-驱显128x64黑白LCS显示屏

31-驱显128x64黑白LCS显示屏
沙发
玛尼玛尼哄| | 2017-1-16 22:51 | 只看该作者
MBED做这个真是很方便,不知道这个是什么接口的屏幕,4根线是SPI?

使用特权

评论回复
板凳
zhjb1|  楼主 | 2017-1-18 07:56 | 只看该作者
玛尼玛尼哄 发表于 2017-1-16 22:51
MBED做这个真是很方便,不知道这个是什么接口的屏幕,4根线是SPI?

是的,串口128X64的LCD。买来是那种反光式的,自己将背面反光膜撕掉加了个背光板。驱动芯片是SPLC501,但在其他许多不同的LCD上都能驱显。谢谢

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:永远好心情 [img]https://bbs.21ic.com/static/image/s

47

主题

238

帖子

1

粉丝