UP 模拟器 OLED+KEY混合
This commit is contained in:
@@ -82,23 +82,7 @@ struct OLED_Dev {
|
||||
// 2, 0xA4, 0xA6, // 整个显示打开
|
||||
// 1, 0xAF // 打开显示
|
||||
//};
|
||||
const uint8_t initCmd[] = {
|
||||
0xAE, // 关闭显示
|
||||
0xD5, 0x80, // 设置显示时钟分频比/振荡器频率
|
||||
0xA8, 0x3F, // 设置多路复用比率
|
||||
0xD3, 0x00, // 设置显示偏移
|
||||
0x40, 0x00, // 设置显示起始行
|
||||
0x8D, 0x14, // 电荷泵设置
|
||||
0x20, 0x00, // 设置内存寻址模式
|
||||
0xA0, // 设置段重映射
|
||||
0xC0, // 设置COM输出扫描方向
|
||||
0xDA, 0x12, // 设置COM引脚硬件配置
|
||||
0x81, 0xCF, // 设置对比度控制
|
||||
0xD9, 0xF1, // 设置预充电周期
|
||||
0xDB, 0x20, // 设置VCOMH取消电平
|
||||
0xA4, 0xA6, // 整个显示打开
|
||||
0xAF // 打开显示
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief OLED初始化
|
||||
@@ -229,6 +213,32 @@ 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: [输入] 数字显示的起始横坐标
|
||||
* @param y: [输入] 数字显示的起始纵坐标
|
||||
* @param num: [输入] 要显示的数字
|
||||
* @param len: [输入] 数字长度
|
||||
* @param size1: [输入] 字体大小
|
||||
* @return void
|
||||
* @example OLED_ShowNum(&oled_dev, 0, 0, 12345, 5, 12);
|
||||
**/
|
||||
void OLED_ShowNum(OLED_T *dev, uint8_t x, uint8_t y, uint32_t num, uint8_t len, uint8_t size1);
|
||||
|
||||
/**
|
||||
* @brief 在OLED屏幕上显示图片
|
||||
* @param dev: [输入] OLED设备指针
|
||||
* @param x0: [输入] 图片左上角横坐标
|
||||
* @param y0: [输入] 图片左上角纵坐标
|
||||
* @param x1: [输入] 图片右下角横坐标
|
||||
* @param y1: [输入] 图片右下角纵坐标
|
||||
* @param bmp: [输入] 图片数据数组指针
|
||||
* @return void
|
||||
* @example OLED_ShowPic(&oled_dev, 0, 0, 127, 63, bmp_data);
|
||||
**/
|
||||
void OLED_ShowPic(OLED_T *dev, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t *bmp);
|
||||
|
||||
/**
|
||||
* @brief 设置显示起始坐标
|
||||
* @param dev: [输入] OLED设备指针
|
||||
|
@@ -3,6 +3,24 @@
|
||||
|
||||
#define BUFPOINT(x, y) (*(dev->buf + x + (y * dev->width)))
|
||||
|
||||
const uint8_t initCmd[] = {
|
||||
0xAE, // 关闭显示
|
||||
0xD5, 0x80, // 设置显示时钟分频比/振荡器频率
|
||||
0xA8, 0x3F, // 设置多路复用比率
|
||||
0xD3, 0x00, // 设置显示偏移
|
||||
0x40, 0x00, // 设置显示起始行
|
||||
0x8D, 0x14, // 电荷泵设置
|
||||
0x20, 0x00, // 设置内存寻址模式
|
||||
0xA0, // 设置段重映射
|
||||
0xC0, // 设置COM输出扫描方向
|
||||
0xDA, 0x12, // 设置COM引脚硬件配置
|
||||
0x81, 0xCF, // 设置对比度控制
|
||||
0xD9, 0xF1, // 设置预充电周期
|
||||
0xDB, 0x20, // 设置VCOMH取消电平
|
||||
0xA4, 0xA6, // 整个显示打开
|
||||
0xAF // 打开显示
|
||||
};
|
||||
|
||||
void OLED_Init(OLED_T *dev) {
|
||||
uint8_t *cmdIndex = (uint8_t *) initCmd;
|
||||
// uint8_t count, temp;
|
||||
@@ -190,6 +208,35 @@ void OLED_ShowString(OLED_T *dev, uint8_t x, uint8_t y, uint8_t *chr, uint8_t si
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t OLED_Pow(uint8_t m, uint8_t n) {
|
||||
uint32_t result = 1;
|
||||
while (n--) {
|
||||
result *= m;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void OLED_ShowNum(OLED_T *dev, uint8_t x, uint8_t y, uint32_t num, uint8_t len, uint8_t size1) {
|
||||
uint8_t t, temp;
|
||||
for (t = 0; t < len; t++) {
|
||||
temp = (num / OLED_Pow(10, len - t - 1)) % 10;
|
||||
if (temp == 0) {
|
||||
OLED_ShowChar(dev, x + (size1 / 2) * t, y, '0', size1);
|
||||
} else {
|
||||
OLED_ShowChar(dev, x + (size1 / 2) * t, y, temp + '0', size1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OLED_ShowPic(OLED_T *dev, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t *bmp) {
|
||||
uint8_t y = 0;
|
||||
if (y % 8 == 0)y = 0;
|
||||
else y += 1;
|
||||
for (y = y0; y < y1; y++) {
|
||||
OLED_SPos(dev, x0, y);
|
||||
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++) {
|
||||
|
Reference in New Issue
Block a user