void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 Char_Size) { unsigned char c=0,i=0; c=chr-' ';//得到偏移后的值 if(x>Max_Column-1){x=0;y=y+2;} if(Char_Size ==16) { OLED_Set_Pos(x,y); for(i=0;i<8;i++) OLED_WR_Byte(F8X16[c*16+i],OLED_DATA); OLED_Set_Pos(x,y+1); for(i=0;i<8;i++) OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA); } else { OLED_Set_Pos(x,y); for(i=0;i<6;i++) OLED_WR_Byte(F6x8[c][i],OLED_DATA); } }
时间: 2023-06-19 10:03:23 浏览: 162
这是一段OLED屏幕上显示字符的C语言代码。函数的输入参数包括字符在屏幕上的位置(x,y),要显示的字符(chr),以及字符的大小(Char_Size)。函数会根据字符的大小选择合适的字库(F8X16或F6x8),然后在屏幕上显示该字符。具体来说,如果字符大小为16,那么函数会将该字符分为两行,每行8个像素,然后分别在屏幕上显示出来。如果字符大小为其他值,那么函数会使用F6x8字库,在屏幕上显示该字符。
相关问题
void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 Char_Size) { unsigned char j=0; while (chr[j]!='\0') { OLED_ShowChar(x,y,chr[j],Char_Size); x+=8; if(x>120){x=0;y+=2;} j++; } }
这段代码是用来在OLED屏幕上显示字符串的函数。它的参数包括字符串的起始坐标(x, y),字符串内容(chr),以及字符显示的大小(Char_Size)。在函数中,它会调用OLED_ShowChar函数来逐个显示字符,每次显示完一个字符后,x坐标加8,如果x坐标超出了屏幕宽度(120),则重新从0开始,并将y坐标加2,以便在下一行显示。最后,当整个字符串都显示完成后,该函数就会结束。
编写程序void OLED_ShowChinese(u8 x,u8 y,u8 chr,u8 size,u8 mode)实现在oled上显示汉字
这是一个基于Arduino平台的OLED显示屏库,可以在OLED上显示汉字:
```
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_ADDR 0x3C
#define OLED_RESET -1
Adafruit_SSD1306 display(OLED_RESET);
// 字库数组
const unsigned char F8X16[] PROGMEM = {
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
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,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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*/
};
void OLED_Init() {
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();
display.display();
}
void OLED_ShowChinese(unsigned char x, unsigned char y, unsigned char chr, unsigned char size, unsigned char mode) {
unsigned char c = 0, i = 0;
unsigned char ch = chr - ' ';
unsigned char chi = ch * 16;
unsigned char x0 = x, y0 = y;
if (size == 16) {
for (i = 0; i < 16; i++) {
c = pgm_read_byte(&F8X16[chi + i]);
for (unsigned char j = 0; j < 8; j++) {
if ((c >> (7 - j)) & 0x01) {
display.drawPixel(x + j, y + i, 1);
}
else {
if (mode) display.drawPixel(x + j, y + i, 0);
}
}
}
}
display.display();
}
void setup() {
OLED_Init();
}
void loop() {
OLED_ShowChinese(0, 0, '中', 16, 1);
delay(5000);
OLED_ShowChinese(20, 0, '国', 16, 1);
delay(5000);
}
```
这个程序中使用了F8X16字库,可以在16x16的区域中显示汉字。可以根据实际情况修改字库和代码。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)