学习oled这个就够了,oled单片机驱动源码版本V6.0-S13-SPI
原理图
下面这些平台的源码都有:
下面是例程都是有完整的源码(包含各种单片机及嵌入式系统的驱动源码):
(01)OLED_stm32 显示例程
(02)OLED_XS128 用PA0123
(03)OLED_K60演示
(04)OLED_STC&52
(05)OLED_LQ-XS128用PE2345
(06)OLED_XS128-SPI采用标准SPI总线
(07)OLED_demo52259正式版
(08)OLED_arduino_SPI_例程
(09)OLED_C51系列_SPI_例程
(10)OLED_MSP430系列_SPI_例程
(11)OLED_PIC系列_SPI_例程
资料还包含
OLED裸屏用户资料\
原理图\
取模软件\
程序例程\
OLED 模块 使用说明.pdf
字模软件的使用.pdf
下面是教程的部分内容截图:
资料包里面还有(各种屏的详细资料):
OLED开发设计说明-研发必读-100309(1).pdf
SAS1-9046-B UG-2864HSWEG01-Univision.pdf
SSD1306-Revision 1.1 (Charge Pump).pdf
UG-2864HSWEG01 Drawing - 090120B.pdf
UG-2864HSWEG01 user guide.pdf
下面分享个stm32单片机的源码:
1、该代码已经经过实测验证OK
2、单片机采有stm32f103zevt
3、晶振为8M,总线时钟为24M(/* PLLCLK = 8MHz / 2 * 6 = 24 MHz */),若你的环境与该代码不一样,请自行修改spi通信部分延时
4、管脚定义:
//-----------------OLED端口定义----------------
#define LCD_SCL_CLR() GPIO_ResetBits(GPIOB,GPIO_Pin_1)
#define LCD_SCL_SET() GPIO_SetBits(GPIOB,GPIO_Pin_1)
#define LCD_SDA_CLR() GPIO_ResetBits(GPIOB,GPIO_Pin_2)
#define LCD_SDA_SET() GPIO_SetBits(GPIOB,GPIO_Pin_2)
#define LCD_RST_CLR() GPIO_ResetBits(GPIOB,GPIO_Pin_3)
#define LCD_RST_SET() GPIO_SetBits(GPIOB,GPIO_Pin_3)
#define LCD_DC_CLR() GPIO_ResetBits(GPIOB,GPIO_Pin_4)
#define LCD_DC_SET() GPIO_SetBits(GPIOB,GPIO_Pin_4)
5、电路连接:
VCC接3.3V,IO口直接单片机,不需要上拉电阻或串联电阻
6、程序如果没有调通,液晶是无显示的,也就是黑屏,请耐心调试,有疑问可以跟我们联系,谢谢
- /*OLED底层驱动
- *@采用列行式,分辨率为128*64
- *存放格式如下.
- *[0]0 1 2 3 ... 127
- *[1]0 1 2 3 ... 127
- *[2]0 1 2 3 ... 127
- *[3]0 1 2 3 ... 127
- *[4]0 1 2 3 ... 127
- *[5]0 1 2 3 ... 127
- *[6]0 1 2 3 ... 127
- *[7]0 1 2 3 ... 127
- */
- #include "stm32f10x_lib.h"
- #include "stdlib.h"
- #include "userinc/OLED.h"
- #define XLevelL 0x00
- #define XLevelH 0x10
- #define XLevel ((XLevelH&0x0F)*16+XLevelL)
- #define Max_Column 128
- #define Max_Row 64
- #define Brightness 0xCF
- #define X_WIDTH 128
- #define Y_WIDTH 64
- //======================================
- const u8 F6x8[] =
- {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , // sp
- …………限于本文篇幅 字库请从51黑电子论坛下载附件…………
- 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 // horiz lines
- };
- const u8 F16x16_Idx[] =
- {
- "测距离周长面积度高坡亩仪搜索卫星大小查记录删除系统值设单价公顷元询每电池压经纬°㎡型号版本剩余空间返回退出"
- };
- const u8 F16x16[] =
- {
- 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,//测0,
- …………限于本文篇幅 字库请从51黑电子论坛下载附件…………
- };
- //======================================================
- // 128X64I液晶底层驱动[8X16]字体库
- // 设计者: powerint
- // 描 述: [8X16]西文字符的字模数据 (纵向取模,字节倒序)
- // !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
- //======================================================
- const u8 F8X16[]=
- {
- 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
- …………限于本文篇幅 字库请从51黑电子论坛下载附件…………
- };
- /* 生成实心菱形图标的16*16点阵*/
- const u8 nonside[] =
- {
- 0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,//◆0,
- };
- void LCD_WrDat(u8 data)
- {
- u8 i=8;
- //LCD_CS=0;;
- LCD_DC_SET();
- LCD_SCL_CLR();
- //asm("nop");
- while(i--)
- {
- if(data&0x80){LCD_SDA_SET();}
- else{LCD_SDA_CLR();}
- LCD_SCL_SET();
- //asm("nop");;
- //asm("nop");
- LCD_SCL_CLR();
- data<<=1;
- }
- //LCD_CS=1;
- }
- void LCD_WrCmd(u8 cmd)
- {
- u8 i=8;
-
- //LCD_CS=0;;
- LCD_DC_CLR();
- LCD_SCL_CLR();
- //asm("nop");
- while(i--)
- {
- if(cmd&0x80){LCD_SDA_SET();}
- else{LCD_SDA_CLR();}
- LCD_SCL_SET();
- //asm("nop");;
- //asm("nop");
- LCD_SCL_CLR();
- cmd<<=1;;
- }
- //LCD_CS=1;
- }
- /*设置起始地址
- *Y轴是按8格递进的,y轴0~63,只能按8格的倍数显示,
- *因为列行式只能按8个字节进行
- */
- void LCD_Set_Pos(u8 x, u8 y)
- {
- LCD_WrCmd(0xb0+(y>>3));
- LCD_WrCmd(((x&0xf0)>>4)|0x10);
- LCD_WrCmd((x&0x0f)|0x01);
- }
- void LCD_Fill(u8 bmp_data)
- {
- u8 y,x;
-
- for(y=0;y<8;y++)
- {
- LCD_WrCmd(0xb0+y);
- LCD_WrCmd(0x01);
- LCD_WrCmd(0x10);
- for(x=0;x<X_WIDTH;x++)
- LCD_WrDat(bmp_data);
- }
- }
- void LCD_CLS(void)
- {
- u8 y,x;
- for(y=0;y<8;y++)
- {
- LCD_WrCmd(0xb0+y);
- LCD_WrCmd(0x01);
- LCD_WrCmd(0x10);
- for(x=0;x<X_WIDTH;x++)
- LCD_WrDat(0);
- }
- }
- //清除一行0-63
- void LCD_CLS_y(char y)
- {
- u8 x;
-
- LCD_WrCmd(0xb0+(y>>3));
- LCD_WrCmd(0x01);
- LCD_WrCmd(0x10);
- for(x=0;x<X_WIDTH;x++)
- {
- LCD_WrDat(0);
- }
-
- }
- //清除一行上的一块区域y=0-63
- void LCD_CLS_line_area(u8 start_x,u8 start_y,u8 width)
- {
- u8 x;
-
- LCD_WrCmd(0xb0+(start_y>>3));
- LCD_WrCmd(0x01);
- LCD_WrCmd(0x10);
- for(x=start_x;x<width;x++)
- {
- LCD_WrDat(0);
- }
-
- }
- void LCD_DLY_ms(u16 ms)
- {
- u16 a;
- while(ms)
- {
- a=1335;
- while(a--);
- ms--;
- }
- return;
- }
- void LCD_Init(void)
- {
- //DDRA=0XFF;
-
- LCD_SCL_SET();
- //LCD_CS=1; //预制SLK和SS为高电平
-
- LCD_RST_CLR();
- LCD_DLY_ms(50);
- LCD_RST_SET();
- LCD_WrCmd(0xae);//--turn off oled panel
- LCD_WrCmd(0x00);//---set low column address
- LCD_WrCmd(0x10);//---set high column address
- LCD_WrCmd(0x40);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
- LCD_WrCmd(0x81);//--set contrast control register
- LCD_WrCmd(0xcf); // Set SEG Output Current Brightness
- LCD_WrCmd(0xa1);//--Set SEG/Column Mapping 0xa0左右反置 0xa1正常
- LCD_WrCmd(0xc8);//Set COM/Row Scan Direction 0xc0上下反置 0xc8正常
- LCD_WrCmd(0xa6);//--set normal display
- LCD_WrCmd(0xa8);//--set multiplex ratio(1 to 64)
- LCD_WrCmd(0x3f);//--1/64 duty
- LCD_WrCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
- LCD_WrCmd(0x00);//-not offset
- LCD_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency
- LCD_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
- LCD_WrCmd(0xd9);//--set pre-charge period
- LCD_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
- LCD_WrCmd(0xda);//--set com pins hardware configuration
- LCD_WrCmd(0x12);
- LCD_WrCmd(0xdb);//--set vcomh
- LCD_WrCmd(0x40);//Set VCOM Deselect Level
- LCD_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
- LCD_WrCmd(0x02);//
- LCD_WrCmd(0x8d);//--set Charge Pump enable/disable
- LCD_WrCmd(0x14);//--set(0x10) disable
- LCD_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
- LCD_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7)
- LCD_WrCmd(0xaf);//--turn on oled panel
- LCD_Fill(0x00); //初始清屏
- LCD_Set_Pos(0,0);
-
- }
- //==============================================================
- //函数名: void LCD_PutPixel(u8 x,u8 y)
- //功能描述:绘制一个点(x,y)
- //参数:真实坐标值(x,y),x的范围0~127,y的范围0~64
- //返回:无
- //==============================================================
- void LCD_PutPixel(u8 x,u8 y)
- {
- u8 data1; //data1当前点的数据
-
- //LCD_Set_Pos(x,y);
- data1 = 0x01<<(y%8);
- LCD_WrCmd(0xb0+(y>>3));
- LCD_WrCmd(((x&0xf0)>>4)|0x10);
- LCD_WrCmd((x&0x0f)|0x00);
- LCD_WrDat(data1);
- }
- //==============================================================
- //函数名: void LCD_Put_Column(u8 x,u8 y,u8 data)
- //功能描述:操作一列显示,一列全显示0XFF,清除一列0X00;
- //参数:真实坐标值(x,y),x的范围0~127,y的范围0~64
- //返回:无
- //==============================================================
- void LCD_Put_Column(u8 x,u8 y,u8 data)
- {
- LCD_WrCmd(0xb0+(y>>3));
- LCD_WrCmd(((x&0xf0)>>4)|0x10);
- LCD_WrCmd((x&0x0f)|0x00);
- LCD_WrDat(data);
- }
- //==============================================================
- //函数名: void LCD_Rectangle(u8 x1,u8 y1,
- // u8 x2,u8 y2,u8 color,u8 gif)
- //功能描述:绘制一个实心矩形
-
- …………限于本文篇幅 完整源码请从51黑论坛下载附件…………
复制代码
全部资料下载:
V6.0-S13-SPI.rar
(13.28 MB, 下载次数: 867)
|