OLED屏显示功能的实现
作者:互联网
RT1052开发板是一款面向中高档应用的产品,因而其配置的显示的显示器件也为触摸屏。这样就使得它留给使用者的扩展端口比较少,要想自行扩展就主要向矩阵键盘接口KEY PAD着手了。
为了给其配置一个必要的显示窗口,本人所选的显示器件是I2C接口的OLED屏,它只需占用2个GPIO口即可使用。为达到图1的显示效果,OLED屏使用的是P24中的引脚1和3,所使用的是GPIO1_IO25和GPIO1_IO27。
<ignore_js_op>
OLED屏显示效果
<ignore_js_op>
为使SCLK和SDIN引脚输出高低电平,其定义引脚如下:
#define OLED_SCLK_Set() GPIO_PinWrite(GPIO1, (25U), 1U);
#define OLED_SCLK_Clr() GPIO_PinWrite(GPIO1, (25U), 0U);
#define OLED_SDIN_Set() GPIO_PinWrite(GPIO1, (27U), 1U);
#define OLED_SDIN_Clr() GPIO_PinWrite(GPIO1, (27U), 0U);
配置GPIO1_IO25和GPIO1_IO27为输出端口的函数为:
OLED屏的初始化函数为:
实现图1所示效果的主程序为:
有了OLED屏这个显示串口,我们在观察运行结果就可以不完全依赖调试串口了。
- void LCD_GPIO_Cogfig(void)
- {
- gpio_pin_config_t led_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};
- GPIO_PinInit(GPIO1, (25U), &led_config);
- GPIO_PinInit(GPIO1, (27U), &led_config);
- }
OLED屏的初始化函数为:
- void OLED_Init(void)
- {
- LCD_GPIO_Cogfig();
- OLED_SCLK_Set();
- OLED_SDIN_Set();
- delay_ms(800);
- OLED_WR_Byte(0xAE,OLED_CMD);//--display off
- 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
- OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
- 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(0x3F,OLED_CMD);//--1/32 duty
- OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
- 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(0x80,OLED_CMD);//
- OLED_WR_Byte(0xD8,OLED_CMD);//set area color mode off
- OLED_WR_Byte(0x05,OLED_CMD);//
- OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
- OLED_WR_Byte(0xF1,OLED_CMD);//
- OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
- OLED_WR_Byte(0x12,OLED_CMD);//
- OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
- OLED_WR_Byte(0x30,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
- }
实现图1所示效果的主程序为:
- int main(void)
- {
- uint16_t i=0;
- gpio_pin_config_t led_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};
- BOARD_ConfigMPU();
- BOARD_InitPins();
- BOARD_BootClockRUN();
- BOARD_InitDebugConsole();
- /* Print a note to terminal. */
- PRINTF("\r\n OLED 屏驱动测试\r\n");
- GPIO_PinInit(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, &led_config);
- OLED_Init();
- OLED_Clear();
- OLED_ShowString(0,2,"OK1052-C",12);
- OLED_ShowString(0,4,"0.96' OLED TEST",12);
- OLED_ShowString(0,6,"JLXX 2018/10/6",12);
- while(1)
- {
- delay();
- if (g_pinSet)
- {
- GPIO_PinWrite(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, 0U);
- g_pinSet = false;
- }
- else
- {
- GPIO_PinWrite(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, 1U);
- g_pinSet = true;
- }
- }
- }
有了OLED屏这个显示串口,我们在观察运行结果就可以不完全依赖调试串口了。
标签:功能,set,实现,CMD,OLED,WR,GPIO,Byte 来源: https://www.cnblogs.com/zhugeanran/p/16379958.html