
-
UID:1023450
-
- 注册时间2011-12-16
- 最后登录2022-04-17
- 在线时间2350小时
-
-
访问TA的空间加好友用道具
|
序 在我的帖子: 捡了个 M64+JD19264 ,改个AVR开发板(含ARDUINO示波器代码)http://bbs.mydigit.cn/read.php?tid=1501687,介绍了arduino点亮 ks0108芯片组的JD19264液晶例子。 这个板子的液晶是JD19264,为了点亮它,花费了很多精力,因为avr驱动19264液晶的样例很少,芯片不同,驱动也不同,也不想过多在这方面的细节上多耗脑子,便想用arduino下大名鼎鼎的u8glib,该库支持常见的好几十种lcd,便下载下来,但很快发现,这个库就是不支持ks0107/0108芯片组的19264lcd,对ks0108 只支持一种分辨率:128X64! 好在同一芯片组,驱动方式几乎相同, 而且u8lib是用C++写成,封装得非常好,其最底层和硬件有关的代码也按通用性的要求提供了方便的移植,只要调用相应的函数就行,便尝试增加对19264的支持,尽管这次移植针对的是JD19264,但方法是通用的,你可以仿照这一过程来增加对尚未支持的lcd扩充支持; 一、分析,用关键词KS0108、ks0108 搜索整个库,只有三个文件于此硬件相关:1 ..\U8glib\src\U8glib.h2 ..\U8glib\src\clib\u8g.h3 ..\U8glib\src\clib\u8g_dev_ks0108_128x64.c 二、在相关头文件中增加相应的申明: 1 u8g.h: Line 385: /* Display: Generic KS0108b, Size: 128x64 monochrom */ Line 386: extern u8g_dev_t u8g_dev_ks0108_128x64; /* official Arduino Library interface */ Line 387: extern u8g_dev_t u8g_dev_ks0108_128x64_fast; /* faster, but uses private tables from the Arduino Library */ 这三行代码声明了一个 ks0108 128X64的设备,仿照这三行,我们先拷贝并在下方粘贴,并将贴入的代码中所有128X64改成192X64,具体如下 - /* Display: Generic KS0108b, Size: 192x64 monochrom */
- extern u8g_dev_t u8g_dev_ks0108_192x64; /* official Arduino Library interface */
- extern u8g_dev_t u8g_dev_ks0108_192x64_fast; /* faster, but uses private tables from the Arduino Library */
2 U8glib.h也有三行找到: Line 1108: class U8GLIB_KS0108_128 : public U8GLIB Line 1111: U8GLIB_KS0108_128(uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, Line 1113: : U8GLIB(&u8g_dev_ks0108_128x64_fast, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset) 具体代码为: - class U8GLIB_KS0108_128 : public U8GLIB
- {
- public:
- U8GLIB_KS0108_128(uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
- uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw = U8G_PIN_NONE, uint8_t reset = U8G_PIN_NONE)
- : U8GLIB(&u8g_dev_ks0108_128x64_fast, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
- { }
- };
进行了类声明 class U8GLIB_KS0108_128 我们也复制并在它的下方粘贴,修改128为192,仿照它声明一个 class U8GLIB_KS0108_192,具体代码为: - class U8GLIB_KS0108_192 : public U8GLIB
- {
- public:
- U8GLIB_KS0108_192(uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
- uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw = U8G_PIN_NONE, uint8_t reset = U8G_PIN_NONE)
- : U8GLIB(&u8g_dev_ks0108_192x64_fast, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
- { }
- };
这样声明部分就完成了,剩下就是实现了,这在u8g_dev_ks0108_128x64.c文件中; 3 u8g_dev_ks0108_192x64.c 先复制个u8g_dev_ks0108_128x64.c的副本,并更名为 u8g_dev_ks0108_192x64.c,并打开,要改的并不多,首先是将所有128改为192; 接着将定义 #define WIDTH 128 改为 #define WIDTH 192 继续将 static const uint8_t u8g_dev_ks0108_192x64_init_seq[] PROGMEM = { 仿照128 将下面的初始化数据由128的两片选两屏增加到三屏;jd19264是个三屏两片选(CSA CSB); 最后uint8_t u8g_dev_ks0108_192x64_fn 中 case U8G_DEV_MSG_PAGE_NEXT:两屏增加到三屏;完整的代码为: - /*
- u8g_dev_ks0108_192x64.c
- Universal 8bit Graphics Library
-
- Copyright (c) 2011, olikraus@gmail.com
- All rights reserved.
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this list
- of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above copyright notice, this
- list of conditions and the following disclaimer in the documentation and/or other
- materials provided with the distribution.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- for JD19264 ks0108 by huaweiwx@sina.com 2012.12.20
- ADDRESS = 0 (Command Mode)
- 0x03f Display On
- 0x0c0 Start Display at line 0
- 0x0b8 | x write to page [0..24]
- 0x040 | y write to y address (y:0..63)
- u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
- u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE)
-
- */
- #include "u8g.h"
- #define WIDTH 192
- #define HEIGHT 64
- #define PAGE_HEIGHT 8
- static const uint8_t u8g_dev_ks0108_192x64_init_seq[] PROGMEM = {
- //for two sele CSA CSB
- U8G_ESC_CS(0), /* disable chip 11*/
- U8G_ESC_ADR(0), /* instruction mode */
- U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
- U8G_ESC_CS(1), /* enable chip 1 */
- 0x03f, /* display on */
- 0x0c0, /* start at line 0 */
- U8G_ESC_DLY(20), /* delay 20 ms */
- U8G_ESC_CS(2), /* enable chip 2 */
- 0x03f, /* display on */
- 0x0c0, /* start at line 0 */
- U8G_ESC_DLY(20), /* delay 20 ms */
- U8G_ESC_CS(3), /* enable chip 3 */
- 0x03f, /* display on */
- 0x0c0, /* start at line 0 */
- U8G_ESC_DLY(20), /* delay 20 ms */
- U8G_ESC_CS(0), /* disable all chips */
- U8G_ESC_END /* end of sequence */
-
- };
- uint8_t u8g_dev_ks0108_192x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
- {
-
- switch(msg)
- {
- case U8G_DEV_MSG_INIT:
- u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
- u8g_WriteEscSeqP(u8g, dev, u8g_dev_ks0108_192x64_init_seq);
- break;
- case U8G_DEV_MSG_STOP:
- break;
- case U8G_DEV_MSG_PAGE_NEXT:
- {
- u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
- u8g_SetAddress(u8g, dev, 0); /* D/I:0 command mode */
- u8g_SetChipSelect(u8g, dev, 3);
- u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /*X select current page (KS0108b) */
- u8g_WriteByte(u8g, dev, 0x040 ); /*Y set address 0 */
- u8g_SetAddress(u8g, dev, 1); /* data mode */
- u8g_WriteSequence(u8g, dev, 64, pb->buf);
- u8g_SetChipSelect(u8g, dev, 0);
-
- u8g_SetAddress(u8g, dev, 0); /* command mode */
- u8g_SetChipSelect(u8g, dev, 2);
- u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (KS0108b) */
- u8g_WriteByte(u8g, dev, 0x040 ); /* set address 0 */
- u8g_SetAddress(u8g, dev, 1); /* data mode */
- u8g_WriteSequence(u8g, dev, 64, 64+(uint8_t *)pb->buf);
- u8g_SetChipSelect(u8g, dev, 0);
-
- u8g_SetAddress(u8g, dev, 0); /* command mode */
- u8g_SetChipSelect(u8g, dev, 1);
- u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (KS0108b) */
- u8g_WriteByte(u8g, dev, 0x040 ); /* set address 0 */
- u8g_SetAddress(u8g, dev, 1); /* data mode */
- u8g_WriteSequence(u8g, dev, 64, 64*2+(uint8_t *)pb->buf);
- u8g_SetChipSelect(u8g, dev, 0);
- }
- break;
- }
- return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
- }
- U8G_PB_DEV(u8g_dev_ks0108_192x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_192x64_fn, U8G_COM_PARALLEL);
- U8G_PB_DEV(u8g_dev_ks0108_192x64_fast, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_192x64_fn, U8G_COM_FAST_PARALLEL);
全部过程和修改内容都贴在这里了,如由坛友肯帮我对全部example中的代码逐个测试一下,也是对arduino开源精神的贡献,当然我也会抽空逐个测试,如没问题,届时将正式公开,其实上面已经是全部代码了,算是个预公开吧。 其它:在我那个 M64+JD19264上,LCD背光电源没有直接接VCC而是通过PA4控制个三极管控制背光电源的开关,所以在我上述帖子中有如下语句:- pinMode(PA_4, 1); //19264 backled on/of
- digitalWrite(PA_4, 0); //19264 backled on
[ 此帖被huaweiwx在2015-12-30 11:32重新编辑 ]
|