In this experiment, we created oled.c and oled.h files. These two files are used to store OLED-related driver functions and file declarations.
The code of oled.c is quite long, so we will not post it here. We will only introduce a few important functions. The first is the OLED_Init function. The structure of this function is relatively simple. It starts with the initialization of the IO port. Here we use the macro definition OLED_MODE to determine the IO port to be set. The rest are some initialization sequences. We can do it according to the information provided by the manufacturer. Finally, it should be pointed out that because OLED has no backlight, after initialization, we clear the video memory, so we can't see anything on the screen, just like there is no power. Don't think that this is an initialization failure. The data module will be written to display it. The code of the OLED_Init function is as follows:
// Initialize SSD1306
void OLED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB
|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE
|RCC_AHB1Periph_GPIOG, ENABLE); //Enable PORTA~E, PORTG clock
#if OLED_MODE==1 //Use 8080 parallel port mode
//GPIO initialization settings
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //Normal output mode
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //Push-pull output
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_Init(GPIOA, &GPIO_InitStructure); // Initialization
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7 ;
GPIO_Init(GPIOB, &GPIO_InitStructure); // Initialization
GPIO_InitStructure.GPIO_Pin =
GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_11;
GPIO_Init(GPIOC, &GPIO_InitStructure); // Initialization
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;
GPIO_Init(GPIOD, &GPIO_InitStructure); // Initialization
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_5;
GPIO_Init(GPIOE, &GPIO_InitStructure); // Initialization
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_Init(GPIOG, &GPIO_InitStructure); // Initialization
OLED_WR=1;
OLED_RD=1;
#else //Use 4-wire SPI serial port mode
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //Normal output mode
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //Push-pull output
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_Init(GPIOB, &GPIO_InitStructure); // Initialization
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;
GPIO_Init(GPIOC, &GPIO_InitStructure); // Initialization
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOD, &GPIO_InitStructure); // Initialization
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_Init(GPIOG, &GPIO_InitStructure); // Initialize OLED_SDIN=1;
OLED_SCLK=1;
#endif
Previous article:STM32f4---OLCD display experimental code (02)
Next article:STM32f4---capacitive touch button experimental code (02)
Recommended ReadingLatest update time:2024-11-17 00:57
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EEWORLD University Hall----Analog Integrated Circuit Design (Li Zhangquan, Shanghai Jiaotong University)
- Request a free ZVS buck-boost evaluation board!
- USB TYPE C interface problem urgent help
- Notice on the extension of ON Semiconductor and Avnet IoT Innovation Design Competition
- Can't find header file when compiling
- RTC timekeeping function + GPIO control LCD12864 display
- On-chip memory resources of RSL10
- UART Protocol Timing Summary
- NXP Smart Car Northeast Competition First Prize, we will open source after the competition
- Non-inverting proportional amplifier feedback resistor setting