Arduino和C51开发OLED显⽰屏
技术:51单⽚机、Arduino、OLED显⽰屏、U8glib
概述arduino字符串转数组
OLED显⽰屏常常⽤作为智能产品的显⽰设备,本⽂简单介绍OLED显⽰屏的使⽤⽅法。
详细
代码下载:
⼀、OLED显⽰屏
OLED显⽰屏是利⽤有机电⾃发光⼆极管制成的显⽰屏。由于同时具备⾃发光有机电激发光⼆极管,不需背光源、对⽐度⾼、厚度薄、视⾓⼴、反应速度快、可⽤于挠曲性⾯板、使⽤温度范围⼴、构造及制程较简单等优异之特性,被认为是下⼀代的平⾯显⽰器新兴应⽤技术。
这⾥我们使⽤的0.96⼨的OLED显⽰屏,它的显⽰区域是128*64的点阵,每个点都能⾃⼰发光。OLED显⽰屏可以显⽰汉字、字符和图案等,智能⼿环和智能⼿表等智能设备⼀般都是选择OLED显⽰屏来作为显⽰设备。
⼆、51单⽚机 — OLED显⽰屏
硬件连接:
这⾥简单介绍OLED显⽰中⽂:
1. 打开PCtoLCD200
< -> 选项,修改⼀些选项:
2. 输⼊你想要显⽰的汉字,点击->⽣成字模,复制下⾯的数组即可:
我这⾥输⼊的是:”显⽰屏测试程序”,对应数组为:
{0x00,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x00},
{0x40,0x42,0x44,0x58,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x50,0x48,0x46,0x40,0x00},/*"显",0*/ {0x40,0x40,0x42,0x42,0x42,0x42,0x42,0xC2,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00},
{0x20,0x10,0x08,0x06,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x02,0x04,0x08,0x30,0x00},/*"⽰",1*/ {0x00,0x00,0xFE,0x12,0x92,0xB2,0xD2,0x92,0x92,0x92,0xD2,0xB2,0x9E,0x00,0x00,0x00},
{0x40,0x30,0x0F,0x04,0x84,0x64,0x1F,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x00,0x00},/*"屏",2*/ {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},/*"测",3*/ {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},/*"试",4*/ {0x24,0x24,0xA4,0xFE,0x23,0x22,0x00,0x3E,0x22,0x22,0x22,0x22,0x22,0x3E,0x00,0x00},
{0x08,0x06,0x01,0xFF,0x01,0x06,0x40,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x41,0x00},/*"程",5*/ {0x00,0x00,0xFC,0x04,0x04,0x04,0x14,0x15,0x56,0x94,0x54,0x34,0x14,0x04,0x04,0x00},
{0x40,0x30,0x0F,0x00,0x01,0x01,0x01,0x41,0x81,0x7F,0x01,0x01,0x01,0x05,0x03,0x00},/*"序",6*/想要显⽰出来的话,要把这些数组放到oledfont.h⽂件下:
main函数代码:
int main(void)
{
u8 t;
OLED_Init();  //初始化OLED
OLED_Clear();  //清屏
t=' ';
while(1)
{
OLED_ShowCHinese(0,0,0); //0:显
OLED_ShowCHinese(18,0,1);//1:⽰
OLED_ShowCHinese(36,0,2);//2:屏
OLED_ShowCHinese(54,0,3);//3:测
OLED_ShowCHinese(72,0,4);//4:试
OLED_ShowCHinese(90,0,5);//5:程
OLED_ShowCHinese(108,0,6);//6:序
OLED_ShowString(0,2,"1.3' OLED TEST"); //打印字符串
OLED_ShowString(20,4,"2018/12/25");
OLED_ShowString(0,6,"ASCII:");
OLED_ShowString(63,6,"CODE:");
OLED_ShowChar(48,6,t);//显⽰ASCII字符
t++;
if(t>'~')
t=' ';
OLED_ShowNum(103,6,t,3,16);//显⽰ASCII字符的码值
delay1s();
}
}
程序显⽰效果如下:
三、Arduino — OLED显⽰屏
硬件连接:
加载库⽂件:
打开Arduino IDE -> 项⽬ -> 加载库 -> 管理库中搜索U8glib,然后安装即可。
OLED显⽰屏显⽰代码:
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(10, 9, 12, 11, 13); //创建对象
void setup(void) {
}
void loop(void) {
for(int i=10;i<80;i++){
u8g.firstPage();  //表⽰图像循环的开始
do {
u8g.setFont(u8g_font_fub30);//设置字体和⾃号
u8g.setPrintPos(70, 50); //显⽰的位置
u8g.print(i);//显⽰变量i的值
u8g.setFont(u8g_font_fub30);//设置字体和⾃号
u8g.setPrintPos(20, 50); //显⽰的位置
u8g.print("i=");//显⽰ "i = "
}while( Page() );//Page() 表⽰图像循环的结束
delay(500);//显⽰的时间间隔
}
}
效果图如下:
四、总结
本⽂简单描述了OLED显⽰屏,并教⼤家如何⽤C51和Arduino进⾏开发。OLED显⽰屏显⽰效果⾮常的好,所以常常也被⽤来做⼀些智能设备的显⽰屏,下篇⽂章我也会教⼤家如何在OLED显⽰屏上显⽰时钟、温湿度值和光照强度等信息。
五、项⽬结构图
代码下载:
注:本⽂著作权归作者,由demo⼤师发表,拒绝转载,转载需要作者授权

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。