找回密码
 立即注册

QQ登录

只需一步,快速开始

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

LCD19264点阵屏怎样显示字符串?

[复制链接]
跳转到指定楼层
楼主
ID:965189 发表于 2024-6-25 11:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请教各位大侠,无字库的19264点阵屏,单个字符显示可以了,但是,显示字符串的函数不知道怎样写。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1109793 发表于 2024-6-25 16:39 | 只看该作者
一个一个顺序显示呗
回复

使用道具 举报

板凳
ID:366877 发表于 2024-6-25 16:41 | 只看该作者
能写一个字符就能写一串字符,无非就是for()语句控制而已。
回复

使用道具 举报

地板
ID:123289 发表于 2024-6-25 19:04 | 只看该作者
将程序写成F(x),分别用X1,X2,X3,X4... 代入F(x)多次重复运行。
回复

使用道具 举报

5#
ID:69038 发表于 2024-6-25 22:57 | 只看该作者
给你参考 一下:
  1. //***功能:显示一个ASCII字符,5*8字体 ;
  2. //*** x: 列坐标,0-191列,0-63,左屏,64-127,中屏,128-191,右屏        ;
  3. //*** y:行坐标,0~7页,真实地址是 start_page+row;
  4. //***ustr: 待显示字符;
  5. void lcd_show_char(uchar x,uchar y,uchar ustr)
  6. {
  7.     char i;
  8.         uchar temp;
  9.         uchar cs;
  10. ustr=ustr-' ';
  11.   for (i=0;i<6;i++)
  12.           {
  13.                 if(x<=63) cs=0;
  14.                 if(x>63 && x<=127) cs=1;
  15.                 if(x>127 ) cs=2;
  16.                 if (x>191) return;//列大于191,无效
  17.                 LCD_SendData(start_page+y,com,cs);
  18.                 LCD_SendData(start_column+x % 64,com,cs);
  19.             temp=dot5x8[ustr][i];
  20.                 temp=butterfly(temp);
  21.             LCD_SendData(temp,dat,cs);
  22.                 x++;
  23.           }
  24. }
  25. //***功能:显示一个ASCII的字符串,5*8字体 ;
  26. //*** x: 列坐标,0-191列,0-63,左屏,64-127,中屏,128-191,右屏        ;
  27. //*** y:行坐标,0~7页,真实地址是 start_page+row;
  28. //***ustr: 待显示字符串;
  29. void lcd_show_string(uchar x,uchar y,uchar *ustr)
  30. {

  31. if (y>=8) return; //页大于7,无效;
  32.           while(*ustr!='\0')
  33.         {      
  34.                 lcd_show_char(x,y,*ustr);
  35.                 x+=6;
  36.                 ustr++;
  37.         }  
  38. }
复制代码
调用:
  1.         lcd_show_string(50,0,"LCD_19264 DEMO ");
  2.         lcd_show_string(42,1,"Designed By zhuls");
  3.         lcd_show_string(0,2,"Show a string in LCD screen");
  4.         lcd_show_string(0,3,"if(col<=63) is left;");
  5.         lcd_show_string(0,4,"if(col>63 && col<=127) is middle");
  6.         lcd_show_string(0,5,"if(col>127 && col<=191) is right;");
  7.         lcd_show_string(0,6,"if(col>=192) display is invalid!!"); //
复制代码
最后一个“!”的X超限,不显示
如果没有“if (x>191) return;//列大于191,无效”这行,则最后一个“!”会返回所在屏的第一列显示,结果是乱码了。


回复

使用道具 举报

6#
ID:69038 发表于 2024-6-25 23:28 | 只看该作者
回复

使用道具 举报

7#
ID:965189 发表于 2024-6-26 08:41 | 只看该作者
zhuls 发表于 2024-6-25 22:57
给你参考 一下:
调用:最后一个“!”的X超限,不显示
如果没有“if (x>191) return;//列大于191,无效 ...

非常感谢你。我慢慢消化一下。有不明白的地方再向你请教。
回复

使用道具 举报

8#
ID:1129954 发表于 2024-7-31 16:01 | 只看该作者
zhuls 发表于 2024-6-25 22:57
给你参考 一下:
调用:最后一个“!”的X超限,不显示
如果没有“if (x>191) return;//列大于191,无效 ...

大佬,源码能分享一下吗。感谢
回复

使用道具 举报

9#
ID:69038 发表于 2024-8-2 07:01 | 只看该作者
柒月了吧 发表于 2024-7-31 16:01
大佬,源码能分享一下吗。感谢

可以,只是基本的显示:

  1. #include <STC8H.H>
  2. #include "5x8_dot.h"
  3. #include "HZFONT.h"
  4. #define uchar unsigned char
  5. #define uint  unsigned int

  6. #define DATABus P1
  7. #define CSBus P3
  8. sbit RS = P3^7;         //指令数据选择 =>pin4
  9. sbit RW = P3^6;         //读写控制          =>pin5
  10. sbit ENABLE  = P3^5;    //指令数据控制 =>pin6
  11. sbit Reset = P5^4;      //复位                  =>pin16

  12. sbit CS1 = P3^4;   //左屏幕选择,低电平有效        =>pin15
  13. sbit CS2 = P3^3;   //中屏幕选择                            =>pin17
  14. sbit CS3 = P3^2;   //右屏幕选择                                =>pin18


  15. #define start_line      0xC0    //起始行,可以用于图形上下滚动
  16. #define start_page      0xb8    //起始页
  17. #define start_column    0x40    //起始列
  18. #define display_on      0x3f    //显示开
  19. #define display_off     0x3e    //显示关

  20. #define screen_left     0    //左屏
  21. #define screen_mid      1    //左屏
  22. #define screen_right    2    //右屏

  23. #define com    0    //命令标志
  24. #define dat    1    //数据标志
  25. void LCD_Show_Chinese(uchar x,uchar y,uchar index);
  26. void lcd_show_string(uchar x,uchar y,uchar *ustr);
  27. void lcd_show_char(uchar x,uchar y,uchar ustr);
  28. void LCD_SendData(char data_byte,char data_type,char Screen);
  29. void LCD_Init();
  30. void LCD_Fill(uchar fill);
  31. void Delay1ms(unsigned int T);
  32. uchar butterfly(uchar byte) ;
  33. void test();
  34. void Delay1ms(unsigned int T)                        //延时1ms
  35. {
  36.     uchar j;
  37.         while (T)  
  38.     {
  39.         for (j=12;j>0;j--);
  40.     T--;
  41.         }
  42. }

  43. void main (void) //主程序
  44. {

  45.         P3M0 = 0x00; P3M1 = 0x00;
  46.     P1M0 = 0x00; P1M1 = 0x00;
  47.         P5M0 = 0x00; P5M1 = 0x00;
  48.         LCD_Init();   //LCD初始化
  49.         LCD_Fill(0);  //清屏
  50.         LCD_Show_Chinese(0,0,0);
  51.         LCD_Show_Chinese(16,0,1);
  52.         LCD_Show_Chinese(160,0,2);
  53.         LCD_Show_Chinese(176,0,3);
  54.         LCD_Show_Chinese(168,2,4);


  55.         lcd_show_string(50,0,"LCD_19264 DEMO ");
  56.         lcd_show_string(42,1,"Designed By zhuls");
  57.         lcd_show_string(0,2,"Show a string in LCD screen");
  58.         lcd_show_string(0,3,"if(col<=63) is left;");
  59.         lcd_show_string(0,4,"if(col>63 && col<=127) is middle");
  60.         lcd_show_string(0,5,"if(col>127 && col<=191) is right");
  61.         lcd_show_string(0,6,"if(col>=192) display is invalid!!");

  62. while(1)//主循环
  63. {
  64.     test();
  65. }
  66. }
  67. //***********************************************
  68. //一次送一个字节数据,存于data_byte//
  69. //数据类型由data_type决定,为1是数据,为0是命令
  70. //左中右屏选择由screen决定,为0是左屏,为1是中屏,为2是右屏
  71. //
  72. //*******************************************

  73. void LCD_SendData(char data_byte,char data_type,char Screen)//
  74. {
  75. switch (Screen)//screen为0是左屏,为1是中屏,为2是右屏
  76. {
  77. case 0: CS1=0;CS2=1;CS3=1;break;
  78. case 1: CS1=1;CS2=0;CS3=1;break;
  79. case 2: CS1=1;CS2=1;CS3=0;break;
  80. }
  81.         RW=0;
  82.     RS=data_type;
  83.         DATABus=data_byte;
  84.     Delay1ms(1);
  85.            ENABLE=1;
  86.     Delay1ms(1);
  87.         ENABLE=0;
  88.     Delay1ms(1);
  89. }

  90. //*******************************************
  91. //初始化LCD
  92. //******************************************
  93. void LCD_Init()       
  94. {
  95.         char Screen;
  96.          Delay1ms(10);
  97.         for (Screen=0;Screen<3;Screen++)
  98.         {
  99.     LCD_SendData(display_on,com,Screen);//开显示
  100.            }
  101. }
  102. //*******************************************
  103. //填充数据FILL,
  104. //fill是要填充的数据
  105. //******************************************
  106. void LCD_Fill(uchar fill)
  107. {
  108.         char column,page;
  109.         char Screen;
  110.         for (Screen=0;Screen<3;Screen++)//0是左屏,1是中屏,2是右屏
  111.         {
  112.           for (page=0;page<8;page++)                        //清屏
  113.           {
  114.             LCD_SendData(start_page+page,com,Screen);//清屏
  115.                 LCD_SendData(start_column,com,Screen);//定位到0列
  116.                 for (column=0;column<64;column++)
  117.                 {
  118.                         LCD_SendData(fill,dat,Screen);
  119.                 }
  120.           }  
  121.     }
  122. }
  123. //*******************************************************
  124. // 一个字节中的8bit高低互换,
  125. //bit0=bit7,bit1=bit6...bit6=bit1,bit7=bit0
  126. //蝶形算法
  127. uchar butterfly(uchar byte)
  128. {
  129.   uchar half_h,half_l;
  130.   half_h= (byte & 0x55)<<1;
  131.   half_l= (byte & 0xAA)>>1;
  132.   byte=half_h | half_l;
  133.   half_h= (byte & 0x33)<<2;
  134.   half_l= (byte & 0xcc)>>2;
  135.   byte=half_h | half_l;
  136.   half_h= (byte & 0x0f)<<4;
  137.   half_l= (byte & 0xf0)>>4;
  138.   byte=half_h | half_l;
  139.   return byte;
  140. }
  141. //测试显示
  142. void test()
  143. {
  144.   uchar i,j;

  145.   for (j=0;j<3;j++)
  146.   {
  147.          LCD_SendData(start_page+7,com,j);
  148.          LCD_SendData(start_column,com,j);
  149.   for (i=0;i<32;i++)
  150.     {
  151.      LCD_SendData(0x55,dat,j);
  152.      LCD_SendData(0xaa,dat,j);
  153.           Delay1ms(10000);
  154.         }
  155. }       
  156.     Delay1ms(50000);
  157. for(j=0;j<3;j++)
  158.         {
  159.          LCD_SendData(start_page+7,com,j);
  160.          LCD_SendData(start_column,com,j);
  161. for (i=0;i<64;i++)
  162.     {
  163.      LCD_SendData(0xff,dat,j);
  164.          Delay1ms(5000);
  165.         }
  166.         }
  167. }
  168. //***功能:显示一个ASCII,5*8字体 ;
  169. //*** x: 列坐标,0-191列,0-63,左屏,64-127,中屏,128-191,右屏        ;
  170. //*** y:行坐标,0~7页,真实地址是 start_page+row;
  171. //***ustr: 待显示字符;

  172. void lcd_show_char(uchar x,uchar y,uchar ustr)
  173. {
  174.     char i;
  175.         uchar temp;
  176.         uchar cs;
  177. if (y>=8) return; //页大于7,无效;
  178.    ustr=ustr-' ';
  179.   for (i=0;i<6;i++)
  180.           {
  181.                 if(x<=63) cs=0;
  182.                 if(x>63 && x<=127) cs=1;
  183.                 if(x>127 ) cs=2;
  184.                 if (x>191) return;//列大于191,无效
  185.                 LCD_SendData(start_page+y,com,cs);
  186.                 LCD_SendData(start_column+x % 64,com,cs);
  187.             temp=dot5x8[ustr][i];
  188.                 temp=butterfly(temp);
  189.             LCD_SendData(temp,dat,cs);
  190.                 x++;
  191.           }
  192. }
  193. //***功能:显示一个ASCII的字符串,5*8字体 ;
  194. //*** x: 列坐标,0-191列,0-63,左屏,64-127,中屏,128-191,右屏        ;
  195. //*** y:行坐标,0~7页,真实地址是 start_page+row;
  196. //***ustr: 待显示字符串;
  197. void lcd_show_string(uchar x,uchar y,uchar *ustr)
  198. {

  199.           while(*ustr!='\0')
  200.         {      
  201.                 lcd_show_char(x,y,*ustr);
  202.                 x+=6;
  203.                 ustr++;
  204.         }  
  205. }
  206. /******************************************************************************
  207.       函数说明:显示单个16x16汉字
  208.       入口数据:x,y显示坐标
  209.                 index 要显示的汉字索引
  210.       返回值:  无
  211. ******************************************************************************/
  212. void LCD_Show_Chinese(uchar x,uchar y,uchar index)
  213. {
  214.   uchar i,temp,cs;
  215.   
  216.    for (i=0;i<16;i++)
  217.           {
  218.                 if(x<=63) cs=0;
  219.                 if(x>63 && x<=127) cs=1;
  220.                 if(x>127 ) cs=2;
  221.                 if (x>191) return;//列大于191,无效
  222.                 LCD_SendData(start_page+y,com,cs);
  223.                 LCD_SendData(start_column+x % 64,com,cs);
  224.             temp=font16[index][i*2];
  225.             LCD_SendData(temp,dat,cs);
  226.                 LCD_SendData(start_page+y+1,com,cs);
  227.                 LCD_SendData(start_column+x % 64,com,cs);
  228.             temp=font16[index][i*2+1];
  229.             LCD_SendData(temp,dat,cs);
  230.                 x++;
  231.          }                                         
  232. }

复制代码
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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