本帖最后由 9999jim 于 2022-7-11 12:36 编辑
@安小芯 感谢国民技术及21ic提供的开发板,收到板后,经过几天的摸索,上个OLED屏测试一下。手上的屏幕是IIC接口的,这里仅以软件的方式来实现。本程序使用GPIOB连接显示屏,测试程序占用以下管脚:
#define OLED_SCL GPIO_PIN_7
#define OLED_SDA GPIO_PIN_9
实现高低电位控制语句如下:
#define OLED_SCLK_Clr() GPIOB->PBC = OLED_SCL; SysTick_Delay_Us(2);//CLK
#define OLED_SCLK_Set() GPIOB->PBSC = OLED_SCL;SysTick_Delay_Us(2);
#define OLED_SDIN_Clr() GPIOB->PBC = OLED_SDA;SysTick_Delay_Us(2);//DIN
#define OLED_SDIN_Set() GPIOB->PBSC = OLED_SDA;SysTick_Delay_Us(2);
GPIO初始化及OLED初始化函数如下:
void OLED_Init(void)
{
GPIO_InitType GPIO_InitStructure;
RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOB);
// GPIO_Structure_Initialize(&GPIO_InitStructure);
// RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
GPIO_InitStructure.Pin = GPIO_PIN_7|GPIO_PIN_9;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUT_PP;
GPIO_InitStructure.GPIO_Slew_Rate = GPIO_SLEW_RATE_FAST;
// GPIO_InitStructure.GPIO_Current = GPIO_DS_4MA;
GPIO_Peripheral_Initialize(GPIOB, &GPIO_InitStructure);
OLED_SCLK_Set();
OLED_SDIN_Set();
SysTick_Delay_Ms(800);
OLED_WR_Byte(0xAE,OLED_CMD);
OLED_WR_Byte(0x02,OLED_CMD);
OLED_WR_Byte(0x10,OLED_CMD);
OLED_WR_Byte(0x40,OLED_CMD);
OLED_WR_Byte(0x81,OLED_CMD);
OLED_WR_Byte(0xff,OLED_CMD);
OLED_WR_Byte(0xA1,OLED_CMD);
OLED_WR_Byte(0xC8,OLED_CMD);
OLED_WR_Byte(0xA6,OLED_CMD);
OLED_WR_Byte(0xA8,OLED_CMD);
OLED_WR_Byte(0x3f,OLED_CMD);
OLED_WR_Byte(0xD3,OLED_CMD);
OLED_WR_Byte(0x00,OLED_CMD);
OLED_WR_Byte(0xd5,OLED_CMD);
OLED_WR_Byte(0x80,OLED_CMD);
OLED_WR_Byte(0xD9,OLED_CMD);
OLED_WR_Byte(0xF1,OLED_CMD);
OLED_WR_Byte(0xDA,OLED_CMD);
OLED_WR_Byte(0x12,OLED_CMD);
OLED_WR_Byte(0xDB,OLED_CMD);
OLED_WR_Byte(0x40,OLED_CMD);
OLED_WR_Byte(0x20,OLED_CMD);
OLED_WR_Byte(0x02,OLED_CMD);
OLED_WR_Byte(0x8D,OLED_CMD);
OLED_WR_Byte(0x14,OLED_CMD);
OLED_WR_Byte(0xA4,OLED_CMD);
OLED_WR_Byte(0xA6,OLED_CMD);
OLED_WR_Byte(0xAF,OLED_CMD);
OLED_WR_Byte(0xAF,OLED_CMD);
主程序如下:
int main(void)
{
OLED_Init();
OLED_Clear(0);
OLED_ShowString(0,0,"n32g430",16);
OLED_ShowString(0,2,"OLED TEST",16);
OLED_ShowString(0,4,"21.COM",16);
}
实际运行如图:
程序已打包,感谢各位观看~
iic_oled.zip
(1.74 MB)
|