有了前面程序下载和点亮LED灯的基础,我们就可以利用I/O口来尝试驱动OLED屏了,这里选的是I2C接口的OLED屏,只需占用2个I/O口,故十分节省资源,对于像HC32L110这样原本就引脚不多的芯片更是如此。 那么选哪个引脚来连接OLED屏呢? 这里选取的是P35和P36,其中P35--- CLK,P36--- DIN。 配置这2个引脚为输出功能的函数为: void App_OledInit(void)
{
Gpio_InitIOExt(3, 5, GpioDirOut, TRUE, FALSE, TRUE, FALSE);
Gpio_InitIOExt(3, 6, GpioDirOut, TRUE, FALSE, TRUE, FALSE);
}
是这2个引脚输出高低电平的语句为: #define OLED_SCLK_Set() Gpio_SetIO(3, 5, TRUE) #define OLED_SCLK_Clr() Gpio_SetIO(3, 5, FALSE)
#define OLED_SDIN_Set() Gpio_SetIO(3, 6, TRUE) #define OLED_SDIN_Clr() Gpio_SetIO(3, 6, FALSE) 该显示屏的初始化函数为: void OLED_Init(void)
{
OLED_SCLK_Set();
OLED_SDIN_Set();
delay1ms(800);
OLED_WR_Byte(0xAE,OLED_CMD);//--display off
OLED_WR_Byte(0x40,OLED_CMD);//--set start line address
OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
OLED_WR_Byte(0x81,OLED_CMD); // contract control
OLED_WR_Byte(0xFF,OLED_CMD);//--128
OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap
OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse
OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
OLED_WR_Byte(0x1F,OLED_CMD);//--1/32 duty
OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset
OLED_WR_Byte(0x00,OLED_CMD);//
OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
OLED_WR_Byte(0xf0,OLED_CMD);//
OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
OLED_WR_Byte(0x22,OLED_CMD);//
OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
OLED_WR_Byte(0x02,OLED_CMD);//
OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
OLED_WR_Byte(0x49,OLED_CMD);//
OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable
OLED_WR_Byte(0x14,OLED_CMD);//
OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
OLED_Clear();
}
实现图1和图2显示效果的主程序为: int32_t main(void)
{
delay1ms(100);
OLED_Init();
OLED_Clear();
OLED_ShowString(0,0,"HC32L110 TEST",16);
OLED_ShowString(0,2,"OLED DISPLAY",16);
delay1ms(2000);
OLED_Clear();
OLED_ShowCHinese(0, 0, 3);
OLED_ShowCHinese(16, 0, 4);
OLED_ShowCHinese(32, 0, 5);
OLED_ShowCHinese(48, 0, 6);
OLED_ShowCHinese(64, 0, 7);
OLED_ShowCHinese(0, 2, 8);
OLED_ShowCHinese(16, 2, 9);
OLED_ShowCHinese(32, 2, 10);
OLED_ShowCHinese(48, 2, 11);
OLED_ShowCHinese(64, 2, 12);
while (1);
}
图1 显示字符串
图2 显示汉字
|