标题: 基于SC95F8616单片机的中西文混排显示 [打印本页]

作者: jinglixixi    时间: 2020-7-18 08:29
标题: 基于SC95F8616单片机的中西文混排显示
前面介绍了区位法显示汉字,但使用起来多少有些不便,为了便于中西文混排,这里介绍用指针来实现混排显示的方法。
其显示效果如图1所示,其中首行显示的是内码,次行显示是的内容。

1混排显示

混排显示主程序为:
  1. void  main(void)
  2. {
  3.          no=0;
  4.          x=0;
  5.          OLED_Init();
  6.          OLED_Clear();
  7.          LcdShowString(0,0,"啊A阿",0,1);
  8.          while(1);
  9. }
复制代码

混排显示函数为:
  1. void LcdShowString(uint32_t x,uint32_t y,uint8_t *pucCode,uint32_t color,uint32_t bgcolor)
  2. {
  3.           uint32_t x_bak=x;
  4.           uint8_t  u,v,no,p;
  5.           p=x;
  6.           while(*pucCode)
  7.           {
  8.                              if(*pucCode & 0x80)
  9.                              {
  10.                                         u=*pucCode;
  11.                                         v=(u&0xf0)>>4;
  12.                                         if(v<10) OLED_ShowChar (x,y,v+'0',16);
  13.                                         else OLED_ShowChar (x,y,v+55,16);

  14.                                         x=x+8;
  15.                                         v=(u&0x0f);
  16.                                         if(v<10) OLED_ShowChar (x,y,v+'0',16);
  17.                                         else OLED_ShowChar (x,y,v+55,16);

  18.                                         x=x+8;
  19.                                         u=*(++pucCode);
  20.                                         no=u-161;
  21.                                        
  22.                                         v=(u&0xf0)>>4;
  23.                                         if(v<10) OLED_ShowChar (x,y,v+'0',16);
  24.                                         else OLED_ShowChar (x,y,v+55,16);

  25.                                         x=x+8;
  26.                                         v=(u&0x0f);
  27.                                         if(v<10) OLED_ShowChar (x,y,v+'0',16);
  28.                                         else OLED_ShowChar (x,y,v+55,16);

  29.                                         *(++pucCode);
  30.                                         x+=8;
  31.                                         OLED_ShowCHinesey(p,y+2, no*2);
  32.                                         p+=16;
  33.                               }
  34.                              else
  35.                              {
  36.                                         u=*pucCode;
  37.                                         v=(u&0xf0)>>4;
  38.                                         if(v<10) OLED_ShowChar (x,y,v+'0',16);
  39.                                         else OLED_ShowChar (x,y,v+55,16);
  40.                                         x+=8;

  41.                                         v=(u&0x0f);
  42.                                         if(v<10) OLED_ShowChar (x,y,v+'0',16);
  43.                                         else OLED_ShowChar (x,y,v+55,16);
  44.                                         x+=8;
  45.                                         OLED_ShowChar(p,y+2,u,16);
  46.                                         p+=8;
  47.                                         *(++pucCode);
  48.                              }

  49.                              if(x>113)
  50.                              {
  51.                                        x = x_bak;
  52.                              }
  53.           }
  54. }
复制代码

2超长显示





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1