UP 加入中文显示Unicode 和对应字库生成脚本
This commit is contained in:
@@ -213,6 +213,18 @@ void OLED_ShowChar(OLED_T *dev, uint8_t x, uint8_t y, uint8_t chr, uint8_t size1
|
||||
*/
|
||||
void OLED_ShowString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *chr, uint8_t size1);
|
||||
|
||||
/**
|
||||
* @brief 在OLED上显示指定大小的中文字符串
|
||||
* @param dev: [输入] OLED设备指针
|
||||
* @param x: [输入] X坐标
|
||||
* @param y: [输入] Y坐标
|
||||
* @param str: [输入] 中文字符串指针
|
||||
* @param size: [输入] 字体大小
|
||||
* @return void
|
||||
* @example OLED_ShowCHString(&oled_device, 0, 0, chinese_str, 16);
|
||||
**/
|
||||
void OLED_ShowCHString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *str, uint8_t size);
|
||||
|
||||
/**
|
||||
* @brief 在OLED屏幕上显示数字
|
||||
* @param dev: [输入] OLED设备指针
|
||||
|
@@ -1,12 +1,7 @@
|
||||
#ifndef HW_LIB_OLED_FONT_H
|
||||
#define HW_LIB_OLED_FONT_H
|
||||
//常用ASCII表
|
||||
//偏移量32
|
||||
//ASCII字符集
|
||||
//偏移量32
|
||||
//大小:12*6
|
||||
/************************************6*8的点阵************************************/
|
||||
//12*12 ASCII字符集点阵
|
||||
|
||||
//12*6 ASCII字符集点阵
|
||||
const unsigned char asc2_1206[95][12] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},/*" ",0*/
|
||||
{0x00, 0x00, 0x00, 0x00, 0x3F, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},/*"!",1*/
|
||||
@@ -104,7 +99,7 @@ const unsigned char asc2_1206[95][12] = {
|
||||
{0x00, 0x00, 0x40, 0x20, 0x7B, 0xE0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00},/*"}",93*/
|
||||
{0x40, 0x00, 0x80, 0x00, 0x40, 0x00, 0x20, 0x00, 0x20, 0x00, 0x40, 0x00},/*"~",94*/
|
||||
};
|
||||
//16*16 ASCII字符集点阵
|
||||
//16*8 ASCII字符集点阵
|
||||
const unsigned char asc2_1608[95][16] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},/*" ",0*/
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xCC, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},/*"!",1*/
|
||||
@@ -202,7 +197,7 @@ const unsigned char asc2_1608[95][16] = {
|
||||
{0x00, 0x00, 0x40, 0x02, 0x40, 0x02, 0x3E, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},/*"}",93*/
|
||||
{0x00, 0x00, 0x60, 0x00, 0x80, 0x00, 0x80, 0x00, 0x40, 0x00, 0x40, 0x00, 0x20, 0x00, 0x20, 0x00},/*"~",94*/
|
||||
};
|
||||
//24*24 ASICII字符集点阵
|
||||
//24*12 ASICII字符集点阵
|
||||
const unsigned char asc2_2412[95][36] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x0F, 0x80, 0x38, 0x0F, 0xFE, 0x38, 0x0F, 0x80, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},/*"!",1*/
|
||||
|
46
lib/inc/oled/oled_font_chuc.h
Normal file
46
lib/inc/oled/oled_font_chuc.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef HW_LIB_OLED_FONT_CHUC_H
|
||||
#define HW_LIB_OLED_FONT_CHUC_H
|
||||
typedef struct {
|
||||
uint8_t name[3];
|
||||
uint8_t data[32];
|
||||
} Chinese_t;
|
||||
|
||||
Chinese_t Hzk[] = {
|
||||
{
|
||||
// Original: 字
|
||||
{0x5B, 0x57},
|
||||
{0x10, 0x0C, 0x04, 0x24, 0x24, 0x24, 0x25, 0x26, 0xA4, 0x64, 0x24, 0x04, 0x04, 0x14, 0x0C, 0x00,
|
||||
0x02, 0x02, 0x02, 0x02, 0x02, 0x42, 0x82, 0x7F, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00
|
||||
}},
|
||||
{
|
||||
// Original: 库
|
||||
{0x5E, 0x93},
|
||||
{0x00, 0x00, 0xFC, 0x24, 0x24, 0xA4, 0x64, 0x3D, 0xA6, 0x24, 0x24, 0x24, 0x24, 0x24, 0x04, 0x00,
|
||||
0x40, 0x30, 0x0F, 0x10, 0x13, 0x12, 0x12, 0x12, 0xFF, 0x12, 0x12, 0x12, 0x12, 0x10, 0x10, 0x00
|
||||
}},
|
||||
{
|
||||
// Original: 生
|
||||
{0x75, 0x1F},
|
||||
{0x80, 0x40, 0x30, 0x1E, 0x10, 0x10, 0x10, 0xFF, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00,
|
||||
0x40, 0x40, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7F, 0x42, 0x42, 0x42, 0x42, 0x42, 0x40, 0x40, 0x00
|
||||
}},
|
||||
{
|
||||
// Original: 成
|
||||
{0x62, 0x10},
|
||||
{0x00, 0x00, 0xF8, 0x88, 0x88, 0x88, 0x88, 0x08, 0x08, 0xFF, 0x08, 0x09, 0x0A, 0xC8, 0x08, 0x00,
|
||||
0x80, 0x60, 0x1F, 0x00, 0x10, 0x20, 0x1F, 0x80, 0x40, 0x21, 0x16, 0x18, 0x26, 0x41, 0xF8, 0x00
|
||||
}},
|
||||
{
|
||||
// Original: 测
|
||||
{0x6D, 0x4B},
|
||||
{0x10, 0x60, 0x02, 0x8C, 0x00, 0xFE, 0x02, 0xF2, 0x02, 0xFE, 0x00, 0xF8, 0x00, 0xFF, 0x00, 0x00,
|
||||
0x04, 0x04, 0x7E, 0x01, 0x80, 0x47, 0x30, 0x0F, 0x10, 0x27, 0x00, 0x47, 0x80, 0x7F, 0x00, 0x00
|
||||
}},
|
||||
{
|
||||
// Original: 试
|
||||
{0x8B, 0xD5},
|
||||
{0x40, 0x40, 0x42, 0xCC, 0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0xFF, 0x10, 0x11, 0x16, 0x10, 0x00,
|
||||
0x00, 0x00, 0x00, 0x3F, 0x10, 0x28, 0x60, 0x3F, 0x10, 0x10, 0x01, 0x0E, 0x30, 0x40, 0xF0, 0x00
|
||||
}},
|
||||
};
|
||||
#endif //HW_LIB_OLED_FONT_CHUC_H
|
@@ -153,7 +153,7 @@ double :"[double]-> "#v"=%.2f" END, \
|
||||
default: "[err]-> "#v"=%p" END)
|
||||
#define POUT(s) printf(TYPE_F(s) ,s)
|
||||
|
||||
|
||||
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
#include "oled.h"
|
||||
#include "oled_font.h"
|
||||
#include "oled_font_chuc.h"
|
||||
|
||||
#define BUFPOINT(x, y) (*(dev->buf + x + (y * dev->width)))
|
||||
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
|
||||
|
||||
const uint8_t initCmd[] = {
|
||||
0xAE, // 关闭显示
|
||||
@@ -104,6 +106,16 @@ void OLED_Set(OLED_T *dev, uint8_t x, uint8_t y) {
|
||||
BUFPOINT(x, i) |= n;
|
||||
}
|
||||
|
||||
void OLED_BSet(OLED_T *dev, uint8_t x, uint8_t y, uint8_t data) {
|
||||
uint8_t i, ys = y;
|
||||
for (i = 0; i < 8; i++) //写入数据
|
||||
{
|
||||
if (GET_BIT(data, i))OLED_Set(dev, x, ys);
|
||||
else OLED_RSet(dev, x, ys);
|
||||
ys++;
|
||||
}
|
||||
}
|
||||
|
||||
void OLED_RSet(OLED_T *dev, uint8_t x, uint8_t y) {
|
||||
uint8_t i, m, n;
|
||||
i = y / 8;
|
||||
@@ -171,7 +183,7 @@ void OLED_DrawCircle(OLED_T *dev, uint8_t x, uint8_t y, uint8_t r) {
|
||||
|
||||
void OLED_ShowChar(OLED_T *dev, uint8_t x, uint8_t y, uint8_t chr, uint8_t size1) {
|
||||
uint8_t i, m, temp, size2, chr1;
|
||||
uint8_t y0 = y;
|
||||
uint8_t ys = y;
|
||||
size2 = (size1 / 8 + ((size1 % 8) ? 1 : 0)) * (size1 / 2); //得到字体一个字符对应点阵集所占的字节数
|
||||
chr1 = chr - ' '; //计算偏移后的值
|
||||
for (i = 0; i < size2; i++) {
|
||||
@@ -181,12 +193,12 @@ void OLED_ShowChar(OLED_T *dev, uint8_t x, uint8_t y, uint8_t chr, uint8_t size1
|
||||
else return;
|
||||
for (m = 0; m < 8; m++) //写入数据
|
||||
{
|
||||
if (temp & 0x80)OLED_Set(dev, x, y);
|
||||
else OLED_RSet(dev, x, y);
|
||||
if (temp & 0x80)OLED_Set(dev, x, ys);
|
||||
else OLED_RSet(dev, x, ys);
|
||||
temp <<= 1;
|
||||
y++;
|
||||
if ((y - y0) == size1) {
|
||||
y = y0;
|
||||
ys++;
|
||||
if ((ys - y) == size1) {
|
||||
ys = y;
|
||||
x++;
|
||||
break;
|
||||
}
|
||||
@@ -208,6 +220,30 @@ void OLED_ShowString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *chr, uint8_t si
|
||||
}
|
||||
}
|
||||
|
||||
void OLED_ShowCHString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *str, uint8_t size) {
|
||||
uint8_t i, temp, size2, ys = y, xs = x;
|
||||
uint16_t index;
|
||||
size2 = (size / 8 + ((size % 8) ? 1 : 0)) * (size); //得到字体一个字符对应点阵集所占的字节数
|
||||
while (*str) {
|
||||
for (index = 0; index < sizeof(Hzk) / 35; index++) {
|
||||
if (Hzk[index].name[0] == str[0] && Hzk[index].name[1] == str[1])//对比汉字区码位码
|
||||
{
|
||||
for (i = 0; i < size2; i++) {
|
||||
temp = Hzk[index].data[i];
|
||||
OLED_BSet(dev, xs + (i % size), ys, temp);
|
||||
if (i == size2 / 2)ys += size / 2;
|
||||
}
|
||||
xs += size;
|
||||
ys = y;
|
||||
str++;
|
||||
str++;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t OLED_Pow(uint8_t m, uint8_t n) {
|
||||
uint32_t result = 1;
|
||||
while (n--) {
|
||||
@@ -237,6 +273,7 @@ void OLED_ShowPic(OLED_T *dev, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, u
|
||||
dev->data(bmp + y * (x1 - x0), x1 - x0);
|
||||
}
|
||||
}
|
||||
|
||||
void OLED_Fill(OLED_T *dev, uint8_t data) {
|
||||
uint8_t x, y;
|
||||
for (y = 0; y < (dev->height >> 3); y++) {
|
||||
|
@@ -3,6 +3,7 @@
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <ctime>
|
||||
#include <stdint.h>
|
||||
#include "tool.h"
|
||||
|
||||
float Mapping(float val, float I_Min, float I_Max, float O_Min, float O_Max) {
|
||||
@@ -45,6 +46,16 @@ void BufPrint(char *name, void *buf, Type_t type, unsigned int len, unsigned cha
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
uint8_t UTF8ToUnicode(uint8_t *dataArea, uint8_t dataAreaLength, uint8_t *uniDA) {
|
||||
uint8_t len = dataAreaLength * 2 / 3;
|
||||
// uint8_t uniDA[len];
|
||||
for (int i = 0; i < dataAreaLength / 3; i++) {
|
||||
uniDA[i * 2] = ((dataArea[i * 3] & 0xF) << 4) + ((dataArea[i * 3 + 1] >> 2) & 0xF);
|
||||
uniDA[i * 2 + 1] = ((dataArea[i * 3 + 1] & 0x3) << 6) + (dataArea[i * 3 + 2] & 0x3F);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
float Str2Float(char *str) {
|
||||
int integer = 0;
|
||||
double decimal = 0;
|
||||
|
Reference in New Issue
Block a user