描述
本文来源电子发烧友社区,作者:黄炼榕, 帖子地址:
https://bbs.elecfans.com/jishu_2021255_1_1.html既然有了gpio,那就先看看基于gpio实现的iic通信吧。别的不多说先弄清楚板子上的oLED引脚号。
OLED |
|
VCC |
|
GND |
|
SCL |
GPIO14 |
SDA |
GPIO13 |
把支持I2C的宏定义打开,该宏定义所在位置为:vendorhisihi3861hi3861buildconfigusr_config.mk找到后修改如下:CONFIG_I2C_SUPPORT=y示例一个写字节函数void OLED_WR_Byte(uint8_t dat,uint8_t cmd){ hi_u8 m_send_data[2] = { 0 }; hi_u32 status; hi_i2c_data hi3861_i2c_data = { 0 }; if(cmd) { m_send_data[0] = 0x40; } else { m_send_data[0] = 0x00; } m_send_data[1] = dat; hi3861_i2c_data.send_buf = m_send_data; hi3861_i2c_data.send_len = 2; status = hi_i2c_write(HI_I2C_IDX_0, 0x78, &hi3861_i2c_data); if (status != HI_ERR_SUCCESS) { printf(" Error: I2C write status = 0x%x! rn", status);return;}}初始化oled还是跟以前一样void OLED_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 frequencyOLED_WR_Byte(0x80,OLED_CMD); //--set divide ratio, Set Clock as 100 Frames/SecOLED_WR_Byte(0xD9,OLED_CMD); //--set pre-charge period OLED_WR_Byte(0xF1,OLED_CMD); //Set Pre-Charge as 15 Clocks & Discharge as 1 ClockOLED_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); //--turn on oled panel OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/ OLED_Clear(); OLED_Set_Pos(0,0); }void OLED_Demo(void){OLED_Init();OLED_Clear();for(i=0;i<8;i++) {OLED_ShowCHinese(i*16,0,i+0);}for(i=0;i<7;i++) {OLED_ShowCHinese(i*16,2,i+8);}for(i=0;i<4;i++) {OLED_ShowCHinese(i*16,4,i+15);}for(i=0;i<4;i++) {OLED_ShowCHinese(i*16,6,i+19);}}SYS_RUN(OLED_Demo);编译烧录即可
打开APP阅读更多精彩内容