STM32 的OLED的使用

您所在的位置:网站首页 tft屏幕模块的CS接口什么功能 STM32 的OLED的使用

STM32 的OLED的使用

2024-07-04 12:55| 来源: 网络整理| 查看: 265

7脚OLED依次有引脚:GND、VCC、D0、D1、RES、DC、CS七个脚 模块接口定义: 1. GND 电源地 2. VCC 电源正(3~5.5V) 3. D0 OLED 的 D0 脚,在 SPI 和 IIC 通信中为时钟管脚 4. D1 OLED 的 D1 脚,在 SPI 和 IIC 通信中为数据管脚 5. RES OLED 的 RES#脚,用来复位(低电平复位) 6. DC OLED 的 D/C#E 脚,数据和命令控制管脚 7. CS OLED 的 CS#脚,也就是片选管脚

D0,D1,RES,DC都不需要接在有SPI功能的管脚,直接接编程芯片任意管脚(只要你不需要用这些被接的管脚及其上面有限个数的功能),配置I/O功能就可以了,OLED端口宏定义如下(D0、D1、RES、DC分别接PB12、PB13、PB14、PB15):

#define OLED_SCLK_Clr() GPIO_ResetBits(GPIOB,GPIO_Pin_12)//CLK #define OLED_SCLK_Set() GPIO_SetBits(GPIOB,GPIO_Pin_12) #define OLED_SDIN_Clr() GPIO_ResetBits(GPIOB,GPIO_Pin_13)//DIN #define OLED_SDIN_Set() GPIO_SetBits(GPIOB,GPIO_Pin_13) #define OLED_RST_Clr() GPIO_ResetBits(GPIOB,GPIO_Pin_14)//RES #define OLED_RST_Set() GPIO_SetBits(GPIOB,GPIO_Pin_14) #define OLED_DC_Clr() GPIO_ResetBits(GPIOB,GPIO_Pin_15)//DC #define OLED_DC_Set() GPIO_SetBits(GPIOB,GPIO_Pin_15) #define OLED_CS_Clr() GPIO_ResetBits(GPIOB,GPIO_Pin_10)//CS #define OLED_CS_Set() GPIO_SetBits(GPIOB,GPIO_Pin_10)

管脚初始化如下:

//初始化SSD1306(驱动IC) void OLED_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE); //使能PA、PB端口时钟 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//速度50MHz GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIOB, &GPIO_InitStructure); 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_Clear(); OLED_Set_Pos(0,0); }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3