请选择 进入手机版 | 继续访问电脑版

930电子网

 找回密码
 立即注册
艾克姆科技推出最新产品STC8H3K64S4开发板
查看: 1012|回复: 0

STC8-I2C-Oled大字体代码

[复制链接]

2

主题

3

帖子

38

积分

新手上路

Rank: 1

积分
38
发表于 2022-2-21 23:39:39 | 显示全部楼层 |阅读模式
本帖最后由 xiaoxuesheng 于 2022-2-21 23:47 编辑

16*32字体,可以反白显示,在网上查了很多天几乎找不到,对于经验丰富的这些代码很简单,对于新手能想破脑袋,分享的代码属于简化过后的。







显示效果

我把代码放到附件


字符显示代码8x16示例代码有

  1. /***功能描述:显示8x16点阵 ***/
  2. void OLED_Char_8x16(uchar x, uchar y, uchar chr, uchar mode)
  3. {
  4.     unsigned char c = 0, i = 0, j;
  5.     c = chr - ' ';
  6.     if (x > Max_Column - 1)
  7.     {
  8.         x = 0;
  9.         y = y + 2;
  10.     }

  11.     for (j = 0; j < 2; j++)
  12.     {
  13.         OLED_Set_Pos(x, y + j);
  14.         for (i = 0; i < 8; i++)
  15.         {
  16.             if (!mode)
  17.             {
  18.                 OLED_WrDat(F8X16[c * 16 + i + j * 8]);
  19.             }
  20.             else
  21.             {
  22.                 OLED_WrDat(~F8X16[c * 16 + i + j * 8]);
  23.             }
  24.         }
  25.     }
  26. }
  27. /***功能描述:显示16x32点阵 ***/
  28. void OLED_Char_16x32(uchar x, uchar y, uchar chr, uchar mode)
  29. {
  30.     unsigned char c = 0, i = 0, j;
  31.     c = chr - '0';
  32.     if (x > Max_Column - 1)
  33.     {
  34.         x = 0;
  35.         y = y + 2;
  36.     }
  37.     for (j = 0; j < 4; j++) //高度4页
  38.     {
  39.         OLED_Set_Pos(x, y + j);
  40.         for (i = 0; i < 16; i++) //宽度
  41.         {
  42.             if (!mode)
  43.             {
  44.                 OLED_WrDat(F16X32[c * 64 + i + j * 16]);
  45.             }
  46.             else
  47.             {
  48.                 OLED_WrDat(~F16X32[c * 64 + i + j * 16]);
  49.             }
  50.         }
  51.     }
  52. }


  53. /******功能描述:在指定位置显示一个字符,包括部分字符************************
  54. // x:0~127  y:0~7   chr:要显示的字符   size:选择字体大小  mode:1反白,0正常显示
  55. ***************************************************************/
  56. void OLED_ShowChar(uchar x, uchar y, uchar chr, uchar Size, uchar mode)
  57. {
  58.    if (Size == 32)
  59.     {
  60.         OLED_Char_16x32(x, y, chr, mode);
  61.     }
  62.     else if (Size == 16)
  63.     {
  64.         OLED_Char_8x16(x, y, chr, mode);
  65.     }
  66.     else if (Size == 12)
  67.     {
  68.         OLED_Char_6x8(x, y, chr, mode);
  69.     }
  70. }
复制代码



字符显示取模只有数字

  1. const unsigned char code F16X32[]=
  2.     {
  3.                        
  4. 0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x40,0x40,0xC0,0xC0,0x80,0x00,0x00,0x00,
  5. 0x00,0x00,0xF0,0xFE,0xFF,0x0F,0x01,0x00,0x00,0x00,0x00,0x01,0x07,0xFF,0xFE,0xF0,
  6. 0x00,0x00,0x1F,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0xFF,0x1F,
  7. 0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x06,0x04,0x04,0x06,0x07,0x03,0x01,0x00,0x00,/*"0",0*/

  8. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
  9. 0x00,0x00,0x00,0x01,0x01,0x01,0x01,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
  10. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
  11. 0x00,0x00,0x00,0x04,0x04,0x04,0x06,0x07,0x07,0x07,0x06,0x04,0x04,0x04,0x00,0x00,/*"1",1*/

  12. 0x00,0x00,0x00,0x00,0x80,0xC0,0x40,0x40,0x40,0x40,0xC0,0xC0,0x80,0x80,0x00,0x00,
  13. 0x00,0x00,0x1E,0x1F,0x19,0x00,0x00,0x00,0x00,0x00,0x00,0xC1,0xFF,0x7F,0x3E,0x00,
  14. 0x00,0x00,0x00,0x80,0xC0,0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00,0xE0,0xE0,0x00,
  15. 0x00,0x00,0x07,0x07,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x07,0x07,0x01,0x00,/*"2",2*/

  16. 0x00,0x00,0x00,0x80,0x80,0xC0,0x40,0x40,0x40,0xC0,0xC0,0x80,0x80,0x00,0x00,0x00,
  17. 0x00,0x00,0x0F,0x0F,0x0F,0x00,0x80,0x80,0x80,0xC0,0xE1,0x7F,0x3F,0x1E,0x00,0x00,
  18. 0x00,0x00,0xE0,0xE0,0xE0,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0xFF,0xFE,0x78,0x00,
  19. 0x00,0x00,0x01,0x03,0x03,0x06,0x04,0x04,0x04,0x04,0x06,0x03,0x03,0x01,0x00,0x00,/*"3",3*/

  20. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0xC0,0x00,0x00,0x00,
  21. 0x00,0x00,0x00,0x00,0x80,0xE0,0x70,0x3C,0x0E,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,
  22. 0x00,0x10,0x1C,0x1E,0x13,0x11,0x10,0x10,0x10,0xFF,0xFF,0xFF,0xFF,0x10,0x10,0x10,
  23. 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x0F,0x0F,0x0F,0x0F,0x08,0x08,0x08,/*"4",4*/

  24. 0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
  25. 0x00,0x00,0x00,0xF8,0xFF,0xC7,0x60,0x20,0x20,0x20,0x60,0xE0,0xC0,0x80,0x00,0x00,
  26. 0x00,0x00,0xE0,0xE1,0x61,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0xFF,0x7E,0x00,
  27. 0x00,0x00,0x01,0x03,0x06,0x04,0x04,0x04,0x04,0x04,0x06,0x03,0x03,0x01,0x00,0x00,/*"5",5*/

  28. 0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x40,0x40,0x40,0xC0,0x80,0x00,0x00,
  29. 0x00,0x00,0xE0,0xFC,0xFE,0x8F,0x81,0xC0,0x40,0x40,0x40,0xC0,0xC3,0x83,0x03,0x00,
  30. 0x00,0x00,0x3F,0xFF,0xFF,0xC3,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0x7E,
  31. 0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x06,0x04,0x04,0x04,0x06,0x03,0x03,0x01,0x00,/*"6",6*/

  32. 0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
  33. 0x00,0x00,0x0F,0x0F,0x03,0x01,0x00,0x00,0x80,0xE0,0x78,0x1E,0x07,0x01,0x00,0x00,
  34. 0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFC,0xFF,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
  35. 0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"7",7*/

  36. 0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x40,0x40,0x40,0xC0,0xC0,0x80,0x00,0x00,0x00,
  37. 0x00,0x00,0x1E,0x3F,0x7F,0xF1,0xE0,0xC0,0x80,0x80,0x80,0xE1,0x7F,0x3F,0x1E,0x00,
  38. 0x00,0xF8,0xFC,0xFE,0x07,0x03,0x01,0x01,0x01,0x03,0x07,0x0F,0xFE,0xFC,0xF8,0x00,
  39. 0x00,0x00,0x01,0x03,0x03,0x06,0x04,0x04,0x04,0x04,0x06,0x03,0x03,0x01,0x00,0x00,/*"8",8*/

  40. 0x00,0x00,0x00,0x80,0x80,0xC0,0x40,0x40,0x40,0x40,0xC0,0x80,0x00,0x00,0x00,0x00,
  41. 0x00,0xFC,0xFF,0xFF,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0xFF,0xFE,0xF8,0x00,
  42. 0x00,0x00,0x81,0x83,0x87,0x06,0x04,0x04,0x04,0x06,0x83,0xF3,0xFF,0x7F,0x0F,0x00,
  43. 0x00,0x00,0x03,0x03,0x07,0x04,0x04,0x04,0x06,0x07,0x03,0x01,0x00,0x00,0x00,0x00,/*"9",9*/
  44. };
复制代码









本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

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

本版积分规则

QQ|手机版|官方淘宝店|930电子网 ( 皖ICP备16000695号-2

GMT+8, 2022-5-22 15:51 , Processed in 0.103032 second(s), 26 queries .

Powered by Discuz! X3.2

Copyright © 2001-2020, Tencent Cloud.

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