[WiFiduino-8266开发板测试]四、驱显4线LCD
首先用IO4~1测试4线LCD,效果很好;为了避开复用引脚,接着测试IO5,14,13,12这4个引脚,效果很好。本实验采用Blink工程,因此复制一个Blink工程,改名为lcd2864,里面的blink.ino改为lcd2864..ino,创建一个lcd2864.h文档,里面的代码如下://define IO for LCD12864
#define dat 15
#define clk 14
#define reg 13
#define res 12
const unsigned char asc2[]={//ASCII
{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,0x80,0x80,0x80,0x80,0x80},//-
{0x00,0x00,0x00,0x24,0x00,0x00},//:-40
};
//Write Plus
void wri(){
digitalWrite(clk,LOW);
digitalWrite(clk,HIGH);
}
//Write 1 byte to LCD,dt:Data,Command:1/0-Data
void b2l(unsigned int dt,unsigned int com){
unsigned int i;
if(com) digitalWrite(reg,HIGH);else digitalWrite(reg,LOW);
for(i=0;i<8;i++){
if(dt&0x80) digitalWrite(dat,HIGH);else digitalWrite(dat,LOW);
dt=dt<<1;
wri();
}
}
//Set LCD X:0-102 Y:0-3
void setXY(unsigned int pag,unsigned int col){
b2l(0xB0+(7-pag),0);
b2l(0x10+((col&0xF0)>>4),0);//0x12
b2l(col&0x0F,0);//row-L4
}
//LCD Clear
void lcdClear(void){
unsigned int pag,col;
for(pag=0;pag<8;pag++){
setXY(pag,0);
for(col=0;col<132;col++){b2l(0x00,1);};
}
}
//c:Char,cha[]
void c2l(unsigned int pag,unsigned int col,unsigned int c){
unsigned int line;
setXY(pag,col*6);
for (line=0;line<6;line++)
b2l(asc2,1);
}
//12864LCD Initial
void lcdInit(void){
digitalWrite(res,LOW);
delay(500);
digitalWrite(res,HIGH);
delay(500);
b2l(0xAE,0);//AE=Disp Off/AF=Disp On
b2l(0xE2,0);//LCD Initial
delay(5);
b2l(0xA1,0);//Refresh Colum:A0=1-->132/A1=132-->1
b2l(0xC0,0);//Refresh COM:C0=1-->64/C8=64-->1||A0+C8:col--X-->4
b2l(0xA2,0);//A2=1/65=1/7__A3=1/65=1/9
delay(5);
b2l(0x2F,0);//Power Mode:28+VC+VR+VF
delay(5);
b2l(0x22,0);//20->27=1.9,2.19,2.55,3.02,3.61,4.35,5.29,6.48V/Bian Vol
delay(5);
b2l(0x81,0);//V0 Vol,After:Num
b2l(0x1A,0);//000000~111111=0~63=8.83~11.17V/30=10V
delay(5);
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
delay(100);
}
//Display ASCII Test
void dispAsc(void){
int i,j,k=0;
for(i=0;i<8;i++){
for(j=0;j<22;j++){
c2l(i,j,k);
if(k>39){k=0;}else{k++;}}
}
}
lcd2864.ino代码如下:
#include "lcd12864.h"
#define led 0
//define Avr for Test
long js;//,val1,val0;
int dut0,dut1,duty,ddt0=1,ddt1=2,pwmdir0,pwmdir1;
//Display BaseData
void dispBase(void){
c2l(0,3,32);c2l(0,4,18);c2l(0,5,15);c2l(0,6,18);c2l(0,7,13);c2l(0,8,30);c2l(0,9,18);c2l(0,10,23);c2l(0,11,24);//WIFIDUINO
c2l(0,13,29);c2l(0,14,14);c2l(0,15,28);c2l(0,16,29);//TEST
c2l(1,0,19);c2l(1,1,28);//JS
c2l(2,0,28);c2l(2,1,14);c2l(2,2,27);c2l(2,3,31);c2l(2,4,14);c2l(2,5,27);c2l(2,6,40);//SERVER:
c2l(3,0,18);c2l(3,1,25);c2l(3,2,40);//IP:
c2l(3,0,25);c2l(3,1,32);c2l(3,2,13);c2l(3,3,40);//PWD:
c2l(4,0,28);c2l(4,1,29);c2l(4,2,10);c2l(4,3,29);c2l(4,4,40);//STAT:
}
//Display Test Data
void dispMes(void){
c2l(1,3,(js/100000)%10);c2l(1,4,(js/10000)%10);c2l(1,5,(js/1000)%10);c2l(1,6,(js/100)%10);c2l(1,7,(js/10)%10);c2l(1,8,(js)%10);
}
void setup(){
for(int i=12;i<16;i++){pinMode(i,OUTPUT);};
pinMode(LED_BUILTIN,OUTPUT);
lcdInit();
lcdClear();
dispBase();
}
//the loop function runs over and over again forever
void loop(){
js++;
digitalWrite(LED_BUILTIN,LOW);delay(10);digitalWrite(LED_BUILTIN,HIGH);
dispMes();
delay(450);
}
照片41是连接IO1~4驱显LCD,刷屏ASCII码;照片42是设计屏幕驱显服务器状态的信息,以备后用。主程序每循环一圈,计数器增1,LED闪亮10mS,并且刷新服务器信息一次。
页:
[1]