更新:,修改C51代码,实测C51驱动,增加C51连线图
事情一开始是这样的,这一块是从自动寄存柜上拆下的屏幕。已经放置了两三年了,我想着给它用一下。具体的型号是M-1B1
使用的是少见的22pin脚位
然后很神奇,这玩意现在居然要卖几百块钱,这种几千都是虚标价格,实际价格应该在200-300之间,或者也没人知道具体多少。
但是以前的价格我们还是可以查到的,像是这一块Truly M只要十几块钱
这一个屏幕并不是太好驱动,最大问题是资料极其难找,我试着搜索Truly或者搜索都是不同的结果。
truly-msp-gdyly-2w 这个是其中一种g的,m的没找到
在线地址 truly-msp-gdyly-2w - 道客巴巴
avr_truly_Mdriver
在线地址
avr_TRULY_Mdriver - 源码下载|嵌入式/单片机编程|单片机(51,AVR,MSP430等)|源代码 - 源码中国
TRULYM-1A1显示程序 - 百度文库
看了一眼这个g的居然是1998年的资料 ,也因此相关的内容非常难找
引脚的对应,但要注意这个是g,我看了一下,LEDA和LEDK是分别对应21,22
整个的原理图
驱动这一个屏幕,需要提供5V的电压,所以使用5V的MCU来控制是最好的,当然如果说单独提供电压给MCU,也可以用3.3V的来控制逻辑部分。另外有背光的驱动,需要提供高达380mA的大电流,背光的电压要控制在不超过4.6V典型为4.2V。
这也就是说背光的驱动上必须要加电阻至少加一个10欧姆(调试时候应该要加100欧姆)
但是同时我又找到一张m的资料,可以看出来用的液晶面板是有所不同的,模组的尺寸相差有一些,但是基本一致
这个是M
对比一下可以发现,是把东芝芯片换成了环氧树脂封装的某种芯片
另外还找到了M
这个是安装在这样的一个地方上,配的处理器还是ARM
然后还好我更多的搜索了一下,终于在数码之家找到有一位网友可以点亮这一个屏幕的了,可以知道屏幕是使用KS0108,原帖地址 http://bbs.mydigit.cn/read.php?tid=
最重要是给出来引脚图
和实际的进行一下对应,他上面写的加了一个数字行后非常容易引发误解。我通过K和A进行确认后确认这一引脚可能是对的。
从网友那边复制的代码有两个文件一个是ziku.h一个是main.c,他们使用的C51
ziku.h
unsigned char code ye[]= { 0x10,0x61,0x86,0x60,0x84,0xE4,0x1C,0x84,0x45,0x3E,0xA4,0x24,0xE6,0x04,0x00,0x00, 0x02,0x3E,0x01,0x00,0x00,0x3F,0x21,0x20,0x11,0x0A,0x04,0x0B,0x10,0x20,0x00,0x00, }; unsigned char code jin[]= { 0x00,0x80,0x80,0x80,0xBE,0xAA,0x2A,0x2A,0xAA,0xAA,0xBF,0x82,0x80,0x00,0x00,0x00, 0x00,0x3F,0x14,0x14,0x14,0x3F,0x00,0x00,0x3F,0x14,0x14,0x14,0x3F,0x00,0x00,0x00, }; unsigned char code xian[]= { 0x00,0x00,0x00,0x7E,0x2A,0xAA,0x2A,0x2A,0xAA,0x2A,0x2A,0x7F,0x02,0x00,0x00,0x00, 0x20,0x21,0x22,0x2C,0x20,0x3F,0x20,0x20,0x3F,0x28,0x24,0x22,0x31,0x20,0x00,0x00, }; unsigned char code shi[]= { 0x00,0x20,0x22,0x22,0xA2,0x22,0x22,0xE2,0x22,0xA2,0x22,0x23,0x32,0x20,0x00,0x00, 0x00,0x08,0x04,0x02,0x01,0x10,0x20,0x1F,0x00,0x00,0x01,0x02,0x0C,0x00,0x00,0x00, }; unsigned char code she[]= { 0x20,0x20,0x21,0xE6,0x40,0x20,0x5E,0xC2,0x42,0x42,0x4F,0xD2,0x10,0x10,0x00,0x00, 0x00,0x00,0x00,0x0F,0x24,0x22,0x10,0x11,0x0A,0x04,0x0A,0x11,0x30,0x10,0x00,0x00, }; unsigned char code ji[]= { 0x20,0x21,0x22,0xE6,0x00,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x30,0x20,0x00,0x00, 0x00,0x00,0x00,0x1F,0x08,0x04,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x00, }; unsigned char code shang[]= { 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x20,0x20,0x20,0x20,0x30,0x20,0x00,0x00,0x00, 0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0x10,0x10,0x10,0x10,0x10,0x18,0x10,0x00,0x00, }; unsigned char code shan[]= { 0x40,0x44,0x54,0x54,0xD5,0x56,0x54,0xFC,0x56,0xD5,0x54,0x56,0x44,0x40,0x00,0x00, 0x00,0x01,0x01,0x3D,0x25,0x25,0x25,0x25,0x25,0x25,0x3D,0x01,0x01,0x00,0x00,0x00, }; unsigned char code ruo[]= { 0x44,0x44,0x44,0x44,0x44,0xCF,0x74,0x44,0x44,0x4F,0x44,0x44,0x66,0x44,0x00,0x00, 0x08,0x08,0x04,0x02,0x3F,0x11,0x11,0x11,0x11,0x11,0x3F,0x00,0x00,0x00,0x00,0x00, }; unsigned char code shui[]= { 0x00,0x10,0x10,0x10,0xF0,0x00,0x00,0xFF,0xC0,0x20,0x10,0x08,0x00,0x00,0x00,0x00, 0x10,0x08,0x04,0x03,0x00,0x10,0x20,0x1F,0x00,0x01,0x02,0x04,0x08,0x08,0x00,0x00, }; unsigned char code zhong[]= { //0x00,0xF8,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0xFC,0x08,0x00,0x00,0x00, //0x00,0x01,0x01,0x01,0x01,0x01,0x3F,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00, // wo 0x20,0x24,0x24,0x24,0xFE,0x23,0x22,0x20,0x20,0xFF,0x20,0x22,0x2C,0xA0,0x20,0x00, 0x00,0x08,0x48,0x84,0x7F,0x02,0x41,0x40,0x20,0x13,0x0C,0x14,0x22,0x41,0xF8,0x00, }; unsigned char code nan[]= { 0x04,0x04,0xF4,0x14,0x14,0x54,0x94,0x1F,0x94,0x54,0x14,0x14,0xF6,0x04,0x00,0x00, 0x00,0x00,0x3F,0x00,0x05,0x05,0x05,0x1F,0x05,0x05,0x15,0x20,0x1F,0x00,0x00,0x00, }; unsigned char code da[]= { 0x10,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x18,0x10,0x00,0x00, 0x20,0x20,0x10,0x08,0x04,0x03,0x00,0x01,0x02,0x04,0x08,0x10,0x30,0x10,0x00,0x00, }; unsigned char code xue[]= { 0x20,0x18,0x08,0x29,0x2E,0x28,0x29,0xAE,0xA8,0x6C,0x2B,0x08,0x28,0x18,0x00,0x00, 0x02,0x02,0x02,0x02,0x02,0x12,0x22,0x1F,0x02,0x02,0x02,0x02,0x03,0x02,0x00,0x00, };
LCD 引脚 | 描述 | MCU 引脚 |
---|---|---|
CS1 | 芯片选择1 | P3.2 |
CS2 | 芯片选择2 | P3.3 |
CS3 | 芯片选择3 | P3.4 |
CS4 | 芯片选择4 | P3.5 |
RS | 命令/数据 | P2.6 |
RW | 读/写 | P2.5 |
E | 使能 | P2.7 |
DB0~DB7 | 数据总线 | P0.0~P0.7 |
wrcomleft()
:向左半屏写入命令wrcomright()
:向右半屏写入命令wrcomleftdown()
:向左下角屏幕写入命令wrcomrightdown()
:向右下角屏幕写入命令wrdataleft()
:向左半屏写入数据wrdataright()
:向右半屏写入数据wrdataleftdown()
:向左下角屏幕写入数据wrdatarightdown()
:向右下角屏幕写入数据busycheck()
:检查液晶屏幕是否繁忙disp()
:在液晶屏幕上显示指定的数据cursor()
:移动液晶屏幕上的光标delay1ms()
:延迟指定的时间clc_screen()
:清空液晶屏幕,并在屏幕上显示一个空白页面 // ÉÏÉÆÈôË® 2010 3 9 // // ÖÐÄÏ´óѧ // // ÐÅÏ¢¿ÆѧÓ빤³ÌѧԺ // #include "reg51.h" #include <string.h> #include"ziku.h" #define uchar unsigned char #define LCD_DB P0 sbit cs1=P3^2; sbit cs2=P3^3; sbit cs3=P3^4; sbit cs4=P3^5; sbit rs=P2^6; sbit rw=P2^5; sbit e=P2^7; void wrcomleft(uchar); void wrcomright(uchar); void wrcomleftdown(uchar); void wrcomrightdown(uchar); void wrdataleft(uchar); void wrdataright(uchar); void wrdataleftdown(uchar); void wrdatarightdown(uchar); void busycheck(); void disp(uchar,uchar,uchar); void cursor(uchar, uchar); delay1ms(int t); void clc_screen(); main() { uchar *p; P1 &= 0xf0; clc_screen(); while(1) { p=&ye; disp(0xbe,0x40,p); p=&ye; disp(0xbe,0x50,p); p=&ye; disp(0xbe,0x60,p); p=&ye; disp(0xbe,0x70,p); p=&ye; disp(0xbe,0x80,p); p=&ye; disp(0xbe,0xa8,p); p=&ye; disp(0xbe,0xd0,p); } } void disp(uchar page, uchar col, uchar *p) { int i; if(col<0x80) { wrcomleft(0x3f); wrcomleft(page); wrcomleft(col); for(i=0;i<16;i++) { wrdataleft(p); } wrcomleft(page+1); wrcomleft(col); for(i=16;i<32;i++) { wrdataleft(p); } } if(col>0x7f && col<0xA8) { col=col-64; wrcomright(0x3f); wrcomright(page); wrcomright(col); for(i=0;i<16;i++) { wrdataright(p); } wrcomright(page+1); wrcomright(col); for(i=16;i<32;i++) { wrdataright(p); } } if(col>0xA7 && col<0xD0) { col=col-104; wrcomleftdown(0x3f); wrcomleftdown(page); wrcomleftdown(col); for(i=0;i<16;i++) { wrdataleftdown(p); } wrcomleftdown(page+1); wrcomleftdown(col); for(i=16;i<32;i++) { wrdataleftdown(p); } } if(col>0xCf && col<0xF8) { col=col-144; wrcomrightdown(0x3f); wrcomrightdown(page); wrcomrightdown(col); for(i=0;i<16;i++) { wrdatarightdown(p); } wrcomrightdown(page+1); wrcomrightdown(col); for(i=16;i<32;i++) { wrdatarightdown(p); } } } void clc_screen()// ÇåÆÁº¯Êý { int i,j; wrcomleft(0x3f); wrcomright(0x3f); wrcomleftdown(0x3f); wrcomrightdown(0x3f); for(i=0;i<8;i++) { wrcomleft(0xb8+i); wrcomright(0xb8+i); wrcomleft(0x40); wrcomright(0x40); wrcomleftdown(0xb8+i); wrcomrightdown(0xb8+i); wrcomleftdown(0x40); wrcomrightdown(0x40); for(j=0;j<0x40;j++) { wrdataleft(0); wrdataright(0); wrdataleftdown(0); wrdatarightdown(0); } } } void wrcomleft(uchar h)//×óƬдָÁî³ÌÐò { cs1=0; cs2=1; cs3=0; cs4=0; rw=0; //дÓÐЧ rs=0; //дָÁî״̬ LCD_DB=h; delay1ms(0); e=1; delay1ms(0); e=0; //e ϽµÑØдÈëÊý¾Ý } void wrcomright(uchar l)// ÓÒƬдָÁî³ÌÐò { cs1=1; cs2=0; cs3=0; cs4=0; e=1; rw=0;//дÓÐЧ rs=0;//дָÁî״̬ LCD_DB=l; delay1ms(0); e=1; delay1ms(0); e=0; //e ϽµÑØдÈëÊý¾Ý } void wrcomleftdown(uchar h)//×óƬдָÁî³ÌÐò { cs1=0; cs2=0; cs3=0; cs4=1; rw=0; //дÓÐЧ rs=0; //дָÁî״̬ LCD_DB=h; delay1ms(0); e=1; delay1ms(0); e=0; //e ϽµÑØдÈëÊý¾Ý } void wrcomrightdown(uchar l)// ÓÒƬдָÁî³ÌÐò { cs1=0; cs2=0; cs3=1; cs4=0; e=1; rw=0;//дÓÐЧ rs=0;//дָÁî״̬ LCD_DB=l; delay1ms(0); e=1; delay1ms(0); e=0; //e ϽµÑØдÈëÊý¾Ý } void wrdataleft(uchar k)// ×óƬдÊý¾Ý³ÌÐò { cs1=0; cs2=1; cs3=0; cs4=0; rw=0; //дÓÐЧ rs=1; //дÊý¾Ý״̬ LCD_DB=k; delay1ms(0); e=1; delay1ms(0); e=0; //e ϽµÑØдÈëÊý¾Ý } void wrdataright(uchar j)// ÓÒƬдÊý¾Ý³ÌÐò { cs1=1; cs2=0; cs3=0; cs4=0; e=1; rw=0; //дÓÐЧ rs=1; //дÊý¾Ý״̬ LCD_DB=j; delay1ms(0); e=1; delay1ms(0); e=0; //e ϽµÑØдÈëÊý¾Ý } void wrdataleftdown(uchar k)// ×óƬдÊý¾Ý³ÌÐò { cs1=0; cs2=0; cs3=0; cs4=1; rw=0; //дÓÐЧ rs=1; //дÊý¾Ý״̬ LCD_DB=k; delay1ms(0); e=1; delay1ms(0); e=0; //e ϽµÑØдÈëÊý¾Ý } void wrdatarightdown(uchar j)// ÓÒƬдÊý¾Ý³ÌÐò { cs1=0; cs2=0; cs3=1; cs4=0; e=1; rw=0; //дÓÐЧ rs=1; //дÊý¾Ý״̬ LCD_DB=j; delay1ms(0); e=1; delay1ms(0); e=0; //e ϽµÑØдÈëÊý¾Ý } delay1ms(int t) { int i,j; for(i=0;i<t;i++) for(j=0;j<120;j++) ; }
我要移植到Arduino IDE上面,这样方便减少开发时间。
VO不用连接,然后测试时候应该A和K也不用连。
我在上面一个为基础的情况下修改了代码,但是,不能正常的驱动,因为接线或者其他什么原因,VCC和GND的电压一直不够。不管怎么样,当做一个参考来吧
#include <Arduino.h> #define RS 2 #define EN 3 #define RW 4 #define I0 5 #define I2 6 #define I1 7 #define I3 8 #define I4 9 #define I6 10 #define I5 11 #define I7 12 #define CS1 13 #define CS3 A0 #define CS2 A1 #define CS4 A2 #define uchar unsigned char void wrcomleft(uchar); void wrcomright(uchar); void wrcomleftdown(uchar); void wrcomrightdown(uchar); void wrdataleft(uchar); void wrdataright(uchar); void wrdataleftdown(uchar); void wrdatarightdown(uchar); void busycheck(); void disp(uchar,uchar,uchar); void cursor(uchar, uchar); void delay1ms(int t); void clc_screen(); void maintest(); void lg(String s) { Serial.println(s); } void LCD_DB(uchar u) { digitalWrite(I0,u&0x01); digitalWrite(I1,u>>1&0x01); digitalWrite(I2,u>>2&0x01); digitalWrite(I3,u>>3&0x01); digitalWrite(I4,u>>4&0x01); digitalWrite(I5,u>>5&0x01); digitalWrite(I6,u>>6&0x01); digitalWrite(I7,u>>7&0x01); Serial.println("Run Lcd_db"); } void pinInit() { for(int i=2;i<=13;i++) { pinMode(i,OUTPUT); digitalWrite(i,HIGH); } for(int i=A0;i<=A4;i++) { pinMode(i,OUTPUT); digitalWrite(i,HIGH); } Serial.println("Pininit"); } void logicInit() { for(int i=13;i<=A4;i++) { digitalWrite(i,HIGH); } Serial.println("Set pin high"); } void disp(uchar page, uchar col, uchar *p) { int i; lg("Run disp"); if(col<0x80) { wrcomleft(0x3f); wrcomleft(page); wrcomleft(col); for(i=0;i<16;i++) { wrdataleft(p); } wrcomleft(page+1); wrcomleft(col); for(i=16;i<32;i++) { wrdataleft(p); } } if(col>0x7f && col<0xA8) { col=col-64; wrcomright(0x3f); wrcomright(page); wrcomright(col); for(i=0;i<16;i++) { wrdataright(p); } wrcomright(page+1); wrcomright(col); for(i=16;i<32;i++) { wrdataright(p); } } if(col>0xA7 && col<0xD0) { col=col-104; wrcomleftdown(0x3f); wrcomleftdown(page); wrcomleftdown(col); for(i=0;i<16;i++) { wrdataleftdown(p); } wrcomleftdown(page+1); wrcomleftdown(col); for(i=16;i<32;i++) { wrdataleftdown(p); } } if(col>0xCf && col<0xF8) { col=col-144; wrcomrightdown(0x3f); wrcomrightdown(page); wrcomrightdown(col); for(i=0;i<16;i++) { wrdatarightdown(p); } wrcomrightdown(page+1); wrcomrightdown(col); for(i=16;i<32;i++) { wrdatarightdown(p); } } lg("Disp over"); } void clc_screen()// ÇåÆÁº¯Êý { int i,j; wrcomleft(0x3f); wrcomright(0x3f); wrcomleftdown(0x3f); wrcomrightdown(0x3f); for(i=0;i<8;i++) { wrcomleft(0xb8+i); wrcomright(0xb8+i); wrcomleft(0x40); wrcomright(0x40); wrcomleftdown(0xb8+i); wrcomrightdown(0xb8+i); wrcomleftdown(0x40); wrcomrightdown(0x40); for(j=0;j<0x40;j++) { wrdataleft(0); wrdataright(0); wrdataleftdown(0); wrdatarightdown(0); } } } void wrcomleft(uchar h)//×óƬдָÁî³ÌÐò { digitalWrite(CS1,LOW); digitalWrite(CS2,HIGH); digitalWrite(CS3,LOW); digitalWrite(CS4,LOW); digitalWrite(RW,LOW); //дÓÐЧ digitalWrite(RS,LOW); //дָÁî״̬ LCD_DB(h); delay1ms(0); digitalWrite(EN,HIGH); delay1ms(0); digitalWrite(EN,LOW); //e ϽµÑØдÈëÊý¾Ý } void wrcomright(uchar l)// ÓÒƬдָÁî³ÌÐò { digitalWrite(CS1,HIGH); digitalWrite(CS2,LOW); digitalWrite(CS3,LOW); digitalWrite(CS4,LOW); digitalWrite(EN,HIGH); digitalWrite(RW,LOW);//дÓÐЧ digitalWrite(RS,LOW);//дָÁî״̬ LCD_DB(l); delay1ms(0); digitalWrite(EN,HIGH); delay1ms(0); digitalWrite(EN,LOW); //e ϽµÑØдÈëÊý¾Ý } void wrcomleftdown(uchar h)//×óƬдָÁî³ÌÐò { digitalWrite(CS1,LOW); digitalWrite(CS2,LOW); digitalWrite(CS3,LOW); digitalWrite(CS4,HIGH); digitalWrite(RW,LOW); //дÓÐЧ digitalWrite(RS,LOW); //дָÁî״̬ LCD_DB(h); delay1ms(0); digitalWrite(EN,HIGH); delay1ms(0); digitalWrite(EN,LOW); //e ϽµÑØдÈëÊý¾Ý } void wrcomrightdown(uchar l)// ÓÒƬдָÁî³ÌÐò { digitalWrite(CS1,LOW); digitalWrite(CS2,LOW); digitalWrite(CS3,HIGH); digitalWrite(CS4,LOW); digitalWrite(EN,HIGH); digitalWrite(RW,LOW);//дÓÐЧ digitalWrite(RS,LOW);//дָÁî״̬ LCD_DB(l); delay1ms(0); digitalWrite(EN,HIGH); delay1ms(0); digitalWrite(EN,LOW); //e ϽµÑØдÈëÊý¾Ý } void wrdataleft(uchar k)// ×óƬдÊý¾Ý³ÌÐò { digitalWrite(CS1,LOW); digitalWrite(CS2,HIGH); digitalWrite(CS3,LOW); digitalWrite(CS4,LOW); digitalWrite(RW,LOW); //дÓÐЧ digitalWrite(RS,HIGH); //дÊý¾Ý״̬ LCD_DB(k); delay1ms(0); digitalWrite(EN,HIGH); delay1ms(0); digitalWrite(EN,LOW); //e ϽµÑØдÈëÊý¾Ý } void wrdataright(uchar j)// ÓÒƬдÊý¾Ý³ÌÐò { digitalWrite(CS1,HIGH); digitalWrite(CS2,LOW); digitalWrite(CS3,LOW); digitalWrite(CS4,LOW); digitalWrite(EN,HIGH); digitalWrite(RW,LOW); //дÓÐЧ digitalWrite(RS,HIGH); //дÊý¾Ý״̬ LCD_DB(j); delay1ms(0); digitalWrite(EN,HIGH); delay1ms(0); digitalWrite(EN,LOW); //e ϽµÑØдÈëÊý¾Ý } void wrdataleftdown(uchar k)// ×óƬдÊý¾Ý³ÌÐò { digitalWrite(CS1,LOW); digitalWrite(CS2,LOW); digitalWrite(CS3,LOW); digitalWrite(CS4,HIGH); digitalWrite(RW,LOW); //дÓÐЧ digitalWrite(RS,HIGH); //дÊý¾Ý״̬ LCD_DB(k); delay1ms(0); digitalWrite(EN,HIGH); delay1ms(0); digitalWrite(EN,LOW); //e ϽµÑØдÈëÊý¾Ý } void wrdatarightdown(uchar j)// ÓÒƬдÊý¾Ý³ÌÐò { digitalWrite(CS1,LOW); digitalWrite(CS2,LOW); digitalWrite(CS3,HIGH); digitalWrite(CS4,LOW); digitalWrite(EN,HIGH); digitalWrite(RW,LOW); //дÓÐЧ digitalWrite(RS,HIGH); //дÊý¾Ý״̬ LCD_DB(j); delay1ms(0); digitalWrite(EN,HIGH); delay1ms(0); digitalWrite(EN,LOW); //e ϽµÑØдÈëÊý¾Ý } void delay1ms(int t) { int i,j; delay(t); } void setup() { // put your setup code here, to run once: Serial.begin(); pinInit(); Serial.println("Pin Init Over"); delay(1000); } void loop() { maintest(); // put your main code here, to run repeatedly: } unsigned char ye[]= { 0x10,0x61,0x86,0x60,0x84,0xE4,0x1C,0x84,0x45,0x3E,0xA4,0x24,0xE6,0x04,0x00,0x00, 0x02,0x3E,0x01,0x00,0x00,0x3F,0x21,0x20,0x11,0x0A,0x04,0x0B,0x10,0x20,0x00,0x00, }; void maintest() { uchar *p; clc_screen(); while(1) { logicInit(); p=ye; disp(0xbe,0x40,p); p=ye; disp(0xbe,0x50,p); p=ye; disp(0xbe,0x60,p); p=ye; disp(0xbe,0x70,p); p=ye; disp(0xbe,0x80,p); p=ye; disp(0xbe,0xa8,p); p=ye; disp(0xbe,0xd0,p); delay(100); } }