发帖
11 2 0

Ai-M61-32S i2c点亮oled详细教程及踩坑记录

干簧管
论坛元老

19

主题

1241

回帖

7919

积分

论坛元老

积分
7919
Ai-M61-Kit外设移植教程 2653 11 2023-12-10 17:32:31
本帖最后由 干簧管 于 2023-12-24 19:53 编辑
一、首先了解SDK中的i2c
https://bbs.ai-thinker.com/forum ... 1895&extra=page%3D1 泽哥这篇文章写的也很详细,首先参考这个对SDK中的i2c有个初步的认识
二、硬件连接
这里参考泽哥的代码,使用IO0和IO1作为i2c功能使用,后来发现按照其注释连接有问题,sda和scl注释反了

5.PNG

如下,IO0是SCl,IO1是SDA
6.PNG
此oled模组引脚较为简单,只有4p,从左到右依次是GND,VDD,SCK,SDA,于是按照如下连接
oled         Ai-M61-32S
GND <---> GND
VDD <---> 3V3
SCK  <---> IO0
SDA <---> IO1


三、oled工程创建
1.复制i2c_eeprom目录,并将其命名为i2c_oled
1.PNG
2.添加oled.c和oled.h文件,主要用于写oled初始化,清屏,刷图等函数供main函数调用,h文件中则用来声明这些函数以及定义一些宏,如:从机地址等
2.PNG

3.CMakeLists.txt 中的 project 名称换成 i2c_oled,并且添加 target_sources(app PRIVATE oled.c)
3.PNG
四、oled初始化代码编写
从淘宝商家拿到的init code如下,需要设置
  1. static unsigned char OLED_init_cmd[25]=
  2. {
  3.   /*0xae,0X00,0X10,0x40,0X81,0XCF,0xff,0xa1,0xa4,
  4.   0xA6,0xc8,0xa8,0x3F,0xd5,0x80,0xd3,0x00,0XDA,0X12,
  5.   0x8d,0x14,0xdb,0x40,0X20,0X02,0xd9,0xf1,0xAF*/
  6.        0xAE,//关闭显示
  7.        0xD5,//设置时钟分频因子,震荡频率
  8.        0x80,  //[3:0],分频因子;[7:4],震荡频率

  9.        0xA8,//设置驱动路数
  10.        0X3F,//默认0X3F(1/64)
  11.        0xD3,//设置显示偏移
  12.        0X00,//默认为0
  13.        0x40,//设置显示开始行 [5:0],行数.                              
  14.        0x8D,//电荷泵设置
  15.        0x14,//bit2,开启/关闭
  16.        0x20,//设置内存地址模式
  17.        0x02,//[1:0],00,列地址模式;01,行地址模式;10,页地址模式;默认10;
  18.        0xA1,//段重定义设置,bit0:0,0->0;1,0->127;
  19.        0xC8,//设置COM扫描方向;bit3:0,普通模式;1,重定义模式 COM[N-1]->COM0;N:驱动路数
  20.        0xDA,//设置COM硬件引脚配置
  21.        0x12,//[5:4]配置            
  22.        0x81,//对比度设置
  23.        0xEF,//1~255;默认0X7F (亮度设置,越大越亮)
  24.        0xD9,//设置预充电周期
  25.        0xf1,//[3:0],PHASE 1;[7:4],PHASE 2;
  26.        0xDB,//设置VCOMH 电压倍率
  27.        0x30,//[6:4] 000,0.65*vcc;001,0.77*vcc;011,0.83*vcc;
  28.        0xA4,//全局显示开启;bit0:1,开启;0,关闭;(白屏/黑屏)
  29.        0xA6,//设置显示方式;bit0:1,反相显示;0,正常显示        
  30.        0xAF,//开启显示     
  31. };
复制代码
然后需要根据SDK中的发送api将这些code发送到屏端,然后先找个例程参考下发送时序
  1. uint8_t I2C_TxData_Polling(uint8_t Address, uint8_t *Buffer, uint8_t Length)
  2. {
  3.     uint16_t i = 0;

  4.     sI2C_GenerateStart();

  5.     sI2C_WriteByte(OLED_I2C_ADDRESS);

  6.     if (sI2C_GetACK())
  7.     {
  8.         sI2C_GenerateStop();
  9.         return (1);
  10.     }

  11.     sI2C_WriteByte(Address);

  12.     if (sI2C_GetACK())
  13.     {
  14.         sI2C_GenerateStop();
  15.         return (1);
  16.     }

  17.     for (i = 0; i < Length; i++)
  18.     {
  19.         sI2C_WriteByte(*Buffer++);

  20.         if (sI2C_GetACK())
  21.         {
  22.             break;
  23.         }
  24.     }

  25.     sI2C_GenerateStop();

  26.     if (i == Length)
  27.     {
  28.         return (0);
  29.     }
  30.     else
  31.     {
  32.         return (1);
  33.     }
  34. }
复制代码
如上是从网上找的单片机上驱动oled屏幕的i2c发送时序:start->写从机地址->等从机ack->发寄存器地址->发数据->等从机ack ..... ->发数据->等从机ack->stop,于是根据泽哥的讲解以及SDK中的demo,尝试编写以下函数
  1. static void oled_write(unsigned char reg_addr,unsigned char *buff, char buf_size)
  2. {
  3.     struct bflb_i2c_msg_s msgs[2];
  4.   
  5.     msgs[0].addr = OLED_I2C_ADDRESS;
  6.     msgs[0].flags = I2C_M_NOSTOP;
  7.     msgs[0].buffer = &reg_addr;
  8.     msgs[0].length = 1;
  9.    
  10.     msgs[1].addr = OLED_I2C_ADDRESS;
  11.     msgs[1].flags = 0;
  12.     msgs[1].buffer = buff;
  13.     msgs[1].length = buf_size;

  14.     bflb_i2c_transfer(i2c0, msgs, 2);
  15.     //bflb_mtimer_delay_ms(100); //此处影响刷屏速度,先直接去掉后面查看是否存在其他问题
  16. }


  17. void OLED_Init(void)
  18. {
  19.     oled_write(OLED_CMD,OLED_init_cmd, sizeof(OLED_init_cmd) /sizeof(unsigned char));
  20.     printf("OLED_Init over\r\n");
  21. }
复制代码
上述中的 OLED_I2C_ADDRESS ,从其他例程中看到是 0x78,于是我在此也填的这个,后面因为这事浪费了很久,此处应该是 0x3c,左移一位然后最低位为读写控制位

五、取模软件取模

参照这个博客进行取模操作,博主讲解得十分详细 https://blog.csdn.net/qq_39400113/article/details/108036400

4.PNG
六、取模显示效果图
8cf4b9e3c7445e09fd6410bfbaf67b7.jpg

七、实际使用中发现如果i2c通讯失败,官方的SDK并没有报错log,于是在 bflb_i2c_transfer 函数中添加以下打印,来判断i2c通讯失败
由于上面从机地址的问题,导致屏幕一直不亮,添加log流程也都跑完了,也没看出什么问题,幸好手头有一个逻辑分析仪,踩一下波形发现,发送完从机地址后没有回ack,配置的0x78但是波形解析是0xF0,于是改为0x3c再试试就ok了,于是想SDk里面通讯失败咋没有报错的log呢,比如 rx timeout啥的,于是就查看 bflb_i2c_transfer 函数的定义,然后找到了异常时的return,但是此处没有log打印出问题,所以出问题时并没有提示,于是加上以下log,判断下i2c transfer是否存在问题
  1. int bflb_i2c_transfer(struct bflb_device_s *dev, struct bflb_i2c_msg_s *msgs, int count)
  2. {
  3.     uint16_t subaddr = 0;
  4.     uint16_t subaddr_size = 0;
  5.     bool is_addr_10bit = false;
  6.     int ret = 0;

  7.     bflb_i2c_disable(dev);

  8.     for (uint16_t i = 0; i < count; i++) {
  9.         if (msgs[i].flags & I2C_M_TEN) {
  10.             is_addr_10bit = true;
  11.         } else {
  12.             is_addr_10bit = false;
  13.         }
  14.         if (msgs[i].flags & I2C_M_NOSTOP) {
  15.             subaddr = 0;
  16.             for (uint8_t j = 0; j < msgs[i].length; j++) {
  17.                 subaddr += msgs[i].buffer[j] << (j * 8);
  18.             }
  19.             subaddr_size = msgs[i].length;
  20.             bflb_i2c_addr_config(dev, msgs[i].addr, subaddr, subaddr_size, is_addr_10bit);
  21.             i++;
  22.         } else {
  23.             subaddr = 0;
  24.             subaddr_size = 0;
  25.             bflb_i2c_addr_config(dev, msgs[i].addr, subaddr, subaddr_size, is_addr_10bit);
  26.         }

  27.         if (msgs[i].length > 256) {
  28.             return -EINVAL;
  29.         }
  30.         bflb_i2c_set_datalen(dev, msgs[i].length);
  31.         if (msgs[i].flags & I2C_M_READ) {
  32.             bflb_i2c_set_dir(dev, 1);
  33.             if ((msgs[i].flags & I2C_M_DMA) == 0) {
  34.                 ret = bflb_i2c_read_bytes(dev, msgs[i].buffer, msgs[i].length);
  35.                 if (ret < 0) {
  36.                     return ret;
  37.                 }
  38.             } else {
  39.                 bflb_i2c_enable(dev);
  40.             }
  41.         } else {
  42.             bflb_i2c_set_dir(dev, 0);
  43.             if ((msgs[i].flags & I2C_M_DMA) == 0) {
  44.                 ret = bflb_i2c_write_bytes(dev, msgs[i].buffer, msgs[i].length);
  45.                 if (ret < 0) {
  46. ++                  printf("i2c bflb_i2c_transfer error:%d\r\n",ret);
  47.                     return ret;
  48.                 }
  49. ++                //printf("i2c bflb_i2c_transfer Ok\r\n");
  50.             } else {
  51.                 bflb_i2c_enable(dev);
  52.             }
  53.         }
  54.     }

  55.     return 0;
  56. }
复制代码
上传的附件: i2c_oled.zip (4.84 KB, 下载次数: 10)


八、添加ASIIC字符显示
应群友的要求,补上字符显示的部分
  1. //在指定位置显示一个字符,包括部分字符
  2. //x:0~127
  3. //y:0~63
  4. //mode:0,反白显示;1,正常显示                                 
  5. //size:选择字体 16/12
  6. void OLED_ShowChar(unsigned char x,unsigned char y,unsigned char chr,unsigned char Char_Size)
  7. {              
  8.         unsigned char c=0,i=0;        
  9.                 c=chr-' ';//得到偏移后的值                        
  10.                 if(x>Max_Column-1){x=0;y=y+2;}
  11.                 if(Char_Size ==16)
  12.         {
  13.             OLED_Set_Pos(x,y);        
  14.             for(i=0;i<8;i++)
  15.                 oled_write(OLED_DATA,&F8X16[c*16+i],1);
  16.             OLED_Set_Pos(x,y+1);
  17.             for(i=0;i<8;i++)
  18.                 oled_write(OLED_DATA,&F8X16[c*16+i+8],1);
  19.         }
  20.         else {        
  21.             OLED_Set_Pos(x,y);
  22.             for(i=0;i<6;i++)
  23.                 oled_write(OLED_DATA,&F6x8[c][i],1);         
  24.         }
  25. }

  26. //显示一个字符号串
  27. void OLED_ShowString(unsigned char x,unsigned char y,unsigned char *chr,unsigned char Char_Size)
  28. {
  29.         unsigned char j=0;
  30.         while (chr[j]!='\0')
  31.         {                OLED_ShowChar(x,y,chr[j],Char_Size);
  32.                         x+=8;
  33.                 if(x>120){x=0;y+=2;}
  34.                         j++;
  35.         }
  36. }
复制代码
然后加上ASIIC字模
  1. //常用ASCII表
  2. //偏移量32
  3. //ASCII字符集
  4. //偏移量32
  5. //大小:12*6
  6. /************************************6*8的点阵************************************/
  7. const unsigned char F6x8[][6] =               
  8. {
  9. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp
  10. 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// !
  11. 0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// "
  12. 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// #
  13. 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $
  14. 0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// %
  15. 0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// &
  16. 0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// '
  17. 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// (
  18. 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// )
  19. 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// *
  20. 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// +
  21. 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// ,
  22. 0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// -
  23. 0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// .
  24. 0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// /
  25. 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
  26. 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
  27. 0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2
  28. 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
  29. 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
  30. 0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5
  31. 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
  32. 0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7
  33. 0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8
  34. 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
  35. 0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// :
  36. 0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ;
  37. 0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// <
  38. 0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// =
  39. 0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// >
  40. 0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ?
  41. 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @
  42. 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A
  43. 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B
  44. 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C
  45. 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
  46. 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E
  47. 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F
  48. 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G
  49. 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
  50. 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I
  51. 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J
  52. 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K
  53. 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L
  54. 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M
  55. 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
  56. 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
  57. 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P
  58. 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
  59. 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R
  60. 0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S
  61. 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T
  62. 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
  63. 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
  64. 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W
  65. 0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X
  66. 0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y
  67. 0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z
  68. 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [
  69. 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55
  70. 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ]
  71. 0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^
  72. 0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _
  73. 0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// '
  74. 0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a
  75. 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b
  76. 0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c
  77. 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d
  78. 0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e
  79. 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f
  80. 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g
  81. 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h
  82. 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i
  83. 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j
  84. 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k
  85. 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l
  86. 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m
  87. 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n
  88. 0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o
  89. 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p
  90. 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q
  91. 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r
  92. 0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s
  93. 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t
  94. 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
  95. 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
  96. 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
  97. 0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x
  98. 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y
  99. 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z
  100. 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines
  101. };
  102. /****************************************8*16的点阵************************************/
  103. const unsigned char F8X16[]=         
  104. {
  105.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
  106.   0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
  107.   0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
  108.   0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
  109.   0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
  110.   0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
  111.   0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
  112.   0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
  113.   0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
  114.   0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
  115.   0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
  116.   0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
  117.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
  118.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
  119.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
  120.   0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
  121.   0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
  122.   0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
  123.   0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
  124.   0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
  125.   0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
  126.   0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
  127.   0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
  128.   0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
  129.   0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
  130.   0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
  131.   0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
  132.   0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
  133.   0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
  134.   0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
  135.   0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
  136.   0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
  137.   0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
  138.   0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
  139.   0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
  140.   0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
  141.   0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
  142.   0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
  143.   0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
  144.   0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
  145.   0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
  146.   0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
  147.   0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
  148.   0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
  149.   0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
  150.   0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
  151.   0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
  152.   0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
  153.   0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
  154.   0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
  155.   0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
  156.   0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
  157.   0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
  158.   0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
  159.   0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
  160.   0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
  161.   0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
  162.   0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
  163.   0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
  164.   0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
  165.   0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
  166.   0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
  167.   0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
  168.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
  169.   0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
  170.   0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
  171.   0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
  172.   0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
  173.   0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
  174.   0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
  175.   0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
  176.   0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
  177.   0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
  178.   0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
  179.   0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
  180.   0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
  181.   0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
  182.   0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
  183.   0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
  184.   0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
  185.   0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
  186.   0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
  187.   0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
  188.   0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
  189.   0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
  190.   0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
  191.   0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
  192.   0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
  193.   0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
  194.   0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
  195.   0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
  196.   0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
  197.   0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
  198.   0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
  199.   0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
  200. };
复制代码
  1. int main(void)
  2. {
  3.     struct bflb_device_s* gpio;
  4.     board_init();
  5.     //board_i2c0_gpio_init();
  6.    

  7.     gpio = bflb_device_get_by_name("gpio");
  8.     /* I2C0_SCL */
  9.     bflb_gpio_init(gpio, GPIO_PIN_0, GPIO_FUNC_I2C0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
  10.     /* I2C0_SDA */
  11.     bflb_gpio_init(gpio, GPIO_PIN_1, GPIO_FUNC_I2C0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
  12.     i2c0 = bflb_device_get_by_name("i2c0");

  13.     bflb_i2c_init(i2c0, 400000);
  14.     OLED_Init();
  15.     OLED_clr();
  16.     //OLED_show_bmp();
  17.     /*OLED_ShowCHinese(39,0,0);
  18.     OLED_ShowCHinese(55,0,1);
  19.     OLED_ShowCHinese(71,0,2);

  20.     OLED_ShowCHinese(39,2,0);//此处是第2行,因为汉字是16*16
  21.     OLED_ShowCHinese(55,2,1);
  22.     OLED_ShowCHinese(71,2,2);

  23.     OLED_ShowCHinese(39,4,0);
  24.     OLED_ShowCHinese(55,4,1);
  25.     OLED_ShowCHinese(71,4,2);

  26.     OLED_ShowCHinese(39,6,0);
  27.     OLED_ShowCHinese(55,6,1);
  28.     OLED_ShowCHinese(71,6,2);*/
  29.     OLED_ShowString(6,3,"0.96' OLED TEST",16);
  30.     printf("end\r\n");

  31.     while(1){
  32.     }
  33. }
复制代码
显示效果如图
2d2e7022fc9fb05a6788e90cff26422.jpg
修改后的代码打包如下:
上传的附件: i2c_oled_new.zip (27.52 KB, 下载次数: 10)




──── 2人觉得很赞 ────

使用道具 举报

2023-12-10 18:59:26
感谢分享
2023-12-10 22:20:44
2023-12-11 08:49:37
优秀~
2023-12-11 14:29:50
优秀
2023-12-11 19:48:56
感恩
2023-12-12 16:15:36
2024-1-2 08:36:39
2024-1-11 14:54:16
佬 你这个程序清屏一次需要多少ms? 有用逻辑分析仪测量一下时间吗
2024-1-16 09:16:01
is麟儿 发表于 2024-1-11 14:54
佬 你这个程序清屏一次需要多少ms? 有用逻辑分析仪测量一下时间吗

具体没有呢,速度挺慢的
您需要登录后才可以回帖 立即登录
高级模式
12下一页
统计信息
  • 会员数: 28273 个
  • 话题数: 40244 篇