切换到宽版
  • 5901阅读
  • 11回复

[AVR]增加修改 arduino  GLCD库,支持ks0108 192x64 三屏三片选LCD [复制链接]

上一主题 下一主题
离线huaweiwx
 

发帖
1372
M币
2167
专家
65
粉丝
297
只看楼主 倒序阅读 我要置顶 楼主  发表于: 2016-09-19
以前 我修改了u8glib,使其支持ks0107/0108  让arduino u8glib支持ks0107/0108芯片组 192X64液晶 http://bbs.mydigit.cn/read.php?tid=1504464;
虽然u8glib支持很多的芯片、而且用C++引用和定制方法简单,但所有应用代码需放在loop中,这种构架更适应于无控制芯片的LCD;

因此,我还试用了另外一个库:GLCD,功能并不差,只是支持的芯片少。但支持ks0107/0108;因此我稍加修改,就支持19264了,也非常好用;

最近几天,有坛友询问ks0107/0108  19264三屏三片选驱动,我再次研究了一下该库,其实其核心代码也支持三屏三片选,因此为坛友写了个三屏三片选的配置文件,同时也放在坛里供需要的朋友,如需要进行其它移植和配置,这里附个简明的教程:


原移植和配置步骤:
一 针对jd19264 M64/128板子并按照说明增加了下述两个文件:

   1   3屏2片选驱动配置文件:用原始文件 src/config/ks0108_Panel.h复制副本并修改而成:
          src/config/ks0108-192x64_Panel.h
      2   对M4/128特定板子的连接方式配置:用src/config/ks0108_Mega.h复制副本并修改而成:
                 src/config/ks0108_m64128.h

二 修改src/glcd_Config.h 增加相应调用 ks0108-192x64_Panel.h 的选项
   第67行 去除注释 // 这样就能调用 config/ks0108-192x64_Panel.h

三 说明,在ks0108-192x64_Panel.h line 139~149 增加了根据定义__AVR_ATmega128__或__AVR_ATmega64__,自动装入ks0108_m64128.h的程序行,如果在其它板子如 1280/2560/644/644P等,则修改或添加相应的硬件连接文件;

以上两个文件是我以前针对 M64/128 JD19264写的文件,硬件不是这个条件的话,请自行修改;


配置自己的硬件环境实例:  (ks0108芯片  19264 三屏三片选)
    增加了一个文件:拷贝合适的配置文件ks0108_Panel.h副本,并更名为 ks0108-192x64_3cs.h
    line 42 修改为三片选  #define NBR_CHIP_SELECT_PINS   3

使用:
  1  修改src/glcd_Config.h
     第67行 加 注释 // 这样就能不会调用 config/ks0108-192x64_Panel.h
     第68行 去除行首 注释 // 这样就能调用 config/ks0108-192x64_3cs.h(这是我修改好的)
     其它的参数,均需要按实际情况设置,其中的说明很详细的。修改没有多大的困难。

  2 根据你具体连接的板子,修改ks0108_m64128.h 文件(或新建一个其它名称的):
    主要有:
       line 28~30 数据端口直接输出(速度快)

       如未定义数据端口,则需要对 d0~d7 分别定义 (line 32~41)
       对2cs 脚定义(line 46~47)
       在 ks0108-192x64_3cs.h 中已定义NBR_CHIP_SELECT_PINS   3
       所以还需要在line 50 定义片选3脚号  glcdCSEL3
       定义 RW DI EN 脚号,line 57~59
       如有reset脚可控,在line 61
       如有背光可控 在line 66


后记:
  我在ks0108-192x64_Panel.h 42行 修改为:
#ifndef NBR_CHIP_SELECT_PINS
  #define NBR_CHIP_SELECT_PINS   2
#endif
这样 ks0108缺省2片选,如在编译环境有编译选项:
  -DNBR_CHIP_SELECT_PINS=3
选择三片选

或修改为:
#ifndef NBR_CHIP_SELECT_PINS
  #define NBR_CHIP_SELECT_PINS   3
#endif
就变成缺省3片选了。

附:ks0108-192x64_3cs.h
  1. /*
  2. * ks0108-192x64_Panel.h - User specific configuration for Arduino GLCD library
  3. *
  4. * Use this file to set LCD panel parameters
  5. * This version is for a 192x64 ks0108 display
  6. * This file uses a board specific pin assignment file based on the board selected in the IDE
  7. *
  8. */
  9. #ifndef GLCD_PANEL_CONFIG_H
  10. #define GLCD_PANEL_CONFIG_H
  11. /*
  12. * define name for panel configuration
  13. */
  14. #define glcd_PanelConfigName "ks0108-192x64"
  15. /*********************************************************/
  16. /*  Configuration for LCD panel specific configuration   */
  17. /*********************************************************/
  18. #define DISPLAY_WIDTH 192
  19. #define DISPLAY_HEIGHT 64
  20. // panel controller chips
  21. #define CHIP_WIDTH     64  // pixels per chip
  22. #define CHIP_HEIGHT    64  // pixels per chip
  23. /*
  24. * the following is the calculation of the number of chips - do not change
  25. */
  26. #define glcd_CHIP_COUNT (((DISPLAY_WIDTH + CHIP_WIDTH - 1)  / CHIP_WIDTH) * ((DISPLAY_HEIGHT + CHIP_HEIGHT -1) / CHIP_HEIGHT))
  27. /*********************************************************/
  28. /*  Chip Select Configuration                            */
  29. /*********************************************************/
  30. /*
  31. * Change the following define to match the number of Chip Select pins for this panel
  32. * Most panels use two pins for chip select,
  33. * but check your datasheet to see if a different number is required
  34. */
  35. #define NBR_CHIP_SELECT_PINS   3 // the number of chip select pins required for this panel
  36. /*
  37. * The following conditional statements determine the relationship between the chip select
  38. * pins and the physical chips.
  39. * If the chips are displayed in the wrong order, you can swap the glcd_CHIPx defines
  40. */  
  41. /*
  42. * Defines for Panels using two Chip Select pins
  43. */  
  44. #if  NBR_CHIP_SELECT_PINS == 2   //2cspin
  45. /*
  46. * Two Chip panels using two select pins (the most common panel type)
  47. */
  48.   #if glcd_CHIP_COUNT == 2       // 2screen 2cspin
  49.     #define glcd_CHIP0 glcdCSEL1,HIGH,   glcdCSEL2,LOW
  50.     #define glcd_CHIP1 glcdCSEL1,LOW,    glcdCSEL2,HIGH    
  51. /*
  52. * Three Chip panel using two select pins
  53. * 第二屏错需交换
  54. */
  55.   #elif  glcd_CHIP_COUNT == 3    //3screen 2cspin
  56.     #define glcd_CHIP0  glcdCSEL1,LOW,  glcdCSEL2,LOW
  57.     #define glcd_CHIP1  glcdCSEL1,HIGH, glcdCSEL2,LOW
  58.     #define glcd_CHIP2  glcdCSEL1,LOW,  glcdCSEL2,HIGH
  59. /*
  60. * Four Chip panel using two select pins
  61. */
  62.   #elif  glcd_CHIP_COUNT == 4    //4screen 2cspin
  63.     #define glcd_CHIP0  glcdCSEL1,LOW,  glcdCSEL2,LOW
  64.     #define glcd_CHIP1  glcdCSEL1,HIGH, glcdCSEL2,LOW
  65.     #define glcd_CHIP2  glcdCSEL1,HIGH, glcdCSEL2,HIGH    
  66.     #define glcd_CHIP3  glcdCSEL1,LOW,  glcdCSEL2,HIGH    
  67.   #endif
  68. /*
  69. * Defines for Two Chip panels using one Chip Select pin
  70. */
  71. #elif  (NBR_CHIP_SELECT_PINS == 1 && glcd_CHIP_COUNT == 2)  // 2screen 1cspin 128x64
  72.   #define glcd_CHIP0  glcdCSEL1,LOW
  73.   #define glcd_CHIP1  glcdCSEL1,HIGH    
  74. /*
  75. * Defines for Three Chip panels using three select pins
  76. */
  77. #elif (NBR_CHIP_SELECT_PINS == 3 && glcd_CHIP_COUNT == 3)  // 3screen 3cspin 192x64
  78.   #define glcd_CHIP0  glcdCSEL1,HIGH, glcdCSEL2,LOW,  glcdCSEL3,LOW
  79.   #define glcd_CHIP1  glcdCSEL1,LOW,  glcdCSEL2,HIGH, glcdCSEL3,LOW
  80.   #define glcd_CHIP2  glcdCSEL1,LOW,  glcdCSEL2,LOW,  glcdCSEL3,HIGH    
  81. /*
  82. * Defines for Four Chip panel using four select pins
  83. */
  84. #elif  (NBR_CHIP_SELECT_PINS == 4 && glcd_CHIP_COUNT == 4)  //// 4screen 4cspin
  85.   #define glcd_CHIP0  glcdCSEL1,HIGH, glcdCSEL2,LOW,  glcdCSEL3,LOW,  glcdCSEL4,LOW
  86.   #define glcd_CHIP1  glcdCSEL1,LOW,  glcdCSEL2,HIGH, glcdCSEL3,LOW,  glcdCSEL4,LOW
  87.   #define glcd_CHIP2  glcdCSEL1,LOW,  glcdCSEL2,LOW,  glcdCSEL3,HIGH, glcdCSEL4,LOW
  88.   #define glcd_CHIP3  glcdCSEL1,LOW,  glcdCSEL2,LOW,  glcdCSEL3,LOW,  glcdCSEL4,HIGH    
  89. /*
  90. * Here if the Number of Chip Selects is not supported for the selected panel size and chip size
  91. */
  92. #else  //
  93.   #error "The number of Chips and Chip Select pins does not match an option in ks0108-192x64_3cs.h"
  94.   #error "Check that the number of Chip Select pins is correct for the configured panel size"
  95. #endif
  96. /*********************************************************/
  97. /*  End of Chip Select Configuration                     */
  98. /*********************************************************/
  99. /*
  100. * The following defines are for panel specific low level timing.
  101. *
  102. * See your data sheet for the exact timing and waveforms.
  103. * All defines below are in nanoseconds.
  104. */
  105. #define GLCD_tDDR   320    /* Data Delay time (E high to valid read data)        */
  106. #define GLCD_tAS    140    /* Address setup time (ctrl line changes to E HIGH   */
  107. #define GLCD_tDSW   200    /* Data setup time (data lines setup to dropping E)   */
  108. #define GLCD_tWH    450    /* E hi level width (minimum E hi pulse width)        */
  109. #define GLCD_tWL    450    /* E lo level width (minimum E lo pulse width)        */
  110. /*
  111.   * The code below selects a configuration file for pin assignment based on the board selected in the IDE
  112.   * These configurations are compatible with wiring used in earlier versions of the library
  113.   * WARNING: When adding new board types it is not as simple as just editing these lines.
  114.   * There is also a dependency on the file glcd/include/arduino_io.h which does the arduino pin mappings
  115.   */
  116. #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  117. #include "config/ks0108_Mega.h"      // config for mega 1280/2560 board
  118. #elif defined(__AVR_ATmega644P__)  || defined(__AVR_ATmega644__)          
  119. #include "config/ks0108_Sanguino.h"  // config for Sanguino or other ATmega644/p board
  120. #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) || defined(__AVR_ATmega32U4__)// Teensy
  121. #include "config/ks0108_Teensy.h"    // config for Teensy and Teensy++  
  122. #elif defined(__AVR_ATmega128__) || defined(__AVR_ATmega64__)
  123. #include "config/ks0108_m64128.h"      // config for mega 1280/2560 board
  124. #else
  125. #include "config/ks0108_Arduino.h"   // config file for standard Arduino using documented wiring
  126. #endif
  127. #include "device/ks0108_Device.h"
  128. #endif //GLCD_PANEL_CONFIG_H

ks0108_m64128.h
  1. /*
  2. * ks0108_Arduino.h - User specific configuration for Arduino GLCD library
  3. *
  4. * Use this file to set io pins
  5. * This version is for a standard ks0108 display
  6. * connected using the default Arduino wiring
  7. *
  8. */
  9. #ifndef GLCD_PIN_CONFIG_H
  10. #define GLCD_PIN_CONFIG_H
  11. /*
  12. * define name for pin configuration
  13. */
  14. #define glcd_PinConfigName "ks0108_m64128"
  15. /*********************************************************/
  16. /*  Configuration for assigning LCD bits to Arduino Pins */
  17. /*********************************************************/
  18. /* Data pin definitions by huaweiwx@sina.com 2016.2.3
  19. */
  20. //  d0,   d1,   d2,   d3,   d4,   d5,   d6,   d7,  en,  cs1,   cs2,  di,   rw,  reset)
  21. //PC_0, PC_1, PC_2, PC_3, PC_4, PC_5, PC_6, PC_7, PG_1, PD_5, PD_6, PD_7, PG_0, PA_1);  //for M64_GPS    
  22. //直接定义数据端口,快速输出/输入
  23. #define glcdDataPortIN      PINC
  24. #define glcdDataPortOUT     PORTC
  25. #define glcdDataPortDDR     DDRC
  26. #ifndef glcdDataPortIN
  27. #define glcdData0Pin        PIN_C0
  28. #define glcdData1Pin        PIN_C1
  29. #define glcdData2Pin        PIN_C2
  30. #define glcdData3Pin        PIN_C3
  31. #define glcdData4Pin        PIN_C4
  32. #define glcdData5Pin        PIN_C5
  33. #define glcdData6Pin        PIN_C6
  34. #define glcdData7Pin        PIN_C7
  35. #endif
  36. /* Arduino pins used for Commands
  37. * default assignment uses the first five analog pins
  38. */
  39. #define glcdCSEL1           PIN_D5
  40. #define glcdCSEL2           PIN_D6
  41. #if NBR_CHIP_SELECT_PINS >  2
  42.   #define glcdCSEL3         PIN_XX   // third chip select if needed
  43. #endif
  44. #if NBR_CHIP_SELECT_PINS >  3
  45.   #define glcdCSEL4         PIN_XX   // fourth chip select if needed
  46. #endif
  47. #define glcdRW              PIN_G0
  48. #define glcdDI              PIN_D7
  49. #define glcdEN              PIN_G1
  50. // Reset Bit  - uncomment the next line if reset is connected to an output pin
  51. //#define glcdRES           PIN_A1    // Reset Bit
  52. //huawei add
  53. #define LCDBACK_PIN      PA_4
  54. #ifdef  LCDBACK_PIN
  55. #define LcdBackOn()  digitalWrite(LCDBACK_PIN, 0)
  56. #define LcdBackOff() digitalWrite(LCDBACK_PIN, 1)
  57. #endif
  58. #endif //GLCD_PIN_CONFIG_H

其它文件你可以网上百度下载,按我上述内容修改相关文件,也可直接下载我修改好的全部文件:
附件:我改好的全部库文件:GLCD
使用:解压后将glcd文件夹copy到 arduino/libraries 中。




[ 此帖被huaweiwx在2016-09-19 14:15重新编辑 ]
本文内容包含图片或附件,获取更多资讯,请 登录 后查看;或者 注册 成为会员获得更多权限
本帖最近打赏记录:共11条打赏 ,M币+33
12
离线xktx09

发帖
4992
M币
3889
专家
2
粉丝
126
只看该作者 1楼 发表于: 2016-09-19
请登录后查看
本帖最近打赏记录:共1条打赏 ,M币+3
离线liquidator

发帖
3889
M币
11360
专家
0
粉丝
29
只看该作者 2楼 发表于: 2016-09-19
请登录后查看
本帖最近打赏记录:共1条打赏 ,M币+3
离线2545889167

发帖
13268
M币
20754
专家
302
粉丝
4860
只看该作者 3楼 发表于: 2016-09-19
请登录后查看
本帖最近打赏记录:共1条打赏 ,M币+3
离线jpdd521

发帖
25694
M币
7956
专家
15
粉丝
350
只看该作者 4楼 发表于: 2016-09-19
请登录后查看
本帖最近打赏记录:共1条打赏 ,M币+3
离线jpdd521

发帖
25694
M币
7956
专家
15
粉丝
350
只看该作者 5楼 发表于: 2016-09-19
请登录后查看
离线杨雪飞

发帖
5906
M币
1133
专家
28
粉丝
219
只看该作者 6楼 发表于: 2016-09-20
请登录后查看
离线是就好

发帖
114
M币
1386
专家
0
粉丝
13
只看该作者 7楼 发表于: 2016-09-20
请登录后查看
离线cao57508

发帖
2265
M币
3657
专家
9
粉丝
85
只看该作者 8楼 发表于: 2016-09-20
请登录后查看
离线huaweiwx

发帖
1372
M币
2167
专家
65
粉丝
297
只看该作者 9楼 发表于: 2016-09-20
回 cao57508 的帖子
请登录后查看
快速回复
限80 字节
“新手上路”发帖需审核后才能显示(请认真发帖),达到数码9级后取消此限制
 
上一个 下一个