`
今天我们来点亮一下板载oled。
首先开启I2C的功能。
修改文件:vendorhisihi3861hi3861uildconfigusr_config.mk
然后配置IO复用
修改文件:vendorhisihi3861hi3861appwifiiot_appinitapp_io_init.c
- /* I2C MUX: */
- #ifdef CONFIG_I2C_SUPPORT
- /* I2C IO复用也可以选择3/4; 9/10,根据产品设计选择 */
- hi_io_set_func(HI_IO_NAME_GPIO_13, HI_IO_FUNC_GPIO_13_I2C0_SDA);
- hi_io_set_func(HI_IO_NAME_GPIO_14, HI_IO_FUNC_GPIO_14_I2C0_SCL);
- #endif
复制代码
i2c写函数
- hi_u32 my_i2c_write(hi_i2c_idx id, hi_u16 device_addr, hi_u32 send_len)
- {
- hi_u32 status;
- hi_i2c_data es8311_i2c_data = { 0 };
- es8311_i2c_data.send_buf = g_send_data;
- es8311_i2c_data.send_len = send_len;
- status = hi_i2c_write(id, device_addr, &es8311_i2c_data);
- if (status != HI_ERR_SUCCESS) {
- printf("===== Error: I2C write status = 0x%x! =====
- ", status);
- return status;
- }
- return HI_ERR_SUCCESS;
- }
复制代码
oled初始化函数
- void led_init(void)
- {
- OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
- 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 Set Mapping RAM Display Start Line (0x00~0x3F)
- OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
- OLED_WR_Byte(0xCF,OLED_CMD);// Set SEG Output Current Brightness
- OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping 0xa0左右反置 0xa1正常
- OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction 0xc0上下反置 0xc8正常
- OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
- OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
- OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
- OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
- OLED_WR_Byte(0x00,OLED_CMD);//-not offset
- OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
- OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
- OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
- OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
- OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
- OLED_WR_Byte(0x12,OLED_CMD);
- OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
- OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
- OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
- OLED_WR_Byte(0x02,OLED_CMD);//
- OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
- OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
- OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
- OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7)
- OLED_WR_Byte(0xAF,OLED_CMD);
- OLED_Clear();
- }
复制代码
任务函数
- void my_oled_demo(void)
- {
- //初始化
- hi_i2c_init(HI_I2C_IDX_0, 100000); /* baudrate: 100000 */
- led_init();
- OLED_ShowString(0,16,"hello HarmonyOS",16);
- OLED_Refresh();
- }
复制代码
最后附上效果图
`