(一) 移植驱动
0.96寸oled是非常常用的显示模,通过oled可以显示多种字符
在此选取了使用模拟spi方式驱动的oled,采用逐飞库作为基准移植,梳理逐飞科技的oled驱动依赖后,确认其需要的文件有:
(1)font.c front.h 文件中是各种字符的字码;
(2)oeld.c oled.h 文件中是oeld的驱动函数以及显示函数;
(3) sprintf.c sprintf.h 文件中是字符格式化函数,用于格式化变量,在此整合到oled.c中
所以总共需要的文件只有四个:oled.c oled.h font.c font.h
值得注意的地方是:
这里把四个文件附上来
oled.c
//oled12864
//zf库
#include "oled.h"
#include "font.h"
#include <stdarg.h>
#include <string.h>
#define OLED_SCL(x) ((x == 0)? (GPIO_setOutputLowOnPin(OLED_SCL_PORT,OLED_SCL_PIN)) :(GPIO_setOutputHighOnPin(OLED_SCL_PORT,OLED_SCL_PIN)))
#define OLED_SDA(x) ((x == 0)? (GPIO_setOutputLowOnPin(OLED_SDA_PORT,OLED_SDA_PIN)) :(GPIO_setOutputHighOnPin(OLED_SDA_PORT,OLED_SDA_PIN)))
#define OLED_RST(x) ((x == 0)? (GPIO_setOutputLowOnPin(OLED_RST_PORT,OLED_RST_PIN)) :(GPIO_setOutputHighOnPin(OLED_RST_PORT,OLED_RST_PIN)))
#define OLED_DC(x) ((x == 0)? (GPIO_setOutputLowOnPin(OLED_DC_PORT,OLED_DC_PIN)) :(GPIO_setOutputHighOnPin(OLED_DC_PORT,OLED_DC_PIN)))
#define OLED_CS(x) ((x == 0)? (GPIO_setOutputLowOnPin(OLED_CS_PORT,OLED_CS_PIN)) :(GPIO_setOutputHighOnPin(OLED_CS_PORT,OLED_CS_PIN)))
//-------------------------------------------------------------------------------------------------------------------
// @brief 写8位数据
// @param data 数据
// @return void
// @since v1.0
// Sample usage:
// @note 内部调用 用户无需关心
//-------------------------------------------------------------------------------------------------------------------
static void oled_wrdat(uint8 data)
{
uint8 i=8;
OLED_CS(0); // 使能信号端,拉低时正常使用
OLED_DC(1);
OLED_SCL(0);
while(i--)
{
if(data&0x80){OLED_SDA(1);}
else{OLED_SDA(0);}
OLED_SCL(1);
OLED_SCL(0);
data<<=1;
}
OLED_CS(1); // 使能信号端,拉低时正常使用
}
//-------------------------------------------------------------------------------------------------------------------
// @brief 写命令
// @param cmd 命令
// @return void
// @since v1.0
// Sample usage:
// @note 内部调用 用户无需关心
//-------------------------------------------------------------------------------------------------------------------
static void oled_wrcmd(uint8 cmd)
{
uint8 i=8;
OLED_CS(0); // 使能信号端,拉低时正常使用
OLED_DC(0);
OLED_SCL(0);;
while(i--)
{
if(cmd&0x80){OLED_SDA(1);}
else{OLED_SDA(0);}
OLED_SCL(1);
OLED_SCL(0);
cmd<<=1;
}
OLED_CS(1); // 使能信号端,拉低时正常使用
}
//-------------------------------------------------------------------------------------------------------------------
// @brief 转换16进制ascii码
// @param hex ascii码
// @param Print 存放地址
// @return void
// @since v1.0
// Sample usage:
// @note 内部调用 用户无需关心
//-------------------------------------------------------------------------------------------------------------------
static void oled_hexascii(uint16 hex,int8 * Print)
{
uint8 hexcheck ;
uint8 TEMP ;
TEMP = 6 ;
Print[TEMP ]='\0';
while(TEMP)
{
TEMP -- ;
hexcheck = hex%10 ;
hex /=10 ;
Print[TEMP ] = hexcheck + 0x30 ;
}
}
//-------------------------------------------------------------------------------------------------------------------
// @brief OLED初始化函数
// @param NULL
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void oled_init(void)
{
GPIO_setAsOutputPin(OLED_SCL_PORT,OLED_SCL_PIN);
GPIO_setAsOutputPin(OLED_SDA_PORT,OLED_SDA_PIN);
GPIO_setAsOutputPin(OLED_RST_PORT,OLED_RST_PIN);
GPIO_setAsOutputPin(OLED_DC_PORT,OLED_DC_PIN);
GPIO_setAsOutputPin(OLED_CS_PORT,OLED_CS_PIN);
OLED_SCL(1);
OLED_RST(0);
systick_delay_ms(50);
OLED_RST(1);
oled_wrcmd(0xae); // --turn off oled panel
oled_wrcmd(0x00); // ---set low column address
oled_wrcmd(0x10); // ---set high column address
oled_wrcmd(0x40); // --set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
oled_wrcmd(0x81); // --set contrast control register
oled_wrcmd(Brightness); // Set SEG Output Current Brightness
#if (0 == OLED_DISPLAY_DIR)
oled_wrcmd(0xa1); // --Set SEG/Column Mapping 0xa0左右反置 0xa1正常
oled_wrcmd(0xc8); // Set COM/Row Scan Direction 0xc0上下反置 0xc8正常
#else
oled_wrcmd(0xa0); // --Set SEG/Column Mapping 0xa0左右反置 0xa1正常
oled_wrcmd(0xc0); // Set COM/Row Scan Direction 0xc0上下反置 0xc8正常
#endif
oled_wrcmd(0xa6); // --set normal display
oled_wrcmd(0xa8); // --set multiplex ratio(1 to 64)
oled_wrcmd(0x3f); // --1/64 duty
oled_wrcmd(0xd3); // -set display offset Shift Mapping RAM Counter (0x00~0x3F)
oled_wrcmd(0x00); // -not offset
oled_wrcmd(0xd5); // --set display clock divide ratio/oscillator frequency
oled_wrcmd(0x80); // --set divide ratio, Set Clock as 100 Frames/Sec
oled_wrcmd(0xd9); // --set pre-charge period
oled_wrcmd(0xf1); // Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
oled_wrcmd(0xda); // --set com pins hardware configuration
oled_wrcmd(0x12);
oled_wrcmd(0xdb); // --set vcomh
oled_wrcmd(0x40); // Set VCOM Deselect Level
oled_wrcmd(0x20); // -Set Page Addressing Mode (0x00/0x01/0x02)
oled_wrcmd(0x02); //
oled_wrcmd(0x8d); // --set Charge Pump enable/disable
oled_wrcmd(0x14); // --set(0x10) disable
oled_wrcmd(0xa4); // Disable Entire Display On (0xa4/0xa5)
oled_wrcmd(0xa6); // Disable Inverse Display On (0xa6/a7)
oled_wrcmd(0xaf); // --turn on oled panel
oled_fill(0x00); // 初始清屏
oled_set_pos(0,0);
oled_p8x16str(0,0,"Hello MSP432!");
for(uint8 i = 0;i < 128;i ++)
{
oled_putpixel(i,5,0xff);
delay_ms(8);
}
delay_ms(800);
oled_fill(0x00);
oled_set_pos(0,0);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief OLED显示坐标设置
// @param x x轴坐标设置0-127
// @param y y轴坐标设置0-7
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void oled_set_pos(uint8 x, uint8 y)
{
oled_wrcmd(0xb0+y);
oled_wrcmd(((x&0xf0)>>4)|0x10);
oled_wrcmd((x&0x0f)|0x00);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief OLED清屏函数
// @param bmp_data 填充颜色选着(0x00 or 0xff)
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void oled_fill(uint8 bmp_data)
{
uint8 y,x;
for(y=0;y<8;y++)
{
oled_wrcmd(0xb0+y);
oled_wrcmd(0x01);
oled_wrcmd(0x10);
for(x=0;x<X_WIDTH;x++) oled_wrdat(bmp_data);
}
}
//-------------------------------------------------------------------------------------------------------------------
// @brief OLED控制一个坐标下8个像素的点亮与熄灭
// @param x x轴坐标设置0-127
// @param y y轴坐标设置0-7
// @return void
// @since v1.0
// Sample usage: oled_putpixel(0,0,0xff);//将0,0坐标 8个点全部点亮
// Sample usage: oled_putpixel(0,0,0x01);//将0,0坐标 最低位点亮其余7个熄灭
// @note 同理可以任意控制一个坐标下8个像素的点亮与熄灭
//-------------------------------------------------------------------------------------------------------------------
void oled_putpixel(uint8 x,uint8 y,uint8 data1)
{
oled_set_pos(x,y);
oled_wrcmd(0xb0+y);
oled_wrcmd(((x&0xf0)>>4)|0x10);
oled_wrcmd((x&0x0f)|0x00);
oled_wrdat(data1);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief OLED关闭一个坐标所有亮点
// @param x x轴坐标设置0-127
// @param y y轴坐标设置0-7
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void oled_clrpixel(uint8 x,uint8 y)
{
oled_set_pos(x,y);
oled_wrcmd(0xb0+y);
oled_wrcmd(((x&0xf0)>>4)|0x10);
oled_wrcmd((x&0x0f)|0x00);
oled_wrdat(0x00);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief OLED显示字符串(6*8字体)
// @param x x轴坐标设置0-127
// @param y y轴坐标设置0-7
// @param ch[] 字符串
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void oled_p6x8str(uint8 x,uint8 y,const int8 ch[])
{
uint8 c=0,i=0,j=0;
while (ch[j]!='\0')
{
c =ch[j]-32;
if(x>126)
{
x=0;
y++;
}
oled_set_pos(x,y);
for(i=0;i<6;i++)
oled_wrdat(oled_6x8[c][i]);
x+=6;
j++;
}
}
//-------------------------------------------------------------------------------------------------------------------
// @brief OLED显示字符串(8*16字体)
// @param x x轴坐标设置0-127
// @param y y轴坐标设置0-7
// @param ch[] 字符串
// @return void
// @since v1.0
// Sample usage: 务必注意,本函数字符列高位16,因此y应该是每次递增2
//-------------------------------------------------------------------------------------------------------------------
void oled_p8x16str(uint8 x,uint8 y,const int8 ch[])
{
uint8 c=0,i=0,j=0;
while (ch[j]!='\0')
{
c =ch[j]-32;
if(x>120)
{
x=0;
y++;
}
oled_set_pos(x,y);
for(i=0;i<8;i++)
oled_wrdat(oled_8x16[c*16+i]);
oled_set_pos(x,y+1);
for(i=0;i<8;i++)
oled_wrdat(oled_8x16[c*16+i+8]);
x+=8;
j++;
}
}
//-------------------------------------------------------------------------------------------------------------------
// @brief OLED显示无符号数(6*8字体)
// @param x x轴坐标设置0-127
// @param y y轴坐标设置0-7
// @param num 无符号数
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void oled_uint16(uint8 x, uint8 y, uint16 num)
{
int8 ch[7];
oled_hexascii(num,ch);
oled_p6x8str(x, y, &ch[1]); // 显示数字 6*8字体
}
//-------------------------------------------------------------------------------------------------------------------
// @brief OLED显示有符号数(6*8字体)
// @param x x轴坐标设置0-127
// @param y y轴坐标设置0-7
// @param num 有符号数
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void oled_int16(uint8 x, uint8 y, int16 num)
{
int8 ch[7];
if(num<0)
{
num = -num;
oled_p6x8str(x, y, "-");
}
else
oled_p6x8str(x, y, " ");
x+=6;
oled_hexascii(num,ch);
oled_p6x8str(x, y, &ch[1]); // 显示数字 6*8字体
}
//-------------------------------------------------------------------------------------------------------------------
// @brief OLED显示32位有符号(去除整数部分无效的0)
// @param x x轴坐标设置0-127
// @param y y轴坐标设置0-7
// @param dat 需要显示的变量,数据类型uint32
// @param num 需要显示的位数 最高10位 不包含正负号
// @return void
// @since v1.0
// Sample usage: oled_printf_int32(0,0,x,5);//x可以为int32 uint16 int16 uint8 int8类型
// Sample usage: 负数会显示一个 ‘-’号 正数显示一个空格
//-------------------------------------------------------------------------------------------------------------------
void oled_printf_int32(uint16 x,uint16 y,int32 dat,uint8 num)
{
int8 buff[34];
uint8 length;
if(10<num) num = 10;
num++;
if(0>dat)
length = zf_sprintf( &buff[0],"%d",dat); // 负数
else
{
buff[0] = ' ';
length = zf_sprintf( &buff[1],"%d",dat);
length++;
}
while(length < num)
{
buff[length] = ' ';
length++;
}
buff[num] = '\0';
oled_p6x8str(x, y, buff); // 显示数字
}
//-------------------------------------------------------------------------------------------------------------------
// @brief OLED显示浮点数(去除整数部分无效的0)
// @param x x轴坐标设置0-127
// @param y y轴坐标设置0-7
// @param dat 需要显示的变量,数据类型float或double
// @param num 整数位显示长度 最高10位
// @param pointnum 小数位显示长度 最高6位
// @return void
// @since v1.0
// Sample usage: oled_printf_float(0,0,x,2,3);//显示浮点数 整数显示2位 小数显示三位
// @note 特别注意当发现小数部分显示的值与你写入的值不一样的时候,
// 可能是由于浮点数精度丢失问题导致的,这并不是显示函数的问题,
// 有关问题的详情,请自行百度学习 浮点数精度丢失问题。
// 负数会显示一个 ‘-’号 正数显示一个空格
//-------------------------------------------------------------------------------------------------------------------
void oled_printf_float(uint16 x,uint16 y,double dat,uint8 num,uint8 pointnum)
{
static uint8 length;
static int8 buff[34];
static int8 end,point;
static int start;
if(6<pointnum)
pointnum = 6;
if(10<num)
num = 10;
if(0>dat)
length = zf_sprintf( &buff[0],"%f",dat); // 负数
else
{
length = zf_sprintf( &buff[1],"%f",dat);
length++;
}
point = length - 7; // 计算小数点位置
start = point - num - 1; // 计算起始位
end = point + pointnum + 1; // 计算结束位
while(start < 0) // 整数位不够 末尾应该填充空格
{
buff[end] = ' ';
end++;
start++;
}
if(0>dat)
buff[start] = '-';
else
buff[start] = ' ';
buff[end] = '\0';
oled_p6x8str(x, y, buff); // 显示数字
}
//-------------------------------------------------------------------------------------------------------------------
// @brief OLED显示图像
// @param high 图像高度
// @param width 图像宽度
// @param *p 图像地 址(数组)
// @param value 二值化阀值
// @return void
// @since v1.0
// Sample usage:
// @Note 使用Image2lcd V3.2软件取模 C语言数组 水平扫描
// 宽度高度自行设置 颜色反转 256色
//-------------------------------------------------------------------------------------------------------------------
void oled_dis_bmp(uint16 high, uint16 width, uint8 *p,uint8 value)
{
int16 i,j;
int16 temp,temp1;
uint8 dat;
temp1 = high%8;
if(temp1 == 0)
temp = high/8;
else
temp = high/8+1;
for(i=0; i<temp; i++)
{
oled_set_pos(0,i);
for(j=0; j<width; j++)
{
dat = 0;
if( i<(temp-1) || !temp1 || temp1>=1)dat |= (*(p+i*8*width+j+width*0) > value? 1: 0)<<0;
if( i<(temp-1) || !temp1 || temp1>=2)dat |= (*(p+i*8*width+j+width*1) > value? 1: 0)<<1;
if( i<(temp-1) || !temp1 || temp1>=3)dat |= (*(p+i*8*width+j+width*2) > value? 1: 0)<<2;
if( i<(temp-1) || !temp1 || temp1>=4)dat |= (*(p+i*8*width+j+width*3) > value? 1: 0)<<3;
if( i<(temp-1) || !temp1 || temp1>=5)dat |= (*(p+i*8*width+j+width*4) > value? 1: 0)<<4;
if( i<(temp-1) || !temp1 || temp1>=6)dat |= (*(p+i*8*width+j+width*5) > value? 1: 0)<<5;
if( i<(temp-1) || !temp1 || temp1>=7)dat |= (*(p+i*8*width+j+width*6) > value? 1: 0)<<6;
if( i<(temp-1) || !temp1 || temp1>=8)dat |= (*(p+i*8*width+j+width*7) > value? 1: 0)<<7;
oled_wrdat(dat);
}
}
}
//-------------------------------------------------------------------------------------------------------------------
// @brief 汉字显示
// @param x 横坐标 0-127
// @param y 纵坐标 0-7
// @param size 取模的时候设置的汉字字体大小,也就是一个汉字占用的点阵长宽为多少个点,取模的时候需要长宽是一样的。
// @param *p 需要显示的汉字数组
// @param len 需要显示多少位
// @return void
// @since v1.0
// Sample usage:
// @Note 使用PCtoLCD2002软件取模 阴码、逐行式、顺向 16*16
//-------------------------------------------------------------------------------------------------------------------
void oled_print_chinese(uint8 x, uint8 y, uint8 size, const uint8 *p, uint8 len)
{
int16 i,j,k;
for(i=0; i<len; i++)
{
for(j=0; j<(size/8); j++)
{
oled_set_pos(x+i*size,y+j);
for(k=0; k<16; k++)
{
oled_wrdat(*p);
p++;
}
}
}
}
//格式化
uint8 number_conversion_ascii(uint32 dat, int8 *p, uint8 neg_type, uint8 radix)
{
int32 neg_dat;
uint32 pos_dat;
uint8 temp_data = 0;
uint8 valid_num = 0;
if(neg_type)
{
neg_dat = (int32)dat;
if(neg_dat<0) neg_dat = -neg_dat;
while(1)
{
*p = neg_dat%radix + '0';
neg_dat = neg_dat/radix;
valid_num++;
if(!neg_dat) break;
p++;
}
}
else
{
pos_dat = dat;
while(1)
{
temp_data = pos_dat%radix;
if(10 <= temp_data) temp_data += 'A'-10;
else temp_data += '0';
*p = temp_data;
pos_dat = pos_dat/radix;
valid_num++;
if(!pos_dat) break;
p++;
}
}
return valid_num;
}
void printf_reverse_order(int8 *d_buff, uint32 len)
{
uint32 i;
int8 temp_data;
for(i=0;i<len/2;i++)
{
temp_data = d_buff[len-1-i];
d_buff[len-1-i] = d_buff[i];
d_buff[i] = temp_data;
}
}
uint32 zf_sprintf(int8 *buff, const int8 *format, ...)
{
uint32 buff_len=0;
va_list arg;
va_start(arg, format);
while (*format)
{
int8 ret = *format;
if (ret == '%')
{
switch (*++format)
{
case 'a':// 十六进制p计数法输出浮点数 暂未实现
{
}
break;
case 'c':// 一个字符
{
int8 ch = (int8)va_arg(arg, uint32);
*buff = ch;
buff++;
buff_len++;
}
break;
case 'd':
case 'i':// 有符号十进制整数
{
int8 vstr[33];
int32 ival = (int32)va_arg(arg, int32);
uint8 vlen = number_conversion_ascii((uint32)ival, vstr, 1, 10);
if(ival<0)
{
vstr[vlen] = '-';
vlen++;
}
printf_reverse_order(vstr,vlen);
memcpy(buff,vstr,vlen);
buff += vlen;
buff_len += vlen;
}
break;
case 'f':// 浮点数,输出小数点后六位 不能指定输出精度
case 'F':// 浮点数,输出小数点后六位 不能指定输出精度
{
int8 vstr[33];
double ival = (double)va_arg(arg, double);
uint8 vlen = number_conversion_ascii((uint32)(int32)ival, vstr, 1, 10);
if(ival<0)
{
vstr[vlen] = '-';
vlen++;
}
printf_reverse_order(vstr,vlen);
memcpy(buff,vstr,vlen);
buff += vlen;
buff_len += vlen;
ival = ((double)ival - (int32)ival)*1000000;
if(ival)
{
vlen = number_conversion_ascii((uint32)(int32)ival, vstr, 1, 10);
}
else
{
vstr[0] = vstr[1] = vstr[2] = vstr[3] = vstr[4] = vstr[5] = '0';
vlen = 6;
}
while(6>vlen)
{
vstr[vlen] = '0';
vlen++;
}
vstr[vlen] = '.';
vlen++;
printf_reverse_order(vstr,vlen);
memcpy(buff,vstr,vlen);
buff_len += vlen;
}
break;
case 'u':// 无符号十进制整数
{
int8 vstr[33];
uint32 ival = (uint32)va_arg(arg, uint32);
uint8 vlen = number_conversion_ascii(ival, vstr, 0, 10);
printf_reverse_order(vstr,vlen);
memcpy(buff,vstr,vlen);
buff += vlen;
buff_len += vlen;
}
break;
case 'o':// 无符号八进制整数
{
int8 vstr[33];
uint32 ival = (uint32)va_arg(arg, uint32);
uint8 vlen = number_conversion_ascii(ival, vstr, 0, 8);
printf_reverse_order(vstr,vlen);
memcpy(buff,vstr,vlen);
buff += vlen;
buff_len += vlen;
}
break;
case 'x':// 无符号十六进制整数
case 'X':// 无符号十六进制整数
{
int8 vstr[33];
uint32 ival = (uint32)va_arg(arg, uint32);
uint8 vlen = number_conversion_ascii(ival, vstr, 0, 16);
printf_reverse_order(vstr,vlen);
memcpy(buff,vstr,vlen);
buff += vlen;
buff_len += vlen;
}
break;
case 's':// 字符串
{
int8 *pc = va_arg(arg, int8 *);
while (*pc)
{
*buff = *pc;
buff++;
buff_len++;
pc++;
}
}
break;
case 'p':// 以16进制形式输出指针
{
int8 vstr[33];
uint32 ival = (uint32)va_arg(arg, uint32);
uint8 vlen = number_conversion_ascii(ival, vstr, 0, 16);
printf_reverse_order(vstr,8);
memcpy(buff,vstr,8);
buff += 8;
buff_len += 8;
}
break;
case '%':// 输出字符%
{
*buff = '%';
buff++;
buff_len++;
}
break;
default:
break;
}
}
else
{
*buff = (int8)(*format);
buff++;
buff_len++;
}
format++;
}
va_end(arg);
return buff_len;
}
oled.h
#ifndef _OLED_H_
#define _OLED_H_
#include "headfile.h"
//----宏定义OLED引脚----
#define OLED_SCL_PORT GPIO_PORT_P3
#define OLED_SDA_PORT GPIO_PORT_P5
#define OLED_RST_PORT GPIO_PORT_P5
#define OLED_DC_PORT GPIO_PORT_P3
#define OLED_CS_PORT GPIO_PORT_P3
#define OLED_SCL_PIN GPIO_PIN6
#define OLED_SDA_PIN GPIO_PIN2
#define OLED_RST_PIN GPIO_PIN0
#define OLED_DC_PIN GPIO_PIN7
#define OLED_CS_PIN GPIO_PIN5
//定义显示方向
//0 横屏模式
//1 横屏模式 旋转180
#define OLED_DISPLAY_DIR 0
#if (0==OLED_DISPLAY_DIR || 1==OLED_DISPLAY_DIR)
#define X_WIDTH 128
#define Y_WIDTH 64
#else
#error "OLED_DISPLAY_DIR 定义错误"
#endif
#define Brightness 0x7f // 设置OLED亮度 越大越亮 范围0-0XFF
#define XLevelL 0x00
#define XLevelH 0x10
#define XLevel ((XLevelH&0x0F)*16+XLevelL)
#define Max_Column 128
#define Max_Row 64
void oled_init (void);
void oled_fill (uint8 dat);
void oled_set_pos (uint8 x, uint8 y);
void oled_putpixel (uint8 x,uint8 y,uint8 data1);
void oled_clrpixel (uint8 x,uint8 y);
void oled_p6x8str (uint8 x,uint8 y,const int8 ch[]);
void oled_p8x16str (uint8 x,uint8 y,const int8 ch[]);
void oled_uint16 (uint8 x, uint8 y, uint16 num);
void oled_int16 (uint8 x, uint8 y, int16 num);
void oled_printf_int32 (uint16 x,uint16 y,int32 dat,uint8 num);
void oled_printf_float (uint16 x,uint16 y,double dat,uint8 num,uint8 pointnum);
void oled_dis_bmp (uint16 high, uint16 width, uint8 *p,uint8 value);
void oled_print_chinese (uint8 x, uint8 y, uint8 size, const uint8 *p, uint8 len);
//格式化
uint32 zf_sprintf(int8 *buff, const int8 *format, ...);
#endif
font.c
//font
#include "font.h"
const uint8 oled_6x8[][6] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
{ 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
{ 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
{ 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
{ 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
{ 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %
{ 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
{ 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
{ 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
{ 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
{ 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
{ 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
{ 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,
{ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
{ 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
{ 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
{ 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
{ 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
{ 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
{ 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
{ 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
{ 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
{ 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
{ 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
{ 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
{ 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9
{ 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
{ 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
{ 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
{ 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
{ 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
{ 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
{ 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @
{ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
{ 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
{ 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
{ 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
{ 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
{ 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
{ 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
{ 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
{ 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
{ 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P
{ 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q
{ 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R
{ 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
{ 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T
{ 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U
{ 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V
{ 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W
{ 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
{ 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
{ 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
{ 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [
{ 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55
{ 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]
{ 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
{ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
{ 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '
{ 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
{ 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
{ 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d
{ 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
{ 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f
{ 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g
{ 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h
{ 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i
{ 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j
{ 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k
{ 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l
{ 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
{ 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p
{ 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r
{ 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
{ 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t
{ 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u
{ 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v
{ 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w
{ 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
{ 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y
{ 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z
{ 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines
};
const uint8 oled_8x16[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00, // ! 1
0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // " 2
0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00, // # 3
0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00, // $ 4
0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00, // % 5
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10, // & 6
0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ' 7
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00, // ( 8
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00, // ) 9
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00, // * 10
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00, // + 11
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00, // , 12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01, // - 13
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00, // . 14
0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00, // / 15
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00, // 0 16
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, // 1 17
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00, // 2 18
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00, // 3 19
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00, // 4 20
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00, // 5 21
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00, // 6 22
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, // 7 23
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00, // 8 24
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00, // 9 25
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00, // : 26
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00, // ; 27
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00, // < 28
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00, // = 29
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00, // > 30
0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00, // ? 31
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00, // @ 32
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20, // A 33
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00, // B 34
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00, // C 35
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00, // D 36
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00, // E 37
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00, // F 38
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00, // G 39
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20, // H 40
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, // I 41
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00, // J 42
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00, // K 43
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00, // L 44
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00, // M 45
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00, // N 46
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00, // O 47
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00, // P 48
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00, // Q 49
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20, // R 50
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00, // S 51
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00, // T 52
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00, // U 53
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00, // V 54
0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00, // W 55
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20, // X 56
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00, // Y 57
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00, // Z 58
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00, // [ 59
0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00, // \ 60
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00, // ] 61
0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ^ 62
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, // _ 63
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ` 64
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20, // a 65
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00, // b 66
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00, // c 67
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20, // d 68
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00, // e 69
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, // f 70
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00, // g 71
0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20, // h 72
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, // i 73
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00, // j 74
0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00, // k 75
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, // l 76
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F, // m 77
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20, // n 78
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00, // o 79
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00, // p 80
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80, // q 81
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00, // r 82
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00, // s 83
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00, // t 84
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20, // u 85
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00, // v 86
0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00, // w 87
0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00, // x 88
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00, // y 89
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00, // z 90
0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40, // { 91
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00, // | 92
0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00, // } 93
0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // ~ 94
};
font.h
#ifndef _FONT_H_
#define _FONT_H_
#include "headfile.h"
extern const uint8 oled_6x8[][6];
extern const uint8 oled_8x16[];
#endif
直接复制即可
在初始化后直接调用,就可以显示各种字符以及变量
实际效果:
(二) 注意事项
在移植过程中使用了模拟SPI进行通信,需要按照h文件中的引脚接线即可;
初始化的时候需要先把引脚初始化,使用宏可以修正引脚
(三)杂谈
msp432中有一个专门的lcd控制器,支持的lcd应该是那种8080总线的屏幕,可以按照demo进行配置,在此只是使用oled;
克隆空白工程请使用 git , 如果你觉得还不错欢迎点亮 star !
git clone https://github.com/YGZone/Design-a-car-with-MSP432P401R.git