我本来手里有一个一半是黄色的一半是白色的OLED,我从网上买的。但我买回来之后就没有点亮过。
我十分伤心。我问了卖家,卖家也发了资料,我十分恼火,主要是这款OLED娘过可以变IIC通讯,还可以四线SPI,还可以三线SPI
我用烙铁焊了后边的跳线。把它变成IIC的驱动没有驱起来,我把它变成三线的还是黑乎乎一片。变成四线的还是。
泥马。。。。。。。老子不搞了行吧。。。。。。。。
就这样我一脚把这款屏打入了“冷宫“(盒子里)。一放就是三年。
三年以后。。。。。。。。
我参加了这个MM32F031的活动。我又把它给想起来了。看了一下是IIC的我就烦了(因为得加上拉。本人是个懒人,不想接上拉电阻来这),又跳回了三线SPI,就是没有那个发线的。本来想一举成功,泥马还是没有亮。
我十分伤心,在我心里,它一定是坏了,或是卖家给我时就是坏的。万能的淘宝,黑心的卖家。。。。。。。
本来这是上个星期的是,但我SPI软硬都驱动了SPI 2.2寸彩屏。给了我一定的自信能驱动这个OLED。
于是我忍痛割爱,花了13块大洋。又从网上包邮一个回来。
全是白色的(我喜欢)。又是一个星期天了,又一个轮回。
早晨起来仍旧调程序。我先到网上收一下这个OLED的例程。本来想从卖家那里要资业,不过应是南方的卖家,没答理我,我想他不没有起来。
我从网上收了贴子都是51的多我就下了一个改了起来。
oled.h
- #ifndef __OLED_H__
- #define __OLED_H__
- #include "HAL_conf.h"
- #include "stdlib.h"
- #define OLED 0
- #define SIZE 16
- #define XLevelL 0x00
- #define XLevelH 0x10
- #define Max_Column 128
- #define Max_Row 64
- #define Brightness 0xff
- #define X_WIDTH 128
- #define Y_WIDTH 64
- //IO Definitions
- #define CS PDout(3)
- #define RST PDout(4)
- #define DC PDout(5)
- #define CLK PDout(6)
- #define DIN PDout(7)
- #define OLED_CS_Clr() GPIO_ResetBits(GPIOB,GPIO_Pin_12);//CS = 0 //CS
- #define OLED_CS_Set() GPIO_SetBits(GPIOB,GPIO_Pin_12);//CS = 1
- #define OLED_RST_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_12);//RST = 0 //RES
- #define OLED_RST_Set() GPIO_SetBits(GPIOA,GPIO_Pin_12);//RST = 1
- #define OLED_DC_Clr() GPIO_ResetBits(GPIOA,GPIO_Pin_11);//DC = 0 //DC
- #define OLED_DC_Set() GPIO_SetBits(GPIOA,GPIO_Pin_11);//DC = 1
- #define OLED_SCLK_Clr() GPIO_ResetBits(GPIOB,GPIO_Pin_13);//CLK = 0//CLK--D0
- #define OLED_SCLK_Set() GPIO_SetBits(GPIOB,GPIO_Pin_13);//CLK = 1
- #define OLED_SDIN_Clr() GPIO_ResetBits(GPIOB,GPIO_Pin_15);//DIN = 0 //DIN--D1
- #define OLED_SDIN_Set() GPIO_SetBits(GPIOB,GPIO_Pin_15);//DIN = 1
- typedef enum
- {
- OLED_CMD,
- OLED_DATA
- }OLED_WR_MODE;
- typedef enum
- {
- Display_ON,
- Display_OFF,
- Display_Clear,
- Display_Test
- }DIS_MODE;
- //OLED?????
- extern void OLED_WR_Byte(uint8_t dat,OLED_WR_MODE cmd);
- extern void OLED_Display_Status(DIS_MODE mode);
- extern void OLEDConfiguration(void);
- extern void OLED_DrawPoint(uint8_t x, uint8_t y, uint8_t t);
- extern void OLED_Fill(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t dot);
- extern void OLED_ShowChar(uint8_t x, uint8_t y, uint8_t chr);
- extern void OLED_ShowNum(uint8_t x, uint8_t y, u32 num, uint8_t len, uint8_t size);
- extern void OLED_ShowString(uint8_t x,uint8_t y, uint8_t *p);
- extern void OLED_Set_Pos(uint8_t x, uint8_t y);
- extern void OLED_ShowCHinese(uint8_t x, uint8_t y, uint8_t no);
- extern void OLED_DrawBMP(uint8_t x0, uint8_t y0,uint8_t x1, uint8_t y1, uint8_t BMP[]);
- #endif
oled.c
- #include "oled.h"
- #include "delay.h"
- const unsigned char 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
- 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,//016
- 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//117
- 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//218
- 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//319
- 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//420
- 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//521
- 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//622
- 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//723
- 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//824
- 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//925
- 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,//A33
- 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B34
- 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C35
- 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D36
- 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E37
- 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F38
- 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G39
- 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H40
- 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I41
- 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J42
- 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K43
- 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L44
- 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M45
- 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N46
- 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O47
- 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P48
- 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q49
- 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R50
- 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S51
- 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T52
- 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U53
- 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V54
- 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W55
- 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X56
- 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y57
- 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z58
- 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,//a65
- 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b66
- 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c67
- 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d68
- 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e69
- 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f70
- 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g71
- 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h72
- 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i73
- 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j74
- 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k75
- 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l76
- 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m77
- 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n78
- 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o79
- 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p80
- 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q81
- 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r82
- 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s83
- 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t84
- 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u85
- 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v86
- 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w87
- 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x88
- 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y89
- 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z90
- 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
- };
- void OLED_WR_Byte(uint8_t dat,OLED_WR_MODE cmd)
- {
- uint8_t i;
- switch(cmd)
- {
- case OLED_CMD:
- OLED_DC_Clr();
- break;
- case OLED_DATA:
- OLED_DC_Set();
- break;
- }
- OLED_CS_Clr();
- for(i = 0; i < 8; i ++)
- {
- OLED_SCLK_Clr();
- if(dat & 0x80)
- {
- OLED_SDIN_Set();
- }
- else
- OLED_SDIN_Clr();
- OLED_SCLK_Set();
- dat<<=1;
- }
- OLED_CS_Set();
- OLED_DC_Set();
- }
- void OLED_Set_Pos(uint8_t x, uint8_t y)
- {
- OLED_WR_Byte(0xB0 + y, OLED_CMD);
- OLED_WR_Byte(((x & 0xF0) >> 4) | 0x10, OLED_CMD);
- OLED_WR_Byte((x & 0x0F) | 0x01, OLED_CMD);
- }
- void OLED_Display_Status(DIS_MODE mode)
- {
- uint8_t i,n;
- switch(mode)
- {
- case Display_ON://??OLED??
- OLED_WR_Byte(0X8D, OLED_CMD); //SET DCDC??
- OLED_WR_Byte(0X14, OLED_CMD); //DCDC ON
- OLED_WR_Byte(0XAF, OLED_CMD); //DISPLAY ON
- break;
- case Display_OFF://??OLED??
- OLED_WR_Byte(0X8D, OLED_CMD); //SET DCDC??
- OLED_WR_Byte(0X10, OLED_CMD); //DCDC OFF
- OLED_WR_Byte(0XAE, OLED_CMD); //DISPLAY OFF
- break;
- case Display_Clear://????,???,????????!??????!!!
- for(i = 0; i < 8; i ++)
- {
- OLED_WR_Byte(0xB0 + i, OLED_CMD); //?????(0~7)
- OLED_WR_Byte(0x00, OLED_CMD); //??????—????
- OLED_WR_Byte(0x10, OLED_CMD); //??????—????
- for(n = 0; n < Max_Column; n ++)
- {
- OLED_WR_Byte(0, OLED_DATA);
- }
- } //????
- break;
- case Display_Test:
- for(i = 0; i < 8; i ++)
- {
- OLED_WR_Byte(0xb0 + i, OLED_CMD); //?????(0~7)
- OLED_WR_Byte(0x00, OLED_CMD); //??????—????
- OLED_WR_Byte(0x10, OLED_CMD); //??????—????
- for(n = 0; n < Max_Column; n ++)
- {
- OLED_WR_Byte(1, OLED_DATA);
- delay_ms(5);
- }
- } //????
- break;
- }
- }
- void OLED_ShowChar(uint8_t x, uint8_t y, uint8_t chr)
- {
- uint8_t c = 0, i = 0;
- c = chr - ' ';//???????
- if(x > Max_Column - 1)
- {
- x = 0;
- y += 2;
- }
- if(SIZE == 16)
- {
- OLED_Set_Pos(x, y);
- for(i = 0; i < 8; i ++)
- {
- OLED_WR_Byte(F8X16[c * 16 + i], OLED_DATA);
- }
- OLED_Set_Pos(x, y + 1);
- for(i = 0; i < 8; i ++)
- {
- OLED_WR_Byte(F8X16[c * 16 + i + 8], OLED_DATA);
- }
- }
- else
- {
- OLED_Set_Pos(x, y + 1);
- for(i = 0; i < 6; i ++)
- {
- // OLED_WR_Byte(F6x8[c][i],OLED_DATA);
- }
- }
- }
- void OLED_ShowChar1(uint8_t x, uint8_t y, uint8_t chr)
- {
- uint8_t c = 0, i = 0;
- c = chr - ' ';//???????
- if(x > Max_Column - 1)
- {
- x = 0;
- y += 2;
- }
- if(SIZE == 16)
- {
- OLED_Set_Pos(x, y);
- for(i = 0; i < 6; i ++)
- {
- // OLED_WR_Byte(F6x8[c][i], OLED_DATA);
- }
- OLED_Set_Pos(x, y + 1);
- for(i = 0; i < 6; i ++)
- {
- //OLED_WR_Byte(F6x8[c][i + 6], OLED_DATA);
- }
- }
- else
- {
- OLED_Set_Pos(x, y + 1);
- for(i = 0; i < 6; i ++)
- {
- // OLED_WR_Byte(F6x8[c][i],OLED_DATA);
- }
- }
- }
- u32 oled_pow(uint8_t m,uint8_t n)
- {
- u32 result = 1;
- while(n --)
- {
- result *= m;
- }
- return result;
- }
-
- void OLED_ShowNum(uint8_t x, uint8_t y, u32 num, uint8_t len, uint8_t size)
- {
- uint8_t t,temp;
- uint8_t enshow = 0;
- for(t = 0; t < len; t ++)
- {
- temp = (num / oled_pow(10, len - t - 1)) % 10;
- if(enshow == 0 && t < (len - 1))
- {
- if(temp == 0)
- {
- OLED_ShowChar(x + (size / 2) * t, y, ' ');
- continue;
- }else enshow = 1;
- }
- OLED_ShowChar(x + (size / 2) * t, y, temp + '0');
- }
- }
- void OLED_ShowString(uint8_t x, uint8_t y, uint8_t *chr)
- {
- uint8_t j = 0;
- while (chr[j] != '\0')
- {
- OLED_ShowChar(x, y, chr[j]);
- x += 8;
- if(x > 120)
- {
- x = 0;
- y += 2;
- }
- j++;
- }
- }
- void OLED_ShowCHinese(uint8_t x, uint8_t y, uint8_t no)
- {
- uint8_t t, adder = 0;
- OLED_Set_Pos(x, y);
- for(t = 0; t < 16; t ++)
- {
- // OLED_WR_Byte(Hzk[2 * no][t], OLED_DATA);
- adder += 1;
- }
- OLED_Set_Pos(x, y + 1);
- for(t = 0; t < 16; t ++)
- {
- //OLED_WR_Byte(Hzk[2 * no + 1][t], OLED_DATA);
- adder += 1;
- }
- }
- void OLED_DrawBMP(uint8_t x0, uint8_t y0,uint8_t x1, uint8_t y1, uint8_t BMP[])
- {
- uint8_t j = 0;
- uint8_t x, y;
- if(y1 % 8 == 0)
- {
- y = y1 / 8;
- }
- else
- {
- y = y1 / 8 + 1;
- }
- for(y = y0; y < y1; y ++)
- {
- OLED_Set_Pos(x0, y);
- for(x = x0; x < x1; x ++)
- {
- OLED_WR_Byte(BMP[j ++], OLED_DATA);
- }
- }
- }
-
- void OLEDConfiguration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB, ENABLE); //??PC,D,G????
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_15 | GPIO_Pin_14;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_SetBits(GPIOB, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_15 | GPIO_Pin_14);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_SetBits(GPIOA, GPIO_Pin_11 | GPIO_Pin_12);
-
- OLED_RST_Set();
- delay_ms(100);
- OLED_RST_Clr();
- delay_ms(100);
- OLED_RST_Set();
- OLED_WR_Byte(0xAE, OLED_CMD);//--turn off oled panel
- OLED_WR_Byte(0x00, OLED_CMD);//---set low column address
- OLED_WR_Byte(0x10, OLED_CMD);//---set high column address
- OLED_WR_Byte(0x40, OLED_CMD);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
- OLED_WR_Byte(0x81, OLED_CMD);//--set contrast control register
- OLED_WR_Byte(0xCF, OLED_CMD); // Set SEG Output Current Brightness
- OLED_WR_Byte(0xA1, OLED_CMD);//--Set SEG/Column Mapping 0xa0???? 0xa1??
- OLED_WR_Byte(0xC8, OLED_CMD);//Set COM/Row Scan Direction 0xc0???? 0xc8??
- OLED_WR_Byte(0xA6, OLED_CMD);//--set normal display
- OLED_WR_Byte(0xA8, OLED_CMD);//--set multiplex ratio(1 to 64)
- OLED_WR_Byte(0x3f, OLED_CMD);//--1/64 duty
- OLED_WR_Byte(0xD3, OLED_CMD);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
- OLED_WR_Byte(0x00, OLED_CMD);//-not offset
- OLED_WR_Byte(0xd5, OLED_CMD);//--set display clock divide ratio/oscillator frequency
- OLED_WR_Byte(0x80, OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
- OLED_WR_Byte(0xD9, OLED_CMD);//--set pre-charge period
- OLED_WR_Byte(0xF1, OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
- OLED_WR_Byte(0xDA, OLED_CMD);//--set com pins hardware configuration
- OLED_WR_Byte(0x12, OLED_CMD);
- OLED_WR_Byte(0xDB, OLED_CMD);//--set vcomh
- OLED_WR_Byte(0x40, OLED_CMD);//Set VCOM Deselect Level
- OLED_WR_Byte(0x20, OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
- OLED_WR_Byte(0x02, OLED_CMD);//
- OLED_WR_Byte(0x8D, OLED_CMD);//--set Charge Pump enable/disable
- OLED_WR_Byte(0x14, OLED_CMD);//--set(0x10) disable
- OLED_WR_Byte(0xA4, OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
- OLED_WR_Byte(0xA6, OLED_CMD);// Disable Inverse Display On (0xa6/a7)
- OLED_WR_Byte(0xAF, OLED_CMD);//--turn on oled panel
- OLED_WR_Byte(0xAF, OLED_CMD); /*display ON*/
- OLED_Display_Status(Display_Clear);
- OLED_Set_Pos(0, 0);
- }
主函数:
- #include "delay.h"
- #include "sys.h"
- #include "uart.h"
- #include "oled.h"
- int main(void)
- {
- delay_init();
- uart_initwBaudRate(115200); //′®¿ú3õê¼»ˉÎa115200
- OLEDConfiguration();
- OLED_ShowString(0,0,"HELLO EEWORLD");
- while(1) //ÎTÏTÑ-»·
- {
-
- }
- }
初始化时要注意,同STM32不一样,的地方是那个GPIOA,和GPIOB的初始化部分,
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB, ENABLE); //??PC,D,G????
而STM32是AHB2
我重新编译居然亮了,见照片
我又把以前的那块OLED管脚不动地插上,萌萌达,居然也亮了。到现在为止在我手上没有烧坏一块我买的OLED。
对一个单片机人来说这是今天双11最大的礼物。
此内容由EEWORLD论坛网友ddllxxrr原创,如需转载或用于商业用途需征得作者同意并注明出处