找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 7282|回复: 3
打印 上一主题 下一主题
收起左侧

T6963C单片机驱动程序模版(可用来驱动很多大屛LCD)

[复制链接]
跳转到指定楼层
楼主
ID:102014 发表于 2016-1-6 02:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
原程序是从proteus的示例工程里的,修改了一个函数.
本来需要自己写的这下省了不少事
  1. /****************************************************************************
  2. * Filename: T6963C.h
  3. * Description: T6963C driver
  4. ****************************************************************************/
  5. #include "Config.h"
  6. #include "Target.h"
  7. #define width      16       //Display width         LCD的最大宽度以16*16为单位
  8. #define addr_w     0x0000   //Text display buffer base address  文本区首址
  9. #define addr_t     0x0100   //Graphics display buffer base address        图形区首址

  10. // T6963C Pin definition
  11. #define fs  (1<<8)        //LCD驱动引脚设置
  12. #define cd  (1<<12)
  13. #define ce  (1<<13)
  14. #define rd  (1<<10)
  15. #define wr  (1<<11)
  16. #define rst (1<<9)
  17. #define bf0  (1<<0)   //LCD忙状态标志位
  18. #define bf1  (1<<1)
  19. #define bf3  (1<<3)

  20. // Function declare
  21. void wr_comm (uint8 comm);
  22. void wr_data (uint8 dat);
  23. void chk_busy (uint8 autowr); //test busy flag        获取LCD状态标记并等待LCD空闲

  24. typedef struct typFNT_GB16 // Chinese font structure  16*16中文字模结构体
  25. { char Index[2];    // font index        字符编码
  26.    char Msk[32];     // font table         字模
  27. } typFNT_GB16;

  28. struct typFNT_GB16 const GB_16[] =          // Windway Font table  字模定义
  29. { "驱", 0x00,0x00,0xF9,0xFE,0x09,0x00,0x49,0x04,0x49,0x84,0x49,0x48,0x49,0x28,0x7D,0x10,
  30.          0x05,0x18,0x05,0x28,0x35,0x24,0xC5,0x44,0x05,0x84,0x29,0x00,0x11,0xFE,0x00,0x00,

  31.    "动", 0x00,0x20,0x00,0x20,0x7E,0x20,0x00,0x20,0x00,0xFC,0xFF,0x24,0x10,0x24,0x10,0x24,
  32.          0x24,0x24,0x22,0x24,0x4F,0x44,0xFA,0x44,0x40,0x84,0x01,0x14,0x02,0x08,0x00,0x00,

  33.    "了", 0x00,0x00,0x7F,0xFC,0x00,0x18,0x00,0x60,0x01,0x80,0x01,0x00,0x01,0x00,0x01,0x00,
  34.          0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00,

  35.    "吗", 0x00,0x00,0x03,0xF8,0x78,0x08,0x49,0x08,0x49,0x08,0x49,0x08,0x49,0x08,0x4B,0xFC,
  36.          0x49,0x04,0x78,0x04,0x4B,0xF4,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x14,0x00,0x08,
  37.    
  38. };

  39. // Bitmap table  图片点阵模
  40. // Picture: C:\..\Desktop\223.bmp
  41. // Picture Size: 128 * 64   
  42. uint8 const  nBitmapDot[] =                  // data table
  43. {         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  44. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  45. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  46. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  47. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  48. 0......................................................
  49. };

  50. /*---------------Delay function----------------*/
  51. void delay (uint16 us)
  52. { while(us--);
  53. }

  54. void delay1 (uint16 ms)
  55. { uint16 i,j;
  56.    for(i=0;i<ms;i++)
  57.    for(j=0;j<3000;j++)
  58.       ;
  59. }

  60. /*---------------LCD init----------------*/
  61. void init_lcd (void)
  62. { IO0CLR=rst;
  63.    IO0SET=rst;
  64.    delay1(50);
  65.    IO0CLR=ce;
  66.    IO0SET=wr;
  67.    IO0SET=rd;
  68.    wr_xd(addr_w,0x40);                   // Set text display buffer base address        设置文本区首地址
  69.    wr_xd(addr_t,0x42);                   // Set graphics display buffer base address   设置图形区首地址
  70.    wr_td(width,0x00,0x41);               // Set text display width                文本区宽度 字节数/行
  71.    wr_td(width,0x00,0x43);               // Set graphics display width        图形区宽度 字节数/行
  72.    wr_comm(0x81);                        // Set display mode: text xor graphics         内部字符发生器有效
  73.    wr_td(0x56,0x00,0x22);                // Set CGRAM offset address   CGRAM偏置地址设置
  74.    wr_comm(0x9c);                        // Set text and graphic display on         文本显示启用 图形显示启用        光标禁止
  75. }

  76. /*------------Write data or command to LCD--------------*/
  77. void wr_od (uint8 dat,uint8 comm)       //write one byte data and one byte command        写单参指令
  78. { wr_data(dat);
  79.    wr_comm(comm);
  80. }

  81. void wr_td (uint8 datl,uint8 dath,uint8 comm)  //write two bytes data and one byte command        写双参指令通过两个char
  82. { wr_data(datl);
  83.    wr_data(dath);
  84.    wr_comm(comm);
  85. }

  86. void wr_xd (uint16 dat,uint8 comm)       //write a 16 bits data and one byte command        写双参指令通过一个int16
  87. { wr_data(dat);
  88.    wr_data(dat>>8);
  89.    wr_comm(comm);
  90. }

  91. void wr_auto (uint8 dat)               //Auto write        向当前地址追加一字节数据
  92. { chk_busy (1);
  93.    IO0CLR=cd;
  94.    IO0SET=rd;
  95.    IO0PIN=(IO0PIN&0XFFFFFF00|dat);
  96.    IO0CLR=wr;
  97.    IO0SET=wr;
  98. }

  99. void wr_comm (uint8 comm)       //write command          写一条指令  时序在这里实现
  100. { chk_busy (0);
  101.    IO0SET=cd;
  102.    IO0SET=rd;
  103.    IO0PIN=(IO0PIN&0XFFFFFF00|comm);
  104.    IO0CLR=wr;
  105.    IO0SET=wr;
  106. }

  107. void wr_data (uint8 dat)       //write data          写一字节数据
  108. { chk_busy (0);
  109.    IO0CLR=cd;
  110.    IO0SET=rd;
  111.    IO0PIN=(IO0PIN&0XFFFFFF00|dat);
  112.    IO0CLR=wr;
  113.    IO0SET=wr;
  114. }

  115. void chk_busy (uint8 autowr)    //test busy flag        获取LCD状态标记并等待LCD空闲
  116. { IO0SET=0xff;
  117.    IO0SET=cd;
  118.    IO0SET=wr;
  119.    IO0DIR &= 0xFFFFFF00;
  120.    IO0CLR=rd;
  121.    if(autowr)
  122.     { while((IO0PIN&bf3)==0);
  123.     }
  124.    else
  125.     { while((IO0PIN&bf0)==0||(IO0PIN&bf1)==0);
  126.     }
  127.    IO0SET=rd;
  128.    IO0DIR |= 0x000000FF;
  129. }

  130. /*--------------Clear RAM------------------*/         //清屏
  131. void clrram (void)
  132. { uint8 i,j;
  133.    wr_xd(addr_w,0x24);                //T6963C 指令        0x24:设置指针         0xb0:开始自动写          0xb2:退出自动写
  134.    wr_comm(0xb0);                                                              
  135.    for(j=0;j<144;j++)
  136.     { for(i=0;i<width;i++)
  137.          wr_auto(0x00);
  138.     }
  139.    wr_comm(0xb2);
  140. }

  141. /*--------------Display matrix------------------*/
  142. void disp_dz (uint8 data1,uint8 data2)         //两行交替绘图
  143. { uint8 i,j;
  144.    wr_xd(addr_t,0x24);
  145.    wr_comm(0xb0);
  146.    for(j=0;j<64;j++)                        //j控制绘制行数
  147.     { for(i=0;i<width;i++)
  148.          wr_auto(data1);
  149.       for(i=0;i<width;i++)
  150.          wr_auto(data2);
  151.     }
  152.    wr_comm(0xb2);
  153. }

  154. /*--------------Draw a (8*l)*yl picture at addr-------------*/
  155. void disp_img (uint8 addr,uint8 xl,uint8 yl,uint8 const *img)         //显示一副点阵图
  156. { uint8 i,j;
  157.    for(j=0;j<yl;j++)
  158.     { for(i=0;i<xl;i++)
  159.        { wr_xd(addr+0X100+j*width+i,0x24);                          //T6963C 指令        0x24:设置指针    0xc0: 数据一次写
  160.          wr_od(img[j*xl+i],0xc0);
  161.        }
  162.     }
  163. }

  164. /*----------Draw a Chinese character at addr----------*/  
  165. void disp_chn (uint16 addr,uint8 xl,uint8 yl,uint8 row_xl,uint8 row_yl,uint8 const  *chn) //显示一个汉字16*16
  166. { uint8 i,j,k,m;
  167.    for(m=0;m<row_yl;m++)
  168.     { for(k=0;k<row_xl;k++)
  169.        { for(j=0;j<yl;j++)
  170.           { for(i=0;i<xl;i++)
  171.              { wr_xd(addr+m*yl*width+k*xl+j*width+i,0x24);
  172.                wr_od(chn[(m*row_xl*xl*yl)+(k*xl*yl)+(j*xl)+i],0xc0);
  173.              }
  174.           }
  175.        }
  176.     }
  177. }

  178. /*--------------Draw string------------------*/
  179. void disp_eng (uint8 const *eng)
  180. { uint8 i,j;
  181.    wr_xd(addr_w,0x24);
  182.    wr_comm(0xb0);
  183.    for(j=0;j<10;j++)
  184.     { for(i=0;i<width;i++)
  185.          wr_auto(eng[j*width+i]);
  186.     }
  187.    wr_comm(0xb2);
  188. }

  189. /*----------Draw a Chinese character at position (x,y)----------*/
  190. void disp_hz(uint32 x,uint32 y,uint8  *str,uint8 size_str) //显示一个汉字字符串  size_str为中文字符的个数        X+1表示位移8点Y+1表示下移16点
  191. { uint8 i,j,n,c1,c2,slen,m=0;
  192.    uint32 tempx,tempy;
  193.    tempx=x;
  194.    tempy=y;
  195.    slen =size_str*2;//strlen((char const*)str);        原版程序的 strlen函数在运行时会卡死所以用一个SIZE参数来替代
  196.         while(m<slen-1)
  197.         {
  198.          c1=str[m+0];c2=str[m+1];
  199.       for(n=0;n<sizeof(GB_16)/sizeof(GB_16[0]);n++)
  200.        { if(c1 == GB_16[n].Index[0]&&c2 == GB_16[n].Index[1])
  201.          break;
  202.        }
  203.       y=tempy;
  204.       x=tempx;   
  205.       for(i=0;i<16;i++)
  206.        { for (j=0;j<2;j++)
  207.           { wr_xd((0x0100+256*y+width*i+x+j),0x24);
  208.             wr_od(GB_16[n].Msk[i*2+j],0xc0);   
  209.           }
  210.        }
  211.       m=m+2;//one Chinese charecter has two bytes, LCDSIZE/8

  212.       tempx += 2;
  213.       if(tempx>=width)
  214.        { tempx = 0;
  215.          tempy += 1;
  216.        }
  217.     }
  218. }

  219. /*----------Draw a character at position (x,y)----------*/
  220. void disp_zf(uint32 x,uint32 y,uint8 *str)                //显示英文字符串
  221. { char c;
  222.    wr_xd((addr_w+16*y+x),0x24);
  223.    wr_comm(0xb0);
  224.    while(*str!='\0')
  225.     { c = (*str);
  226.       wr_auto(c-32);
  227.       str++;
  228.     }
  229.    wr_comm(0xb2);
  230. }
复制代码



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:387410 发表于 2019-9-28 20:38 来自手机 | 只看该作者
最近在用,参考一下,优秀~
回复

使用道具 举报

板凳
ID:198286 发表于 2019-11-16 16:28 | 只看该作者
我在找240128的资料不过还是谢谢了
回复

使用道具 举报

地板
ID:288930 发表于 2020-2-14 10:49 | 只看该作者
请问这个屏怎么用,连接线都不知道怎么接!http://www.51hei.com/bbs/dpj-179796-1.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表