本帖最后由 xiaoxuesheng 于 2023-2-15 17:03 编辑
16*32字体,可以反白显示,在网上查了很多天几乎找不到,对于经验丰富的这些代码很简单,对于新手能想破脑袋,分享的代码属于简化过后的。
显示效果
我把代码放到附件
字符显示代码8x16示例代码有
- /***功能描述:显示8x16点阵 ***/
- void OLED_Char_8x16(uchar x, uchar y, uchar chr, uchar mode)
- {
- unsigned char c = 0, i = 0, j;
- c = chr - ' ';
- if (x > Max_Column - 1)
- {
- x = 0;
- y = y + 2;
- }
- for (j = 0; j < 2; j++)
- {
- OLED_Set_Pos(x, y + j);
- for (i = 0; i < 8; i++)
- {
- if (!mode)
- {
- OLED_WrDat(F8X16[c * 16 + i + j * 8]);
- }
- else
- {
- OLED_WrDat(~F8X16[c * 16 + i + j * 8]);
- }
- }
- }
- }
- /***功能描述:显示16x32点阵 ***/
- void OLED_Char_16x32(uchar x, uchar y, uchar chr, uchar mode)
- {
- unsigned char c = 0, i = 0, j;
- c = chr - '0';
- if (x > Max_Column - 1)
- {
- x = 0;
- y = y + 2;
- }
- for (j = 0; j < 4; j++) //高度4页
- {
- OLED_Set_Pos(x, y + j);
- for (i = 0; i < 16; i++) //宽度
- {
- if (!mode)
- {
- OLED_WrDat(F16X32[c * 64 + i + j * 16]);
- }
- else
- {
- OLED_WrDat(~F16X32[c * 64 + i + j * 16]);
- }
- }
- }
- }
- /******功能描述:在指定位置显示一个字符,包括部分字符************************
- // x:0~127 y:0~7 chr:要显示的字符 size:选择字体大小 mode:1反白,0正常显示
- ***************************************************************/
- void OLED_ShowChar(uchar x, uchar y, uchar chr, uchar Size, uchar mode)
- {
- if (Size == 32)
- {
- OLED_Char_16x32(x, y, chr, mode);
- }
- else if (Size == 16)
- {
- OLED_Char_8x16(x, y, chr, mode);
- }
- else if (Size == 12)
- {
- OLED_Char_6x8(x, y, chr, mode);
- }
- }
复制代码
字符显示取模只有数字
- const unsigned char code F16X32[]=
- {
-
- 0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x40,0x40,0xC0,0xC0,0x80,0x00,0x00,0x00,
- 0x00,0x00,0xF0,0xFE,0xFF,0x0F,0x01,0x00,0x00,0x00,0x00,0x01,0x07,0xFF,0xFE,0xF0,
- 0x00,0x00,0x1F,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xFF,0xFF,0x1F,
- 0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x06,0x04,0x04,0x06,0x07,0x03,0x01,0x00,0x00,/*"0",0*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x01,0x01,0x01,0x01,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x04,0x04,0x04,0x06,0x07,0x07,0x07,0x06,0x04,0x04,0x04,0x00,0x00,/*"1",1*/
- 0x00,0x00,0x00,0x00,0x80,0xC0,0x40,0x40,0x40,0x40,0xC0,0xC0,0x80,0x80,0x00,0x00,
- 0x00,0x00,0x1E,0x1F,0x19,0x00,0x00,0x00,0x00,0x00,0x00,0xC1,0xFF,0x7F,0x3E,0x00,
- 0x00,0x00,0x00,0x80,0xC0,0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00,0xE0,0xE0,0x00,
- 0x00,0x00,0x07,0x07,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x07,0x07,0x01,0x00,/*"2",2*/
- 0x00,0x00,0x00,0x80,0x80,0xC0,0x40,0x40,0x40,0xC0,0xC0,0x80,0x80,0x00,0x00,0x00,
- 0x00,0x00,0x0F,0x0F,0x0F,0x00,0x80,0x80,0x80,0xC0,0xE1,0x7F,0x3F,0x1E,0x00,0x00,
- 0x00,0x00,0xE0,0xE0,0xE0,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0xFF,0xFE,0x78,0x00,
- 0x00,0x00,0x01,0x03,0x03,0x06,0x04,0x04,0x04,0x04,0x06,0x03,0x03,0x01,0x00,0x00,/*"3",3*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0xC0,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x80,0xE0,0x70,0x3C,0x0E,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,
- 0x00,0x10,0x1C,0x1E,0x13,0x11,0x10,0x10,0x10,0xFF,0xFF,0xFF,0xFF,0x10,0x10,0x10,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x0F,0x0F,0x0F,0x0F,0x08,0x08,0x08,/*"4",4*/
- 0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
- 0x00,0x00,0x00,0xF8,0xFF,0xC7,0x60,0x20,0x20,0x20,0x60,0xE0,0xC0,0x80,0x00,0x00,
- 0x00,0x00,0xE0,0xE1,0x61,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0xFF,0x7E,0x00,
- 0x00,0x00,0x01,0x03,0x06,0x04,0x04,0x04,0x04,0x04,0x06,0x03,0x03,0x01,0x00,0x00,/*"5",5*/
- 0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x40,0x40,0x40,0xC0,0x80,0x00,0x00,
- 0x00,0x00,0xE0,0xFC,0xFE,0x8F,0x81,0xC0,0x40,0x40,0x40,0xC0,0xC3,0x83,0x03,0x00,
- 0x00,0x00,0x3F,0xFF,0xFF,0xC3,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0x7E,
- 0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x06,0x04,0x04,0x04,0x06,0x03,0x03,0x01,0x00,/*"6",6*/
- 0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,
- 0x00,0x00,0x0F,0x0F,0x03,0x01,0x00,0x00,0x80,0xE0,0x78,0x1E,0x07,0x01,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFC,0xFF,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"7",7*/
- 0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x40,0x40,0x40,0xC0,0xC0,0x80,0x00,0x00,0x00,
- 0x00,0x00,0x1E,0x3F,0x7F,0xF1,0xE0,0xC0,0x80,0x80,0x80,0xE1,0x7F,0x3F,0x1E,0x00,
- 0x00,0xF8,0xFC,0xFE,0x07,0x03,0x01,0x01,0x01,0x03,0x07,0x0F,0xFE,0xFC,0xF8,0x00,
- 0x00,0x00,0x01,0x03,0x03,0x06,0x04,0x04,0x04,0x04,0x06,0x03,0x03,0x01,0x00,0x00,/*"8",8*/
- 0x00,0x00,0x00,0x80,0x80,0xC0,0x40,0x40,0x40,0x40,0xC0,0x80,0x00,0x00,0x00,0x00,
- 0x00,0xFC,0xFF,0xFF,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0xFF,0xFE,0xF8,0x00,
- 0x00,0x00,0x81,0x83,0x87,0x06,0x04,0x04,0x04,0x06,0x83,0xF3,0xFF,0x7F,0x0F,0x00,
- 0x00,0x00,0x03,0x03,0x07,0x04,0x04,0x04,0x06,0x07,0x03,0x01,0x00,0x00,0x00,0x00,/*"9",9*/
- };
复制代码
|