找回密码
 立即注册

QQ登录

只需一步,快速开始

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

求教各位51单片机连接的LCD12864怎么从右到左滚动显示汉字

[复制链接]
跳转到指定楼层
楼主
ID:275815 发表于 2018-1-14 23:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我用取字模的方法在屏幕上输出了四行八列汉字,想请教下各位怎么从右往左滚动显示汉字,谢谢
  1. #include <reg51.h>
  2. #define  uchar  unsigned char
  3. #define  uint  unsigned int
  4. #define LCDLCDDisp_Off   0x3e
  5. #define LCDLCDDisp_On    0x3f
  6. #define Page_Add     0xb8//ye
  7. #define LCDCol_Add     0x40//lie
  8. #define Start_Line     0xC0//hang
  9. /*****液晶显示器的端口定义*****/
  10. #define data_ora P0 /*液晶数据总线*/
  11. sbit LCDMcs=P2^4 ;    /*片选1*/
  12. sbit LCDScs=P2^3 ;    /*片选2*/
  13. sbit LCDDi=P2^2 ;     /*数据/指令 选择*/
  14. sbit LCDRW=P2^1 ;     /*读/写 选择*/
  15. sbit LCDEnable=P2^0 ;     /*读/写 使能*/
  16. uchar code hz1[]=
  17. {
  18. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  19. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  20. /*------------------------------------------------------------------------------
  21.   源文件 / 文字 : 武
  22.   宽×高(像素): 16×16
  23.   字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/32字节
  24.   数据转换日期  : 2010-7-31 15:50:18
  25. ------------------------------------------------------------------------------*/
  26. 0x20,0x20,0x24,0x24,0x24,0xA4,0x24,0x24,0x20,0xFF,0x20,0x22,0x2C,0x20,0x20,0x00,
  27. 0x40,0xC0,0x7E,0x40,0x40,0x3F,0x22,0x22,0x20,0x03,0x0C,0x10,0x20,0x40,0xF8,0x00,
  28. /*------------------------------------------------------------------------------
  29.   源文件 / 文字 : 汉
  30.   宽×高(像素): 16×16
  31.   字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/32字节
  32.   数据转换日期  : 2010-7-31 15:51:45
  33. ------------------------------------------------------------------------------*/
  34. 0x10,0x60,0x02,0x0C,0xC0,0x02,0x1E,0xE2,0x02,0x02,0x02,0xE2,0x1E,0x00,0x00,0x00,
  35. 0x04,0x04,0x7C,0x03,0x80,0x80,0x40,0x20,0x13,0x0C,0x13,0x20,0x40,0x80,0x80,0x00,
  36. /*------------------------------------------------------------------------------
  37.   源文件 / 文字 : 理
  38.   宽×高(像素): 16×16
  39.   字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/32字节
  40.   数据转换日期  : 2010-7-31 15:52:29
  41. ------------------------------------------------------------------------------*/
  42. 0x04,0x84,0x84,0xFC,0x84,0x84,0x00,0xFE,0x92,0x92,0xFE,0x92,0x92,0xFE,0x00,0x00,
  43. 0x20,0x60,0x20,0x1F,0x10,0x10,0x40,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x40,0x00,
  44. /*------------------------------------------------------------------------------
  45.   源文件 / 文字 : 工
  46.   宽×高(像素): 16×16
  47.   字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/32字节
  48.   数据转换日期  : 2010-7-31 15:53:19
  49. ------------------------------------------------------------------------------*/
  50. 0x00,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x00,0x00,
  51. 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,

  52. /*------------------------------------------------------------------------------
  53.   源文件 / 文字 : 大
  54.   宽×高(像素): 16×16
  55.   字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/32字节
  56.   数据转换日期  : 2010-7-31 15:53:53
  57. ------------------------------------------------------------------------------*/
  58. 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
  59. 0x80,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,0x80,0x00,

  60. /*------------------------------------------------------------------------------
  61.   源文件 / 文字 : 学
  62.   宽×高(像素): 16×16
  63.   字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/32字节
  64.   数据转换日期  : 2010-7-31 15:54:23
  65. ------------------------------------------------------------------------------*/
  66. 0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00,
  67. 0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,0x06,0x05,0x04,0x04,0x04,0x04,0x04,0x00,

  68. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  70. };
  71. uchar code hz2[]=
  72. {
  73. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  75. /*--  文字:  信  --*/
  76. /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  77. 0x00,0x80,0x60,0xF8,0x07,0x00,0x04,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x04,0x00,
  78. 0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0xF9,0x49,0x49,0x49,0x49,0x49,0xF9,0x00,0x00,

  79. /*--  文字:  息  --*/
  80. /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  81. 0x00,0x00,0x00,0xFC,0x54,0x54,0x56,0x55,0x54,0x54,0x54,0xFC,0x00,0x00,0x00,0x00,
  82. 0x40,0x30,0x00,0x03,0x39,0x41,0x41,0x45,0x59,0x41,0x41,0x73,0x00,0x08,0x30,0x00,

  83. /*--  文字:  工  --*/
  84. /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  85. 0x00,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x00,0x00,
  86. 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,

  87. /*--  文字:  程  --*/
  88. /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  89. 0x24,0x24,0xA4,0xFE,0x23,0x22,0x00,0x3E,0x22,0x22,0x22,0x22,0x22,0x3E,0x00,0x00,
  90. 0x08,0x06,0x01,0xFF,0x01,0x06,0x40,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x41,0x00,

  91. /*--  文字:  学  --*/
  92. /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  93. 0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00,
  94. 0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,0x06,0x05,0x04,0x04,0x04,0x04,0x04,0x00,

  95. /*--  文字:  院  --*/
  96. /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  97. 0x00,0xFE,0x22,0x5A,0x86,0x10,0x0C,0x24,0x24,0x25,0x26,0x24,0x24,0x14,0x0C,0x00,
  98. 0x00,0xFF,0x04,0x08,0x07,0x80,0x41,0x31,0x0F,0x01,0x01,0x3F,0x41,0x41,0x71,0x00,

  99. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  100. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  101. };
  102. uchar code hz3[]=
  103. {
  104. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  105. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  106. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  107. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  108. /*--  文字:  通  --*/
  109. /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  110. 0x40,0x42,0xCC,0x00,0x00,0xE2,0x22,0x2A,0x2A,0xF2,0x2A,0x26,0x22,0xE0,0x00,0x00,
  111. 0x80,0x40,0x3F,0x40,0x80,0xFF,0x89,0x89,0x89,0xBF,0x89,0xA9,0xC9,0xBF,0x80,0x00,

  112. /*--  文字:  信  --*/
  113. /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  114. 0x00,0x80,0x60,0xF8,0x07,0x00,0x04,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x04,0x00,
  115. 0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0xF9,0x49,0x49,0x49,0x49,0x49,0xF9,0x00,0x00,

  116. /*--  文字:  工  --*/
  117. /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  118. 0x00,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x00,0x00,
  119. 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,

  120. /*--  文字:  程  --*/
  121. /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  122. 0x24,0x24,0xA4,0xFE,0x23,0x22,0x00,0x3E,0x22,0x22,0x22,0x22,0x22,0x3E,0x00,0x00,
  123. 0x08,0x06,0x01,0xFF,0x01,0x06,0x40,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x41,0x00,

  124. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  125. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  126. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  127. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  128. };
  129. uchar code hz4[]=
  130. {

  131. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  132. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  133. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  134. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  135. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  136. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  137. /*--  文字:  许  --*/
  138. /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  139. 0x40,0x40,0x42,0xCC,0x00,0x00,0x20,0x18,0x0F,0x08,0xF8,0x08,0x08,0x08,0x00,0x00,
  140. 0x00,0x00,0x00,0x7F,0x20,0x10,0x01,0x01,0x01,0x01,0xFF,0x01,0x01,0x01,0x01,0x00,

  141. /*--  文字:  萍  --*/
  142. /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  143. 0x44,0x84,0x14,0x64,0x0F,0x24,0xA4,0x24,0x24,0xE4,0x2F,0x24,0xA4,0x24,0x04,0x00,
  144. 0x08,0x09,0x78,0x04,0x03,0x04,0x04,0x05,0x04,0xFF,0x04,0x05,0x04,0x04,0x04,0x00,
  145. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  146. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  147. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  148. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  149. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  150. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

  151. };
  152. /****************************************************************************
  153. 函数功能:LCD延时程序
  154. 入口参数:t
  155. 出口参数:
  156. ****************************************************************************/
  157. void LCDdelay(uchar x)
  158. {


  159.    int d;
  160.    uchar y;
  161.    for(y=0;y<x;y++)
  162.    for(d=0;d<10;d++);
  163. }
  164. /****************************************************************************
  165. 状态检查,LCD是否忙


  166. *****************************************************************************/
  167. void CheckState()               
  168. {
  169.    uchar dat,DATA;//状态信息(判断是否忙)
  170.    LCDDi=0; // 数据\指令选择,D/I(RS)="L" ,表示 DB7∽DB0 为显示指令数据
  171.    LCDRW=1; //R/W="H" ,E="H"数据被读到DB7∽DB0
  172.    do
  173.    {
  174.       DATA=0x00;
  175.       LCDEnable=1;        //EN下降源
  176.           LCDdelay(1);//延时
  177.           dat=DATA;
  178.       LCDEnable=0;
  179.       dat=0x80 & dat; //仅当第7位为0时才可操作(判别busy信号)
  180.     }
  181.     while(!(dat==0x00));
  182. }
  183. /*****************************************************************************
  184. 函数功能:写命令到LCD程序,RS(DI)=L,RW=L,EN=H,即来一个脉冲写一次
  185. 入口参数:cmdcode
  186. 出口参数:
  187. *****************************************************************************/
  188. void write_com(uchar cmdcode)
  189. {
  190.     CheckState();//检测LCD是否忙
  191.         LCDDi=0;
  192.         LCDRW=0;
  193.         P1=cmdcode;               
  194.         LCDdelay(1);
  195.         LCDEnable=1;
  196.         LCDdelay(1);
  197.         LCDEnable=0;
  198. }

  199. /*****************************************************************************
  200. 函数功能:写数据到LCD程序,RS(DI)=H,RW=L,EN=H,即来一个脉冲写一次
  201. 入口参数:LCDDispdata
  202. 出口参数:
  203. *****************************************************************************/
  204. void write_data(uchar LCDDispdata)
  205. {
  206.     CheckState();//检测LCD是否忙
  207.         LCDDi=1;
  208.         LCDRW=0;
  209.         P1=LCDDispdata;
  210.         LCDdelay(1);
  211.         LCDEnable=1;
  212.         LCDdelay(1);
  213.         LCDEnable=0;
  214. }
  215. /*****************************************************************************
  216. /*****************************************************************************
  217. 函数功能:LCD初始化程序
  218. 入口参数:
  219. 出口参数:
  220. *****************************************************************************/
  221. void init_lcd()
  222. {
  223.         LCDdelay(1);        
  224.         LCDMcs=1;//刚开始关闭两屏
  225.         LCDScs=1;
  226.         LCDdelay(1);
  227.         write_com(LCDLCDDisp_Off);         //写初始化命令
  228.         write_com(Page_Add+0);
  229.         write_com(Start_Line+0);
  230.         write_com(LCDCol_Add+0);
  231.         write_com(LCDLCDDisp_On);
  232. }
  233. /**************************************************************************
  234. 函数功能:清除LCD内存程序
  235. 入口参数:pag,col,hzk
  236. 出口参数:
  237. *****************************************************************************/
  238. void Clr_Scr()
  239. {
  240.         uchar j,k;
  241.         LCDMcs=0; //左、右屏均开显示
  242.         LCDScs=0;
  243.          write_com(Page_Add+0);
  244.          write_com(LCDCol_Add+0);
  245.          for(k=0;k<8;k++)//控制页数0-7,共8页
  246.          {
  247.                 write_com(Page_Add+k); //每页每页进行写
  248.                   for(j=0;j<64;j++)  //每页最多可写32个中文文字或64个ASCII字符
  249.                 {
  250.                       write_com(LCDCol_Add+j);
  251.                         write_data(0x00);//控制列数0-63,共64列,写点内容,列地址自动加1
  252.                 }
  253.         }
  254. }
  255. /*****************************************************************************
  256. 函数功能:一行一行显示
  257. 入口参数:page,column,hzk
  258. 出口参数:
  259. *****************************************************************************/
  260. Disp(uchar page,uchar column, uchar code *word)
  261. {
  262. uchar i;
  263. //左屏
  264. LCDMcs=0;
  265. LCDScs=1;
  266. //上半字
  267. write_com(0xb8|page);
  268. write_com(0x40|column);
  269. for(i=0;i<16;i++)
  270. write_data(word[i]);
  271. for(i=32;i<48;i++)
  272. write_data(word[i]);
  273. for(i=64;i<80;i++)
  274. write_data(word[i]);
  275. for(i=96;i<112;i++)
  276. write_data(word[i]);
  277. //下半字
  278. write_com(0xb8|page+1);
  279. write_com(0x40|column);
  280. for(i=16;i<32;i++)
  281. write_data(word[i]);
  282. for(i=48;i<64;i++)
  283. write_data(word[i]);
  284. for(i=80;i<96;i++)
  285. write_data(word[i]);
  286. for(i=112;i<128;i++)
  287. write_data(word[i]);
  288. //右屏
  289. LCDMcs=1;
  290. LCDScs=0;
  291. //上半字
  292. write_com(0xb8|page);
  293. write_com(0x40);
  294. for(i=128;i<144;i++)
  295. write_data(word[i]);
  296. for(i=160;i<176;i++)
  297. write_data(word[i]);
  298. for(i=192;i<208;i++)
  299. write_data(word[i]);
  300. for(i=224;i<240;i++)
  301. write_data(word[i]);
  302. //下半字
  303. write_com(0xb8|page+1);
  304. write_com(0x40);
  305. for(i=144;i<160;i++)
  306. write_data(word[i]);
  307. for(i=176;i<192;i++)
  308. write_data(word[i]);
  309. for(i=208;i<224;i++)
  310. write_data(word[i]);
  311. for(i=240;i<250;i++)
  312. write_data(word[i]);
  313. }

  314. void main()
  315. {
  316. uint k=0;
  317.         init_lcd();
  318.         Clr_Scr();
  319.      k=0;
  320.       for(k=0xc0;k<0xff;k++)
  321.         {
  322.                  Disp(0,0,hz1);
  323.                  Disp(2,0,hz2);
  324.                  Disp(4,0,hz3);
  325.                  Disp(6,0,hz4);
  326.          LCDMcs=0;
  327.          LCDScs=0;
  328.                  write_com(k);
  329.                  LCDdelay(2);

  330.         }
  331. while(1)
  332.     {

  333.         }
  334. }
复制代码



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

使用道具 举报

沙发
ID:7485 发表于 2018-1-15 15:35 | 只看该作者
本帖最后由 ahshmj 于 2018-1-15 15:40 编辑

我原来用汇编语言做了一个19264向左滚动显示的。估计程序对你有点不适用。

滚动显示的硬件:1、ks0108控制器的LCD(楼主的可以)
                        2、根据显示内容的数据量,应有足够的RAM,如片内不足,可以外挂。
编程的思路是(滚动显示内容不固定):将要滚动显示的汉字字模先逐字节读出再写入RAM暂存,汉字上下部分分别读写(RAM块的分配根据自己的情况,)。然后送显示,每扫描一遍(或N遍,根据滚动的速度要求,来确定N)“显示子程序”送显示的数据在RAM中的首地址加1,尾接头顺序循环送显示。
      不知道你能不能看明白,这样确实很难叙述的明白。但是如果实际做起来就会明白。
回复

使用道具 举报

板凳
ID:265426 发表于 2018-2-2 19:22 | 只看该作者
楼主的程序是滚动的吗?我学习下
回复

使用道具 举报

地板
ID:233487 发表于 2018-2-2 19:39 | 只看该作者
就是显示,清除,移动位置,显示,清除,移动位置,显示的过程
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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