找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

单片机+lcd12864部分显示乱码

查看数: 3466 | 评论数: 13 | 收藏 1
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2020-10-2 21:02

正文摘要:

芯片:AT89S52 实验台:亚龙YL-236型单片机控制功能实训考核装置 (刚开始学.师傅也不会) 部分显示乱码. 我是按照书上的程序弄的.然后在之前也是同一个程序但只能显示字模里面的前十个汉字. 超这个范围 ...

回复

ID:822775 发表于 2021-10-11 18:29
LCD12864都不会用,看不懂
ID:831736 发表于 2021-10-11 16:58
void disp1(uchar x,y,x1,y1,line,rom,uchar *str)
{
uchar a,b,c,d,e;
wr_lcd(0,0x3f);
for(a=0;a<line;a++)
  {
    for(b=0;b<rom;b++)
    {
       for(c=0;c<x1;c++)
           {
                wr_lcd(0,0xb8+x+a*x1+c);
                wr_lcd(0,0xc0);
                wr_lcd(0,0x40+y+b*y1);
                d=a*x1*y1*rom+b*x1*y1+c*y1;
                  for(e=0;e<y1;e++)
                  {
                  wr_lcd(1,~str[d+e]);
                  }
           }
    }
  }
}
打脸!程序有点小问题,把上面那个void disp(---)改成这个
ID:831736 发表于 2021-10-11 15:51
void wr_lcd(uchar a,b)
{
rs=a;
rw=0;
en=1;
P0=b;
en=0;
}
void disp(uchar x,y,x1,y1,line,rom,uchar *str)
{
uchar a,b,c,d,e;
wr_lcd(0,0x3f);
for(a=0;a<line;a++)
  {
    for(b=0;b<rom;b++)
    {
       for(c=0;c<x1;c++)
           {
                wr_lcd(0,0xb8+x+a*x1+c);
                wr_lcd(0,0xc0);
                wr_lcd(0,0x40+y+b*y1);
                d=a*x1*y1*rom+b*x1*y1+c*y1;
                  for(e=0;e<y1;e++)
                  {
                  wr_lcd(1,str[d+e]);
                  }
           }
    }
  }
}
void qpin()
{
static uchar a,b;
for(a=0;a<8;a++)
  {
  for(b=0;b<64;b++)
    {
        cs1=cs2=1;
        disp(a,b,1,1,1,1,0x00);
        }
  }
}
void tpxsh()
{
  cs1=1;cs2=0;
  disp1(0,0,1,64,1,1,tp1);
  disp1(1,0,1,64,1,1,tp1+64*2);
  disp1(2,0,1,64,1,1,tp1+64*4);
  disp1(3,0,1,64,1,1,tp1+64*6);
  disp1(4,0,1,64,1,1,tp1+64*8);
  disp1(5,0,1,64,1,1,tp1+64*10);
  disp1(6,0,1,64,1,1,tp1+64*12);
  disp1(7,0,1,64,1,1,tp1+64*14);
   cs1=0;cs2=1;
  disp1(0,0,1,64,1,1,tp1+64);
  disp1(1,0,1,64,1,1,tp1+64*3);
  disp1(2,0,1,64,1,1,tp1+64*5);
  disp1(3,0,1,64,1,1,tp1+64*7);
  disp1(4,0,1,64,1,1,tp1+64*9);
  disp1(5,0,1,64,1,1,tp1+64*11);
  disp1(6,0,1,64,1,1,tp1+64*13);
  disp1(7,0,1,64,1,1,tp1+64*15);
}
uchar code tp1[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0xF0,0xF8,
0xFC,0xFC,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFC,0xFC,0xF8,0xF0,0x60,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0xE0,0xF0,0xF8,0xFC,0xFC,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFC,0xFC,0xF8,
0xF0,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x0F,0x07,0x03,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x03,0x07,0x0F,0x3F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x0F,0x1F,
0x3F,0x7F,0xFF,0x7F,0x1F,0x07,0x01,0x00,0x00,0x00,0x00,0x60,0x62,0x34,0x1C,0x1C,
0x9C,0xBC,0xF8,0x78,0x70,0x70,0x60,0x20,0x08,0x00,0x30,0x38,0x30,0x30,0x78,0xF8,
0xFC,0x1C,0x1C,0x1C,0x14,0x36,0x76,0x66,0x66,0x64,0x64,0xE8,0x68,0x60,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x1F,0xFF,0xFF,0x7F,0x3F,0x1F,
0x0F,0x07,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81,0x83,
0x41,0x21,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x61,0x43,0xC3,0x82,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x59,0x9D,0x0C,0x04,
0x82,0x83,0x82,0x82,0x86,0x86,0x84,0x84,0x84,0x8C,0xBC,0x94,0x86,0x86,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0xC3,0x42,0x6E,0x1C,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x1F,0x1F,0x00,
0x00,0x08,0x19,0x31,0x61,0x61,0x61,0x60,0x60,0x60,0x61,0x21,0x10,0x00,0x00,0x0C,
0x0C,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xFE,0xFF,0xFF,
0xFE,0xF8,0xF0,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0xE0,0xF0,0xF8,0xFE,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFE,0xFC,0xFC,
0xF8,0xF8,0xF8,0xF8,0xF0,0xF0,0xF0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,
0xE0,0xE0,0xE0,0xE0,0xE0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF8,0xF8,0xF8,0xF8,0xFC,0xFC,
0xFC,0xFE,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
自己去定义端口,我写得有点简单

评分

参与人数 1黑币 +20 收起 理由
admin + 20 回帖助人的奖励!

查看全部评分

ID:970554 发表于 2021-10-8 16:21
楼组,乱码的问题解决了吗
ID:970554 发表于 2021-10-8 16:21
楼主,12864乱码的问题解决了吗
ID:808634 发表于 2020-10-9 07:59
根据12864型号查找相应资料,并根据真值表查找相应错误
ID:88256 发表于 2020-10-8 23:58
嗯哼哼? 发表于 2020-10-8 20:02
不行啊..你有qq嘛.我加一下.

先把资料找出来啊
ID:825326 发表于 2020-10-8 20:02
hhdsdy 发表于 2020-10-4 21:37
试得怎么样?有这款12864的资料吗?

不行啊..你有qq嘛.我加一下.
ID:88256 发表于 2020-10-4 21:37

试得怎么样?有这款12864的资料吗?
ID:825326 发表于 2020-10-3 15:25
hhdsdy 发表于 2020-10-2 22:37
从画面来看,不是你说的“只能显示字模里面的前十个汉字.超这个范围就乱码”,画面上比较正常显示的只有“ ...

好的我在试试
ID:825326 发表于 2020-10-3 12:12
angmall 发表于 2020-10-3 09:27
给你改了一下试试。

铁子.不显示了.没图象辽
ID:155507 发表于 2020-10-3 09:27
给你改了一下试试。

  1. #include <REG52.H>
  2. #define        uint unsigned int
  3. #define        uchar unsigned char
  4. //12864引脚定义
  5. #define lcdDat P0  /* LCD12864 数据线 */
  6. sbit rst=P1^0;
  7. sbit cs2=P1^1;    //片选1低电平有效,控制右半屏
  8. sbit cs1=P1^2;    //片选1低电平有效,控制左半屏
  9. sbit e=P1^3;      //使能端
  10. sbit rw=P1^4;     //RW为1---写;0---读
  11. sbit rs=P1^5;     //RS为0---命令;1----数据

  12. /** LCM忙检测 **/
  13. void busy12864(){
  14.         lcdDat=0xff;    //口线置1,防止干扰
  15.         rs=0;
  16.         rw=1;           //置“命令、读”模式
  17.         e=1;
  18.         while(lcdDat&0x80);
  19.         e=0;//忙等待
  20. }
  21. /** 写命令 参数:comDat为要发送的命令 **/
  22. void Writecom(uchar com){  
  23.         busy12864();                     //忙,则等待
  24.         rs=0;
  25.         rw=0;                            //置“命令、写”模式
  26.         lcdDat=com;
  27.         e=1;
  28.         e=0;//送出命令,并使之有效
  29. }
  30. /** 写数据 参数:dat为要发送的数据 **/
  31. void Writedat(uchar dat){  
  32.         busy12864();                           //忙,则等待
  33.         rs=1;
  34.         rw=0;                                  //置“数据、写”模式
  35.         lcdDat=dat;
  36.         e=1;
  37.         e=0;        //送出数据,并使之有效
  38. }
  39. //清屏函数
  40. void clrLCD(){
  41.         uchar i,j;
  42.         cs1=cs2=0;                           //同时选中左右屏
  43.         for(i=0;i<8;i++)
  44.         {           //共8页
  45.                 Writecom(0xB8+i);  //光标到i页
  46.                 Writecom(0x40);           //光标到页首
  47.                 for(j=0;j<64;j++)
  48.                 {
  49.                         Writedat(0); //写0清屏
  50.                 }
  51.         }
  52. }
  53. /** 初始化12864 **/
  54. void Init12864(){
  55.         lcdDat=0xff;   //口线置1,防止干扰
  56.         rs=0;
  57.         rw=1;          //置“命令、读”模式
  58.         cs1=cs2=0;     //同时选中左右屏
  59.         e=1;
  60.         while(lcdDat&0x10);
  61.         e=0;//等待复位完成
  62.         Writecom(0x3f);          //开显示
  63.         Writecom(0xc0);          //设置显示起始行
  64.         clrLCD();                  //清屏
  65. }
  66. uchar code ywzc[]="ABC"; //索引字串
  67. uchar code ywzm[][16]={         //字串字模
  68.         /*--  文字:  A  --*/
  69.         /*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
  70.         0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,

  71.         /*--  文字:  B  --*/
  72.         /*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
  73.         0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,

  74.         /*--  文字:  C  --*/
  75.         /*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
  76.         0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,

  77. };
  78. uchar code hzzc[]="一二三四五六七八九十当前工步";//字串索引
  79. uchar code hzzm[][32]={  //字串字模
  80.         /*--  文字:  一  --*/
  81.         /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  82.         0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
  83.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  84.         /*--  文字:  二  --*/
  85.         /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  86.         0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00,
  87.         0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,

  88.         /*--  文字:  三  --*/
  89.         /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  90.         0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,
  91.         0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,

  92.         /*--  文字:  四  --*/
  93.         /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  94.         0x00,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00,
  95.         0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,0x00,0x00,

  96.         /*--  文字:  五  --*/
  97.         /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  98.         0x00,0x02,0x42,0x42,0x42,0xC2,0x7E,0x42,0x42,0x42,0x42,0xC2,0x02,0x02,0x00,0x00,
  99.         0x40,0x40,0x40,0x40,0x78,0x47,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x00,

  100.         /*--  文字:  六  --*/
  101.         /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  102.         0x20,0x20,0x20,0x20,0x20,0x20,0x21,0x22,0x2C,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
  103.         0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x01,0x02,0x04,0x18,0x60,0x00,0x00,

  104.         /*--  文字:  七  --*/
  105.         /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  106.         0x80,0x80,0x80,0x80,0x80,0x40,0xFF,0x40,0x40,0x40,0x20,0x20,0x20,0x20,0x00,0x00,
  107.         0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x40,0x40,0x78,0x00,0x00,

  108.         /*--  文字:  八  --*/
  109.         /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  110.         0x00,0x00,0x00,0x00,0x00,0xFC,0x00,0x00,0x00,0x7E,0x80,0x00,0x00,0x00,0x00,0x00,
  111.         0x00,0x80,0x60,0x18,0x07,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x30,0x40,0x80,0x00,

  112.         /*--  文字:  九  --*/
  113.         /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  114.         0x00,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00,0x00,0x00,
  115.         0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x78,0x00,

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

  120.         /*--  文字:  当  --*/
  121.         /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  122.         0x00,0x40,0x42,0x44,0x58,0x40,0x40,0x7F,0x40,0x40,0x50,0x48,0xC6,0x00,0x00,0x00,
  123.         0x00,0x40,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFF,0x00,0x00,0x00,

  124.         /*--  文字:  前  --*/
  125.         /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  126.         0x08,0x08,0xE8,0x29,0x2E,0x28,0xE8,0x08,0x08,0xC8,0x0C,0x0B,0xE8,0x08,0x08,0x00,
  127.         0x00,0x00,0xFF,0x09,0x49,0x89,0x7F,0x00,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00,0x00,

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

  132.         /*--  文字:  步  --*/
  133.         /*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
  134.         0x40,0x40,0x40,0x7C,0x40,0x40,0x40,0xFF,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,
  135.         0x80,0x90,0x88,0x46,0x40,0x40,0x20,0x2F,0x10,0x10,0x08,0x04,0x02,0x00,0x00,0x00,


  136. };


  137. /******** 任意尺寸点阵显示函数 ***********|
  138. |参数:显示位置:row页数,col列号,                  |
  139. |           字符大小:x横向像素,y纵向页数          |
  140. |           显示内容:tab字模表          ******/
  141. void showXY(uchar row,uchar col,uchar x,uchar y,uchar *tab)
  142. {
  143.         uchar i,j;
  144.         bit right;
  145.         if(col<64){right=0;} //置左右屏标志
  146.         else {col-=64;right=1;}        
  147.         for(i=0;i<y;i++)
  148.         {
  149.                 if(right)cs1=1,cs2=0;
  150.                 else  cs1=0,cs2=1;
  151.                 Writecom(0xb8+row+i); //行
  152.                 Writecom(0x40+col);   //列
  153.                 for(j=0;j<x;j++)
  154.                 {
  155.                         if(col+j<64)Writedat(tab[i*x+j]);  //未跨屏
  156.                         else if(right==0)
  157.                         {                  //从左屏跨右屏
  158.                                 cs1=0,cs2=1;                  //选中右屏
  159.                                 Writecom(0xb8+row+i);           //设置行
  160.                                 Writecom(0x40+(col+j-64));
  161.                                 Writedat(tab[i*x+j]);
  162.                         }                                                 //在右屏越界不显示
  163.                 }
  164.         }
  165. }
  166. /* 返回一个8*16字符索引位置 */                                       
  167. uchar enN(uchar *s)
  168. {
  169.         uchar i;
  170.         for(i=0;ywzc[i]!=0;i++)
  171.         if(ywzc[i]==s[0])break;
  172.         return i;        
  173. }
  174. /* 返回一个16*16字符索引位置 */
  175. uchar cnN(uchar *s)
  176. {
  177.         uchar i;
  178.         for(i=0;hzzc[i]!=0;i+=2)
  179.         if(hzzc[i]==*s&&hzzc[i+1]==*(s+1))break ;
  180.         return i/2;
  181. }
  182. /* 显示字符串 */
  183. void showStr(uchar row,uchar col,uchar *s)
  184. {
  185.         uchar i;
  186.         for(i=0;s[i]!=0;i++)
  187.         {
  188.                 if(s[i]<0x80)
  189.                 {         //英文
  190.                         showXY(row,col,8,2,ywzm[enN(&s[i])]);
  191.                         col+=8;
  192.                 }
  193.                 else{                        
  194.                         showXY(row,col,16,2,hzzm[cnN(&s[i])]);        
  195.                         col+=16;i+=1;               
  196.                 }
  197.                 if(col>120)
  198.                 {         //换行处理
  199.                         col=0;
  200.                         row+=2;
  201.                 }
  202.         }
  203. }
  204. void main()
  205. {
  206.         Init12864();           //初始化
  207.         showStr(0,0,"一二三四五");
  208.         showStr(3,0,"六七八九十");
  209.         showStr(6,0,"当前工步");
  210.         while(1);
  211. }


复制代码
ID:88256 发表于 2020-10-2 22:37
从画面来看,不是你说的“只能显示字模里面的前十个汉字.超这个范围就乱码”,画面上比较正常显示的只有“一二三四”,也就是说只有左半屏是正常显示的,同一个字符串里的“五”无法正常显示,说明左右半屏的处理不对,你得看你用的12864具体型号并找到资料,看看里面左右半屏的片选CS1、CS2是怎样使用的,然后更改第169行if(right)cs1=0,cs2=1;以及第178行cs1=0,cs2=1;里的片选试试。

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

Powered by 单片机教程网

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