Embedded 使用STM32F3初始化SSD1305 OLED
我正在尝试使用STM32F3发现板运行基于OLED控制器的OLED。我已经用一个31针行连接了电路板,第一个针绑定在3V上,最后一个针绑定在PD9上(这是电路板左上方的针行)。代码如下所示:Embedded 使用STM32F3初始化SSD1305 OLED,embedded,stm32ldiscovery,Embedded,Stm32ldiscovery,我正在尝试使用STM32F3发现板运行基于OLED控制器的OLED。我已经用一个31针行连接了电路板,第一个针绑定在3V上,最后一个针绑定在PD9上(这是电路板左上方的针行)。代码如下所示: #include "stm32f30x.h" /*--------- PORT-A ----------------------------*/ #define D1 GPIO_Pin_1 #define D1_PORT GPIOA #define D2 GPIO_Pin_3 #def
#include "stm32f30x.h"
/*--------- PORT-A ----------------------------*/
#define D1 GPIO_Pin_1
#define D1_PORT GPIOA
#define D2 GPIO_Pin_3
#define D2_PORT GPIOA
#define D4 GPIO_Pin_5
#define D4_PORT GPIOA
#define D5 GPIO_Pin_7
#define D5_PORT GPIOA
/*-------- PORT-B ----------------------------*/
#define D7 GPIO_Pin_1
#define D7_PORT GPIOB
#define RD GPIO_Pin_11 //8080 Mode RD Display-Pin:14 PD3
#define RD_PORT GPIOB
#define DISP GPIO_Pin_15
#define DISP_PORT GPIOB
/*-------- PORT-C ----------------------------*/
#define D0 GPIO_Pin_3
#define D0_PORT GPIOC
#define D6 GPIO_Pin_5
#define D6_PORT GPIOC
/*-------- PORT-E ----------------------------*/
#define CS GPIO_Pin_7 //PORT-D Display-Pin:19 PD6
#define CS_PORT GPIOE
#define RES GPIO_Pin_11 //PORT-B Display-Pin:20 PC10
#define RES_PORT GPIOE
#define WR GPIO_Pin_13 //8080 Mode WR Display-Pin:15 PD2
#define WR_PORT GPIOE
#define D_C GPIO_Pin_15 //PORT-C Display-Pin:18 PC12
#define D_C_PORT GPIOE
/*-------- PORT-F ----------------------------*/
#define D3 GPIO_Pin_4
#define D3_PORT GPIOF
#define GPIO_PINS_PORTA_OUT (D1 | D2 | D4 | D5 )
#define GPIO_PINS_PORTB_OUT (D7 | RD| DISP)
#define GPIO_PINS_PORTC_OUT (D0 | D6 )
#define GPIO_PINS_PORTE_OUT (CS| D_C | RES | WR)
#define GPIO_PINS_PORTF_OUT (D3)
#define GPIO_PINS_PORTA_IN (D1 | D2 | D4 | D5 )
#define GPIO_PINS_PORTB_IN (D7)
#define GPIO_PINS_PORTC_IN (D0 | D6 )
#define GPIO_PINS_PORTF_IN (D3)
#define GET_BIT(cmd,bitps) (BitAction)((((uint8_t)cmd&((uint8_t)1)<<bitps))>>bitps)
#define GET_INPUT_BIT(port,pin,pos) ((uint8_t)(GPIO_ReadOutputDataBit(port,pin)<<pos))
#define MOD_GPIO_WRITE(cmd) GPIO_WriteBit(D0_PORT,D0,GET_BIT(cmd,0)); \
GPIO_WriteBit(D1_PORT,D1,GET_BIT(cmd,1)); \
GPIO_WriteBit(D2_PORT,D2,GET_BIT(cmd,2)); \
GPIO_WriteBit(D3_PORT,D3,GET_BIT(cmd,3)); \
GPIO_WriteBit(D4_PORT,D4,GET_BIT(cmd,4)); \
GPIO_WriteBit(D5_PORT,D5,GET_BIT(cmd,5)); \
GPIO_WriteBit(D6_PORT,D6,GET_BIT(cmd,6)); \
GPIO_WriteBit(D7_PORT,D7,GET_BIT(cmd,7)) \
#define MOD_GPIO_READ() GET_INPUT_BIT(D0_PORT,D0,0)| GET_INPUT_BIT(D1_PORT,D1,1) | GET_INPUT_BIT(D2_PORT,D2,2)| \
GET_INPUT_BIT(D3_PORT,D3,3) | GET_INPUT_BIT(D4_PORT,D4,4) | GET_INPUT_BIT(D5_PORT,D5,5) | \
GET_INPUT_BIT(D6_PORT,D6,6) | GET_INPUT_BIT(D7_PORT,D7,7)
//proto
void Delay(uint32_t nTime);
void TimingDelay_Decrement(void);
static __IO uint32_t TimingDelay;
//Init the used Ports
static void Init_Ports_Write( void ) {
//D7-0 outputs
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTA_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTB_OUT;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTC_OUT;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTE_OUT;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTF_OUT;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
static void Init_Ports_Read( void ) {
//D7-0 inputs
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTA_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTB_IN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTC_IN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTF_IN;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
static void Init_Ports( void ) {
//init the System
SystemInit();
//Takt für IO-Port A & C aktivieren
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOF, ENABLE);
if (SysTick_Config(SystemCoreClock / 1000000)) { /* Setup SysTick Timer for 1 µsec interrupts (msec/1000000) */
while (1); /* Capture error */
}
Init_Ports_Write();
GPIO_ResetBits(GPIOA, GPIO_PINS_PORTA_OUT);
GPIO_ResetBits(GPIOB, GPIO_PINS_PORTB_OUT);
GPIO_ResetBits(GPIOC, GPIO_PINS_PORTC_OUT);
GPIO_ResetBits(GPIOE, GPIO_PINS_PORTE_OUT);
GPIO_ResetBits(GPIOF, GPIO_PINS_PORTF_OUT);
//set all neg pins
GPIO_SetBits(RES_PORT, RES);
GPIO_SetBits(CS_PORT, CS);
GPIO_SetBits(WR_PORT, WR);
GPIO_SetBits(RD_PORT, RD);
Delay(500000);
}
static void oled_Command_25664(uint8_t cmd){
//write bit by bit
MOD_GPIO_WRITE(cmd);
GPIO_SetBits(RD_PORT, RD);
GPIO_ResetBits(D_C_PORT, D_C);
GPIO_ResetBits(CS_PORT, CS);
GPIO_ResetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(CS_PORT, CS);
__nop();
}
static void oled_Data_25664(uint8_t data){
MOD_GPIO_WRITE(data);
GPIO_SetBits(RD_PORT, RD);
GPIO_SetBits(D_C_PORT, D_C);
GPIO_ResetBits(CS_PORT, CS);
GPIO_ResetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(CS_PORT, CS);
__nop();
}
static uint8_t oled_Read_Data_25664(){
uint8_t read_data;
//Set the D7-0 as inputs
Init_Ports_Read();
//set WR high
read_data = MOD_GPIO_READ();
GPIO_SetBits(WR_PORT, WR);
GPIO_SetBits(D_C_PORT, D_C);
GPIO_ResetBits(CS_PORT, CS);
GPIO_ResetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(RD_PORT, RD);
GPIO_ResetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
read_data = MOD_GPIO_READ();
//Set the D7-0 as outputs
GPIO_SetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_ResetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
//read
read_data = MOD_GPIO_READ();
GPIO_SetBits(D_C_PORT, D_C);
GPIO_SetBits(CS_PORT, CS);
Init_Ports_Write();
return read_data;
}
void Delay(uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/* Decrements the TimingDelay variable.*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00) TimingDelay--;
}
void SysTick_Handler(void)
{
TimingDelay_Decrement();
}
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f30x.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f30x.c file
*/
Init_Ports();
oled_Command_25664(0xAF);//--turn on oled panel
oled_Command_25664(0xA5);
oled_Read_Data_25664();
while(1)
{
oled_Command_25664(0xA5);
Delay(500000);
oled_Command_25664(0xA4);
Delay(500000);
}
}
#include "stm32f30x.h"
/*--------- PORT-A ----------------------------*/
#define D1 GPIO_Pin_1
#define D1_PORT GPIOA
#define D2 GPIO_Pin_3
#define D2_PORT GPIOA
#define D4 GPIO_Pin_5
#define D4_PORT GPIOA
#define D5 GPIO_Pin_7
#define D5_PORT GPIOA
/*-------- PORT-B ----------------------------*/
#define D7 GPIO_Pin_1
#define D7_PORT GPIOB
#define RD GPIO_Pin_11 //8080 Mode RD Display-Pin:14 PD3
#define RD_PORT GPIOB
#define DISP GPIO_Pin_15
#define DISP_PORT GPIOB
/*-------- PORT-C ----------------------------*/
#define D0 GPIO_Pin_3
#define D0_PORT GPIOC
#define D6 GPIO_Pin_5
#define D6_PORT GPIOC
/*-------- PORT-E ----------------------------*/
#define CS GPIO_Pin_7 //PORT-D Display-Pin:19 PD6
#define CS_PORT GPIOE
#define RES GPIO_Pin_11 //PORT-B Display-Pin:20 PC10
#define RES_PORT GPIOE
#define WR GPIO_Pin_13 //8080 Mode WR Display-Pin:15 PD2
#define WR_PORT GPIOE
#define D_C GPIO_Pin_15 //PORT-C Display-Pin:18 PC12
#define D_C_PORT GPIOE
/*-------- PORT-F ----------------------------*/
#define D3 GPIO_Pin_4
#define D3_PORT GPIOF
#define GPIO_PINS_PORTA_OUT (D1 | D2 | D4 | D5 )
#define GPIO_PINS_PORTB_OUT (D7 | RD )
#define GPIO_PINS_PORTC_OUT (D0 | D6 )
#define GPIO_PINS_PORTE_OUT (CS| D_C | RES | WR)
#define GPIO_PINS_PORTF_OUT (D3)
#define GPIO_PINS_PORTA_IN (D1 | D2 | D4 | D5 )
#define GPIO_PINS_PORTB_IN (D7)
#define GPIO_PINS_PORTC_IN (D0 | D6 )
#define GPIO_PINS_PORTF_IN (D3)
#define GET_BIT(cmd,bitps) (BitAction)((((uint8_t)cmd&((uint8_t)1)<<bitps))>>bitps)
#define GET_INPUT_BIT(port,pin,pos) ((uint8_t)(GPIO_ReadOutputDataBit(port,pin)<<pos))
#define MOD_GPIO_WRITE(cmd) GPIO_WriteBit(D0_PORT,D0,GET_BIT(cmd,0)); \
GPIO_WriteBit(D1_PORT,D1,GET_BIT(cmd,1)); \
GPIO_WriteBit(D2_PORT,D2,GET_BIT(cmd,2)); \
GPIO_WriteBit(D3_PORT,D3,GET_BIT(cmd,3)); \
GPIO_WriteBit(D4_PORT,D4,GET_BIT(cmd,4)); \
GPIO_WriteBit(D5_PORT,D5,GET_BIT(cmd,5)); \
GPIO_WriteBit(D6_PORT,D6,GET_BIT(cmd,6)); \
GPIO_WriteBit(D7_PORT,D7,GET_BIT(cmd,7)) \
#define MOD_GPIO_READ() GET_INPUT_BIT(D0_PORT,D0,0)| GET_INPUT_BIT(D1_PORT,D1,1) | GET_INPUT_BIT(D2_PORT,D2,2)| \
GET_INPUT_BIT(D3_PORT,D3,3) | GET_INPUT_BIT(D4_PORT,D4,4) | GET_INPUT_BIT(D5_PORT,D5,5) | \
GET_INPUT_BIT(D6_PORT,D6,6) | GET_INPUT_BIT(D7_PORT,D7,7)
//proto
void Delay(uint32_t nTime);
void TimingDelay_Decrement(void);
static __IO uint32_t TimingDelay;
//Init the used Ports
static void Init_Ports_Write( void ) {
//D7-0 outputs
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTA_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTB_OUT;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTC_OUT;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTE_OUT;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTF_OUT;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
static void Init_Ports_Read( void ) {
//D7-0 inputs
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTA_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTB_IN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTC_IN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTF_IN;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
static void Init_Ports( void ) {
//init the System
SystemInit();
//Takt für IO-Port A & C aktivieren
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOF, ENABLE);
if (SysTick_Config(SystemCoreClock / 1000000)) { /* Setup SysTick Timer for 1 µsec interrupts (msec/1000000) */
while (1); /* Capture error */
}
Init_Ports_Write();
GPIO_ResetBits(GPIOA, GPIO_PINS_PORTA_OUT);
GPIO_ResetBits(GPIOB, GPIO_PINS_PORTB_OUT);
GPIO_ResetBits(GPIOC, GPIO_PINS_PORTC_OUT);
GPIO_ResetBits(GPIOE, GPIO_PINS_PORTE_OUT);
GPIO_ResetBits(GPIOF, GPIO_PINS_PORTF_OUT);
//set all neg pins
GPIO_SetBits(RES_PORT, RES);
GPIO_SetBits(CS_PORT, CS);
GPIO_SetBits(WR_PORT, WR);
GPIO_SetBits(RD_PORT, RD);
Delay(500000);
}
static void oled_Command_25664(uint8_t cmd){
//write bit by bit
MOD_GPIO_WRITE(cmd);
GPIO_SetBits(RD_PORT, RD);
GPIO_ResetBits(D_C_PORT, D_C);
GPIO_ResetBits(CS_PORT, CS);
GPIO_ResetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(CS_PORT, CS);
__nop();
}
static void oled_Data_25664(uint8_t data){
MOD_GPIO_WRITE(data);
GPIO_SetBits(RD_PORT, RD);
GPIO_SetBits(D_C_PORT, D_C);
GPIO_ResetBits(CS_PORT, CS);
GPIO_ResetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(CS_PORT, CS);
__nop();
}
static uint8_t oled_Read_Data_25664(){
uint8_t read_data;
//Set the D7-0 as inputs
Init_Ports_Read();
//set WR high
read_data = MOD_GPIO_READ();
GPIO_SetBits(WR_PORT, WR);
GPIO_SetBits(D_C_PORT, D_C);
GPIO_ResetBits(CS_PORT, CS);
GPIO_ResetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(RD_PORT, RD);
GPIO_ResetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
read_data = MOD_GPIO_READ();
//Set the D7-0 as outputs
GPIO_SetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_ResetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
//read
read_data = MOD_GPIO_READ();
GPIO_SetBits(D_C_PORT, D_C);
GPIO_SetBits(CS_PORT, CS);
Init_Ports_Write();
return read_data;
}
void Delay(uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/* Decrements the TimingDelay variable.*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00) TimingDelay--;
}
void SysTick_Handler(void)
{
TimingDelay_Decrement();
}
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f30x.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f30x.c file
*/
Init_Ports();
oled_Command_25664(0xAF);//--turn on oled panel
oled_Command_25664(0xA4);
oled_Read_Data_25664();
while(1)
{
oled_Command_25664(0xA5);
Delay(500000);
oled_Command_25664(0xA4);
Delay(500000);
}
}
#包括“stm32f30x.h”
/*---------A港----------------------------*/
#定义D1 GPIO_引脚_1
#定义D1_端口GPIOA
#定义D2 GPIO_引脚_3
#定义D2_端口GPIOA
#定义D4 GPIO_引脚_5
#定义D4_端口GPIOA
#定义D5 GPIO_引脚_7
#定义D5_端口GPIOA
/*--------B港----------------------------*/
#定义D7 GPIO_引脚_1
#定义D7_端口GPIOB
#定义RD GPIO_引脚_11//8080模式RD显示引脚:14 PD3
#定义RD_端口GPIOB
#定义显示GPIO引脚15
#定义显示端口GPIOB
/*--------C端口----------------------------*/
#定义D0 GPIO_引脚_3
#定义D0_端口GPIOC
#定义D6 GPIO_引脚_5
#定义D6_端口GPIOC
/*--------东港----------------------------*/
#定义CS GPIO_引脚7//端口D显示引脚:19 PD6
#定义CS_端口GPIOE
#定义RES GPIO_引脚11//PORT-B显示引脚:20 PC10
#定义RES_端口GPIOE
#定义WR GPIO_引脚_13//8080模式WR显示引脚:15 PD2
#定义WR_端口GPIOE
#定义D_C GPIO_引脚_15//端口C显示引脚:18 PC12
#定义D_C_端口GPIOE
/*--------F端口----------------------------*/
#定义D3 GPIO_引脚_4
#定义D3_端口GPIOF
#定义GPIO引脚端口输出(D1 | D2 | D4 | D5)
#定义GPIO引脚端口输出(D7 | RD | DISP)
#定义GPIO引脚端口C输出(D0 | D6)
#定义GPIO引脚端口输出(CS | D | U C | RES | WR)
#定义GPIO引脚端口输出(D3)
#在(D1 | D2 | D4 | D5)中定义GPIO | U引脚| U端口|U
#在(D7)中定义GPIO_引脚_端口B_
#在(D0 | D6)中定义GPIO_引脚_端口C_
#在(D3)中定义GPIO引脚端口
#定义GET_位(cmd,bitps)(BitAction)(((uint8_t)cmd和((uint8_t)1)bitps)
#定义GET_输入位(端口,引脚,pos)((uint8_t)(GPIO_ReadOutputDataBit(端口,引脚)解决方案是DISP信号应保持高Z或端口未初始化。完整代码如下所示:
#include "stm32f30x.h"
/*--------- PORT-A ----------------------------*/
#define D1 GPIO_Pin_1
#define D1_PORT GPIOA
#define D2 GPIO_Pin_3
#define D2_PORT GPIOA
#define D4 GPIO_Pin_5
#define D4_PORT GPIOA
#define D5 GPIO_Pin_7
#define D5_PORT GPIOA
/*-------- PORT-B ----------------------------*/
#define D7 GPIO_Pin_1
#define D7_PORT GPIOB
#define RD GPIO_Pin_11 //8080 Mode RD Display-Pin:14 PD3
#define RD_PORT GPIOB
#define DISP GPIO_Pin_15
#define DISP_PORT GPIOB
/*-------- PORT-C ----------------------------*/
#define D0 GPIO_Pin_3
#define D0_PORT GPIOC
#define D6 GPIO_Pin_5
#define D6_PORT GPIOC
/*-------- PORT-E ----------------------------*/
#define CS GPIO_Pin_7 //PORT-D Display-Pin:19 PD6
#define CS_PORT GPIOE
#define RES GPIO_Pin_11 //PORT-B Display-Pin:20 PC10
#define RES_PORT GPIOE
#define WR GPIO_Pin_13 //8080 Mode WR Display-Pin:15 PD2
#define WR_PORT GPIOE
#define D_C GPIO_Pin_15 //PORT-C Display-Pin:18 PC12
#define D_C_PORT GPIOE
/*-------- PORT-F ----------------------------*/
#define D3 GPIO_Pin_4
#define D3_PORT GPIOF
#define GPIO_PINS_PORTA_OUT (D1 | D2 | D4 | D5 )
#define GPIO_PINS_PORTB_OUT (D7 | RD| DISP)
#define GPIO_PINS_PORTC_OUT (D0 | D6 )
#define GPIO_PINS_PORTE_OUT (CS| D_C | RES | WR)
#define GPIO_PINS_PORTF_OUT (D3)
#define GPIO_PINS_PORTA_IN (D1 | D2 | D4 | D5 )
#define GPIO_PINS_PORTB_IN (D7)
#define GPIO_PINS_PORTC_IN (D0 | D6 )
#define GPIO_PINS_PORTF_IN (D3)
#define GET_BIT(cmd,bitps) (BitAction)((((uint8_t)cmd&((uint8_t)1)<<bitps))>>bitps)
#define GET_INPUT_BIT(port,pin,pos) ((uint8_t)(GPIO_ReadOutputDataBit(port,pin)<<pos))
#define MOD_GPIO_WRITE(cmd) GPIO_WriteBit(D0_PORT,D0,GET_BIT(cmd,0)); \
GPIO_WriteBit(D1_PORT,D1,GET_BIT(cmd,1)); \
GPIO_WriteBit(D2_PORT,D2,GET_BIT(cmd,2)); \
GPIO_WriteBit(D3_PORT,D3,GET_BIT(cmd,3)); \
GPIO_WriteBit(D4_PORT,D4,GET_BIT(cmd,4)); \
GPIO_WriteBit(D5_PORT,D5,GET_BIT(cmd,5)); \
GPIO_WriteBit(D6_PORT,D6,GET_BIT(cmd,6)); \
GPIO_WriteBit(D7_PORT,D7,GET_BIT(cmd,7)) \
#define MOD_GPIO_READ() GET_INPUT_BIT(D0_PORT,D0,0)| GET_INPUT_BIT(D1_PORT,D1,1) | GET_INPUT_BIT(D2_PORT,D2,2)| \
GET_INPUT_BIT(D3_PORT,D3,3) | GET_INPUT_BIT(D4_PORT,D4,4) | GET_INPUT_BIT(D5_PORT,D5,5) | \
GET_INPUT_BIT(D6_PORT,D6,6) | GET_INPUT_BIT(D7_PORT,D7,7)
//proto
void Delay(uint32_t nTime);
void TimingDelay_Decrement(void);
static __IO uint32_t TimingDelay;
//Init the used Ports
static void Init_Ports_Write( void ) {
//D7-0 outputs
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTA_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTB_OUT;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTC_OUT;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTE_OUT;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTF_OUT;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
static void Init_Ports_Read( void ) {
//D7-0 inputs
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTA_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTB_IN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTC_IN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTF_IN;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
static void Init_Ports( void ) {
//init the System
SystemInit();
//Takt für IO-Port A & C aktivieren
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOF, ENABLE);
if (SysTick_Config(SystemCoreClock / 1000000)) { /* Setup SysTick Timer for 1 µsec interrupts (msec/1000000) */
while (1); /* Capture error */
}
Init_Ports_Write();
GPIO_ResetBits(GPIOA, GPIO_PINS_PORTA_OUT);
GPIO_ResetBits(GPIOB, GPIO_PINS_PORTB_OUT);
GPIO_ResetBits(GPIOC, GPIO_PINS_PORTC_OUT);
GPIO_ResetBits(GPIOE, GPIO_PINS_PORTE_OUT);
GPIO_ResetBits(GPIOF, GPIO_PINS_PORTF_OUT);
//set all neg pins
GPIO_SetBits(RES_PORT, RES);
GPIO_SetBits(CS_PORT, CS);
GPIO_SetBits(WR_PORT, WR);
GPIO_SetBits(RD_PORT, RD);
Delay(500000);
}
static void oled_Command_25664(uint8_t cmd){
//write bit by bit
MOD_GPIO_WRITE(cmd);
GPIO_SetBits(RD_PORT, RD);
GPIO_ResetBits(D_C_PORT, D_C);
GPIO_ResetBits(CS_PORT, CS);
GPIO_ResetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(CS_PORT, CS);
__nop();
}
static void oled_Data_25664(uint8_t data){
MOD_GPIO_WRITE(data);
GPIO_SetBits(RD_PORT, RD);
GPIO_SetBits(D_C_PORT, D_C);
GPIO_ResetBits(CS_PORT, CS);
GPIO_ResetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(CS_PORT, CS);
__nop();
}
static uint8_t oled_Read_Data_25664(){
uint8_t read_data;
//Set the D7-0 as inputs
Init_Ports_Read();
//set WR high
read_data = MOD_GPIO_READ();
GPIO_SetBits(WR_PORT, WR);
GPIO_SetBits(D_C_PORT, D_C);
GPIO_ResetBits(CS_PORT, CS);
GPIO_ResetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(RD_PORT, RD);
GPIO_ResetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
read_data = MOD_GPIO_READ();
//Set the D7-0 as outputs
GPIO_SetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_ResetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
//read
read_data = MOD_GPIO_READ();
GPIO_SetBits(D_C_PORT, D_C);
GPIO_SetBits(CS_PORT, CS);
Init_Ports_Write();
return read_data;
}
void Delay(uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/* Decrements the TimingDelay variable.*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00) TimingDelay--;
}
void SysTick_Handler(void)
{
TimingDelay_Decrement();
}
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f30x.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f30x.c file
*/
Init_Ports();
oled_Command_25664(0xAF);//--turn on oled panel
oled_Command_25664(0xA5);
oled_Read_Data_25664();
while(1)
{
oled_Command_25664(0xA5);
Delay(500000);
oled_Command_25664(0xA4);
Delay(500000);
}
}
#include "stm32f30x.h"
/*--------- PORT-A ----------------------------*/
#define D1 GPIO_Pin_1
#define D1_PORT GPIOA
#define D2 GPIO_Pin_3
#define D2_PORT GPIOA
#define D4 GPIO_Pin_5
#define D4_PORT GPIOA
#define D5 GPIO_Pin_7
#define D5_PORT GPIOA
/*-------- PORT-B ----------------------------*/
#define D7 GPIO_Pin_1
#define D7_PORT GPIOB
#define RD GPIO_Pin_11 //8080 Mode RD Display-Pin:14 PD3
#define RD_PORT GPIOB
#define DISP GPIO_Pin_15
#define DISP_PORT GPIOB
/*-------- PORT-C ----------------------------*/
#define D0 GPIO_Pin_3
#define D0_PORT GPIOC
#define D6 GPIO_Pin_5
#define D6_PORT GPIOC
/*-------- PORT-E ----------------------------*/
#define CS GPIO_Pin_7 //PORT-D Display-Pin:19 PD6
#define CS_PORT GPIOE
#define RES GPIO_Pin_11 //PORT-B Display-Pin:20 PC10
#define RES_PORT GPIOE
#define WR GPIO_Pin_13 //8080 Mode WR Display-Pin:15 PD2
#define WR_PORT GPIOE
#define D_C GPIO_Pin_15 //PORT-C Display-Pin:18 PC12
#define D_C_PORT GPIOE
/*-------- PORT-F ----------------------------*/
#define D3 GPIO_Pin_4
#define D3_PORT GPIOF
#define GPIO_PINS_PORTA_OUT (D1 | D2 | D4 | D5 )
#define GPIO_PINS_PORTB_OUT (D7 | RD )
#define GPIO_PINS_PORTC_OUT (D0 | D6 )
#define GPIO_PINS_PORTE_OUT (CS| D_C | RES | WR)
#define GPIO_PINS_PORTF_OUT (D3)
#define GPIO_PINS_PORTA_IN (D1 | D2 | D4 | D5 )
#define GPIO_PINS_PORTB_IN (D7)
#define GPIO_PINS_PORTC_IN (D0 | D6 )
#define GPIO_PINS_PORTF_IN (D3)
#define GET_BIT(cmd,bitps) (BitAction)((((uint8_t)cmd&((uint8_t)1)<<bitps))>>bitps)
#define GET_INPUT_BIT(port,pin,pos) ((uint8_t)(GPIO_ReadOutputDataBit(port,pin)<<pos))
#define MOD_GPIO_WRITE(cmd) GPIO_WriteBit(D0_PORT,D0,GET_BIT(cmd,0)); \
GPIO_WriteBit(D1_PORT,D1,GET_BIT(cmd,1)); \
GPIO_WriteBit(D2_PORT,D2,GET_BIT(cmd,2)); \
GPIO_WriteBit(D3_PORT,D3,GET_BIT(cmd,3)); \
GPIO_WriteBit(D4_PORT,D4,GET_BIT(cmd,4)); \
GPIO_WriteBit(D5_PORT,D5,GET_BIT(cmd,5)); \
GPIO_WriteBit(D6_PORT,D6,GET_BIT(cmd,6)); \
GPIO_WriteBit(D7_PORT,D7,GET_BIT(cmd,7)) \
#define MOD_GPIO_READ() GET_INPUT_BIT(D0_PORT,D0,0)| GET_INPUT_BIT(D1_PORT,D1,1) | GET_INPUT_BIT(D2_PORT,D2,2)| \
GET_INPUT_BIT(D3_PORT,D3,3) | GET_INPUT_BIT(D4_PORT,D4,4) | GET_INPUT_BIT(D5_PORT,D5,5) | \
GET_INPUT_BIT(D6_PORT,D6,6) | GET_INPUT_BIT(D7_PORT,D7,7)
//proto
void Delay(uint32_t nTime);
void TimingDelay_Decrement(void);
static __IO uint32_t TimingDelay;
//Init the used Ports
static void Init_Ports_Write( void ) {
//D7-0 outputs
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTA_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTB_OUT;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTC_OUT;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTE_OUT;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTF_OUT;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
static void Init_Ports_Read( void ) {
//D7-0 inputs
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTA_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTB_IN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTC_IN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PINS_PORTF_IN;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
static void Init_Ports( void ) {
//init the System
SystemInit();
//Takt für IO-Port A & C aktivieren
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOF, ENABLE);
if (SysTick_Config(SystemCoreClock / 1000000)) { /* Setup SysTick Timer for 1 µsec interrupts (msec/1000000) */
while (1); /* Capture error */
}
Init_Ports_Write();
GPIO_ResetBits(GPIOA, GPIO_PINS_PORTA_OUT);
GPIO_ResetBits(GPIOB, GPIO_PINS_PORTB_OUT);
GPIO_ResetBits(GPIOC, GPIO_PINS_PORTC_OUT);
GPIO_ResetBits(GPIOE, GPIO_PINS_PORTE_OUT);
GPIO_ResetBits(GPIOF, GPIO_PINS_PORTF_OUT);
//set all neg pins
GPIO_SetBits(RES_PORT, RES);
GPIO_SetBits(CS_PORT, CS);
GPIO_SetBits(WR_PORT, WR);
GPIO_SetBits(RD_PORT, RD);
Delay(500000);
}
static void oled_Command_25664(uint8_t cmd){
//write bit by bit
MOD_GPIO_WRITE(cmd);
GPIO_SetBits(RD_PORT, RD);
GPIO_ResetBits(D_C_PORT, D_C);
GPIO_ResetBits(CS_PORT, CS);
GPIO_ResetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(CS_PORT, CS);
__nop();
}
static void oled_Data_25664(uint8_t data){
MOD_GPIO_WRITE(data);
GPIO_SetBits(RD_PORT, RD);
GPIO_SetBits(D_C_PORT, D_C);
GPIO_ResetBits(CS_PORT, CS);
GPIO_ResetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(WR_PORT, WR);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(CS_PORT, CS);
__nop();
}
static uint8_t oled_Read_Data_25664(){
uint8_t read_data;
//Set the D7-0 as inputs
Init_Ports_Read();
//set WR high
read_data = MOD_GPIO_READ();
GPIO_SetBits(WR_PORT, WR);
GPIO_SetBits(D_C_PORT, D_C);
GPIO_ResetBits(CS_PORT, CS);
GPIO_ResetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_SetBits(RD_PORT, RD);
GPIO_ResetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
read_data = MOD_GPIO_READ();
//Set the D7-0 as outputs
GPIO_SetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
GPIO_ResetBits(RD_PORT, RD);
__nop();__nop();__nop();__nop();__nop();__nop();
//read
read_data = MOD_GPIO_READ();
GPIO_SetBits(D_C_PORT, D_C);
GPIO_SetBits(CS_PORT, CS);
Init_Ports_Write();
return read_data;
}
void Delay(uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/* Decrements the TimingDelay variable.*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00) TimingDelay--;
}
void SysTick_Handler(void)
{
TimingDelay_Decrement();
}
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f30x.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f30x.c file
*/
Init_Ports();
oled_Command_25664(0xAF);//--turn on oled panel
oled_Command_25664(0xA4);
oled_Read_Data_25664();
while(1)
{
oled_Command_25664(0xA5);
Delay(500000);
oled_Command_25664(0xA4);
Delay(500000);
}
}
#包括“stm32f30x.h”
/*---------A港----------------------------*/
#定义D1 GPIO_引脚_1
#定义D1_端口GPIOA
#定义D2 GPIO_引脚_3
#定义D2_端口GPIOA
#定义D4 GPIO_引脚_5
#定义D4_端口GPIOA
#定义D5 GPIO_引脚_7
#定义D5_端口GPIOA
/*--------B港----------------------------*/
#定义D7 GPIO_引脚_1
#定义D7_端口GPIOB
#定义RD GPIO_引脚_11//8080模式RD显示引脚:14 PD3
#定义RD_端口GPIOB
#定义显示GPIO引脚15
#定义显示端口GPIOB
/*--------C端口----------------------------*/
#定义D0 GPIO_引脚_3
#定义D0_端口GPIOC
#定义D6 GPIO_引脚_5
#定义D6_端口GPIOC
/*--------东港----------------------------*/
#定义CS GPIO_引脚7//端口D显示引脚:19 PD6
#定义CS_端口GPIOE
#定义RES GPIO_引脚11//PORT-B显示引脚:20 PC10
#定义RES_端口GPIOE
#定义WR GPIO_引脚_13//8080模式WR显示引脚:15 PD2
#定义WR_端口GPIOE
#定义D_C GPIO_引脚_15//端口C显示引脚:18 PC12
#定义D_C_端口GPIOE
/*--------F端口----------------------------*/
#定义D3 GPIO_引脚_4
#定义D3_端口GPIOF
#定义GPIO引脚端口输出(D1 | D2 | D4 | D5)
#定义GPIO引脚端口输出(D7 | RD)
#定义GPIO引脚端口C输出(D0 | D6)
#定义GPIO引脚端口输出(CS | D | U C | RES | WR)
#定义GPIO引脚端口输出(D3)
#在(D1 | D2 | D4 | D5)中定义GPIO | U引脚| U端口|U
#在(D7)中定义GPIO_引脚_端口B_
#在(D0 | D6)中定义GPIO_引脚_端口C_
#在(D3)中定义GPIO引脚端口
#定义GET_位(cmd,bitps)(BitAction)(((uint8_t)cmd和((uint8_t)1)bitps)
#定义GET_输入位(端口、引脚、pos)((uint8_t)(GPIO_读取输出数据位(端口、引脚)tl;dr:。问题是什么?谢谢!问题现在就在那里。MCVE呢?关注MCVE代表什么?在使用制造商提供的启动代码作为神奇的十六进制数墙之后,我对OLED驱动电路也遇到了完全相同的问题。非常类似于您的情况:显示器会亮起,但不会亮起正常工作。对我来说,问题是制造商提供的启动代码不正确,就这么简单。@Olaf您使用过这个显示器或控制器吗?问题是数据表中没有写任何关于信号显示的内容,我最初的猜测是将其接地。但这并不是在之后用三个!
响应的理由我声称您应该首先验证硬件。如果出现这种情况,您应该在断言它工作之前检查三次。不,我不知道控制器,但我知道非常相似的控制器,但都需要稍微不同的连接和设置。Olaf在向stackoverflow发布内容之前,我总是检查硬件几次。这是非常基本的事情。很抱歉使用这三个!!!-并不想冒犯任何人。但是请试着理解,如果你假设并说你没有做什么事情,人们可能会生气,所以尽管他们已经做了好几次,还是要做。