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++; } }
时间: 2023-06-19 18:03:29 浏览: 192
这段代码是用来在OLED屏幕上显示字符串的函数。它的参数包括字符串的起始坐标(x, y),字符串内容(chr),以及字符显示的大小(Char_Size)。在函数中,它会调用OLED_ShowChar函数来逐个显示字符,每次显示完一个字符后,x坐标加8,如果x坐标超出了屏幕宽度(120),则重新从0开始,并将y坐标加2,以便在下一行显示。最后,当整个字符串都显示完成后,该函数就会结束。
相关问题
//显示一个字符号串 void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 Char_Size) { while (*chr!='\0') { OLED_ShowChar(x,y,*chr,Char_Size); x+=8; if(x>120){x=0;y+=2;} chr++; } }怎么用
这是一段 C 语言代码,用于在 OLED 显示屏上显示一个字符串。具体使用方法如下:
1. 将此函数代码复制粘贴到你的程序中。
2. 调用此函数,并传入四个参数:x 坐标、y 坐标、要显示的字符串、字符大小。例如:
```
OLED_ShowString(0, 0, "Hello, world!", 16);
```
这将在 OLED 显示屏上的 (0,0) 坐标开始显示字符串 "Hello, world!",字符大小为 16。
注意:在使用此函数前,你需要先初始化 OLED 显示屏,以确保其能正常工作。
编写程序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)
![](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)