当前位置:   article > 正文

【51单片机篇】IIC协议&OLED显示_51单片机模拟iicoled显示

51单片机模拟iicoled显示

一、IIC协议

(一)概述

IIC(集成电路总线)是由飞利浦公司发明的通讯总线,用于连接微控制器及其外围设备,IIC属于半双工同步通信方式。IIC的数据线只有一根,就是SDA,同一时间不管发送还是接收,只能有一个方向进行操作。

(二)构成

IIC串行总线一般有两根信号线,一根是双向的数据SDA,另一根是时钟线SCL,其中时钟信号是由主控器件产生,所有接到IIC总线设备上的串行数据SDA都接到总线的SDA上,各设备的时钟线SCL接到总线的SCL上,对于并联在一条总线上的每个IC都有唯一的地址。

(三)时序分析

IIC总线在传输数据的过程中一共有三种类型信号,分别为:开始信号、结束信号和应答信号。

1.开始信号

时钟线处于高电平,数据线由高电平转为低电平。

2.结束信号

时钟线处于高电平,数据线由低电平转为高电平。

3.应答信号

发送器每发送一个字节(8个bit),就在时钟脉冲9期间释放数据线,由接收器反馈一个应答信号。应答信号为低电平时,规定为有效应答位(ACK,简称应答位),表示接收器已经成功地接收了该字节;应答信号为高电平时,规定为非应答位(NACK),一般表示接收器接收该字节没有成功。

 (四)代码示例

IIC协议基本函数封装

  1. #include "reg52.h"
  2. #include <intrins.h>
  3. sbit scl = P0^1;
  4. sbit sda = P0^3;
  5. void IIC_Start()
  6. {
  7. sda = 1;
  8. scl = 1;
  9. _nop_();
  10. sda = 0;
  11. }
  12. void IIC_Stop()
  13. {
  14. sda = 0;
  15. scl = 1;
  16. _nop_();
  17. sda = 1;
  18. _nop_();
  19. }
  20. char IIC_ACK()
  21. {
  22. char flag;
  23. sda = 1;//就在时钟脉冲9期间释放数据线
  24. _nop_();
  25. scl = 1;
  26. _nop_();
  27. flag = sda;
  28. _nop_();
  29. scl = 0;
  30. _nop_();
  31. return flag;
  32. }
  33. void IIC_Send_Byte(char dataSend)
  34. {
  35. int i;
  36. for(i=0;i<8;i++){
  37. scl = 0;//scl拉低,让sda做好数据准备
  38. sda = dataSend & 0x80;//1000 0000获得dataSend的最高位
  39. _nop_();//发送数据建立时间
  40. scl = 1;//scl拉高开始发送
  41. _nop_();
  42. scl = 0;//发送完毕,拉低
  43. _nop_();
  44. dataSend = dataSend << 1;
  45. }
  46. }
  47. void main()
  48. {
  49. }

 二、OLED显示

(一)时序分析

写命令/数据编程步骤: 

1. start()

2. 写入 b0111 1000 0x78

3. ACK

4. cotrol byte: (0)(0)000000 写入命令 (0)(1)000000写入数据

5. ACK

6. 写入指令/数据

7. ACK

8. STOP

(二)显示一个点

1、初始化

2、显示位置

    Oled_Write_Cmd(0x20);  //选择一个位置,确认页寻址地址
    Oled_Write_Cmd(0x02);  //选择一个位置,确认页寻址地址
    Oled_Write_Cmd(0xB0);  //选择PAGE0

3、显示内容

    Oled_Write_Data(0x08);  //显示一个点

 编程示例

  1. #include "reg52.h"
  2. #include <intrins.h>
  3. sbit scl = P0^1;
  4. sbit sda = P0^3;
  5. void IIC_Start()
  6. {
  7. scl = 0;
  8. sda = 1;
  9. scl = 1;
  10. _nop_();
  11. sda = 0;
  12. }
  13. void IIC_Stop()
  14. {
  15. scl = 0;
  16. scl = 1;
  17. _nop_();
  18. sda = 1;
  19. _nop_();
  20. }
  21. char IIC_ACK()
  22. {
  23. char flag;
  24. sda = 1;//就在时钟脉冲9期间释放数据线
  25. _nop_();
  26. scl = 1;
  27. _nop_();
  28. flag = sda;
  29. _nop_();
  30. scl = 0;
  31. _nop_();
  32. return flag;
  33. }
  34. void IIC_Send_Byte(char dataSend)
  35. {
  36. int i;
  37. for(i=0;i<8;i++){
  38. scl = 0;//scl拉低,让sda做好数据准备
  39. sda = dataSend & 0x80;//1000 0000获得dataSend的最高位
  40. _nop_();//发送数据建立时间
  41. scl = 1;//scl拉高开始发送
  42. _nop_();
  43. scl = 0;//发送完毕,拉低
  44. _nop_();
  45. dataSend = dataSend << 1;
  46. }
  47. }
  48. void OLED_Write_Cmd(char dataCmd)
  49. {
  50. //1.START
  51. IIC_Start();
  52. //2.写入从机地址 b0111 1000 0x78
  53. IIC_Send_Byte(0x78);
  54. //3.ACK
  55. IIC_ACK();
  56. //4.cotrol byte:(0)(0)000000 写入命令 (0)(1)000000 写入数据
  57. IIC_Send_Byte(0x00);
  58. //5.ACK
  59. IIC_ACK();
  60. //6.写入指令/数据
  61. IIC_Send_Byte(dataCmd);
  62. //7.ACK
  63. IIC_ACK();
  64. //8.STOP
  65. IIC_Stop();
  66. }
  67. void OLED_Write_Data(char dataData)
  68. {
  69. //1.START
  70. IIC_Start();
  71. //2.写入从机地址 b0111 1000 0x78
  72. IIC_Send_Byte(0x78);
  73. //3.ACK
  74. IIC_ACK();
  75. //4.cotrol byte:(0)(0)000000 写入命令 (0)(1)000000 写入数据
  76. IIC_Send_Byte(0x40);
  77. //5.ACK
  78. IIC_ACK();
  79. //6.写入指令/数据
  80. IIC_Send_Byte(dataData);
  81. //7.ACK
  82. IIC_ACK();
  83. //8.STOP
  84. IIC_Stop();
  85. }
  86. void OLED_Init(void)
  87. {
  88. OLED_Write_Cmd(0xAE);//--display off
  89. OLED_Write_Cmd(0x00);//---set low column address
  90. OLED_Write_Cmd(0x10);//---set high column address
  91. OLED_Write_Cmd(0x40);//--set start line address
  92. OLED_Write_Cmd(0xB0);//--set page address
  93. OLED_Write_Cmd(0x81); // contract control
  94. OLED_Write_Cmd(0xFF);//--128
  95. OLED_Write_Cmd(0xA1);//set segment remap
  96. OLED_Write_Cmd(0xA6);//--normal / reverse
  97. OLED_Write_Cmd(0xA8);//--set multiplex ratio(1 to 64)
  98. OLED_Write_Cmd(0x3F);//--1/32 duty
  99. OLED_Write_Cmd(0xC8);//Com scan direction
  100. OLED_Write_Cmd(0xD3);//-set display offset
  101. OLED_Write_Cmd(0x00);//
  102. OLED_Write_Cmd(0xD5);//set osc division
  103. OLED_Write_Cmd(0x80);//
  104. OLED_Write_Cmd(0xD8);//set area color mode off
  105. OLED_Write_Cmd(0x05);//
  106. OLED_Write_Cmd(0xD9);//Set Pre-Charge Period
  107. OLED_Write_Cmd(0xF1);//
  108. OLED_Write_Cmd(0xDA);//set com pin configuartion
  109. OLED_Write_Cmd(0x12);//
  110. OLED_Write_Cmd(0xDB);//set Vcomh
  111. OLED_Write_Cmd(0x30);//
  112. OLED_Write_Cmd(0x8D);//set charge pump enable
  113. OLED_Write_Cmd(0x14);//
  114. OLED_Write_Cmd(0xAF);//--turn on oled panel
  115. }
  116. void main()
  117. {
  118. int a = 10;
  119. //1.OLED初始化
  120. OLED_Init();
  121. //2.确认一个位置
  122. //2.1确认页寻址模式
  123. OLED_Write_Cmd(0x20);
  124. OLED_Write_Cmd(0x02);
  125. //2.2选择PAGE0 1011 0000
  126. OLED_Write_Cmd(0xB0);
  127. //3.显示一个点
  128. OLED_Write_Data(0x08);
  129. while(1);//防止程序退出
  130. }

 

(三) 列地址

列初始地址

Oled_Write_Cmd(0x00);   
Oled_Write_Cmd(0x10);

(四)显示字符/汉字/图片

先打开取模软件进行参数设置

 取模格式选择C51格式

 编程示例(只展示主程序部分)

1.显示字符‘A’

  1. /*-- 文字: A --*/
  2. /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
  3. char A1[8] = {0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00};
  4. char A2[8] = {0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20};
  5. void main()
  6. {
  7. int i;
  8. //1.OLED初始化
  9. OLED_Init();
  10. //2.确认一个位置
  11. //2.1确认页寻址模式
  12. OLED_Write_Cmd(0x20);
  13. OLED_Write_Cmd(0x02);
  14. OLED_Clear();
  15. //2.2选择PAGE0
  16. OLED_Write_Cmd(0xB0);
  17. OLED_Write_Cmd(0x00);
  18. OLED_Write_Cmd(0x10);
  19. for(i=0;i<8;i++){
  20. OLED_Write_Data(A1[i]);
  21. }
  22. //2.2选择PAGE1
  23. OLED_Write_Cmd(0xB1);
  24. OLED_Write_Cmd(0x00);
  25. OLED_Write_Cmd(0x10);
  26. for(i=0;i<8;i++){
  27. OLED_Write_Data(A2[i]);
  28. }
  29. while(1);
  30. }

 2.显示“上官可编程”

  1. /*-- 文字: A --*/
  2. /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/
  3. char A1[8] = {0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00};
  4. char A2[8] = {0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20};
  5. /*-- 文字: 上 --*/
  6. /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
  7. code char s1[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00};
  8. code char s2[16] = {0x40,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00};
  9. /*-- 文字: 官 --*/
  10. /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
  11. code char g1[16] = {0x10,0x0C,0x04,0xE4,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0xE4,0x04,0x14,0x0C,0x00};
  12. code char g2[16] = {0x00,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0xF8,0x00,0x00,0x00};
  13. /*-- 文字: 可 --*/
  14. /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
  15. code char k1[16] = {0x00,0x02,0x02,0xF2,0x12,0x12,0x12,0xF2,0x02,0x02,0x02,0xFE,0x02,0x02,0x02,0x00};
  16. code char k2[16] = {0x00,0x00,0x00,0x0F,0x04,0x04,0x04,0x0F,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00};
  17. /*-- 文字: 编 --*/
  18. /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
  19. code char b1[16] = {0x20,0x30,0xAC,0x63,0x30,0x00,0xFC,0x24,0x25,0x26,0x24,0x24,0x24,0x3C,0x00,0x00};
  20. code char b2[16] = {0x22,0x67,0x22,0x12,0x52,0x38,0x07,0xFF,0x09,0x7F,0x09,0x3F,0x89,0xFF,0x00,0x00};
  21. /*-- 文字: 程 --*/
  22. /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
  23. code char c1[16] = {0x24,0x24,0xA4,0xFE,0x23,0x22,0x00,0x3E,0x22,0x22,0x22,0x22,0x22,0x3E,0x00,0x00};
  24. code char c2[16] = {0x08,0x06,0x01,0xFF,0x01,0x06,0x40,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x41,0x00};
  25. void main()
  26. {
  27. unsigned char i;
  28. //1.OLED初始化
  29. OLED_Init();
  30. //2.确认一个位置
  31. //2.1确认页寻址模式
  32. OLED_Write_Cmd(0x20);
  33. OLED_Write_Cmd(0x02);
  34. OLED_Clear();
  35. //2.2选择PAGE0 1011 0000
  36. OLED_Write_Cmd(0xB0);
  37. OLED_Write_Cmd(0x00);
  38. OLED_Write_Cmd(0x10);
  39. for(i=0;i<16;i++){
  40. OLED_Write_Data(s1[i]);
  41. }
  42. for(i=0;i<16;i++){
  43. OLED_Write_Data(g1[i]);
  44. }
  45. for(i=0;i<16;i++){
  46. OLED_Write_Data(k1[i]);
  47. }
  48. for(i=0;i<16;i++){
  49. OLED_Write_Data(b1[i]);
  50. }
  51. for(i=0;i<16;i++){
  52. OLED_Write_Data(c1[i]);
  53. }
  54. //选择page1
  55. OLED_Write_Cmd(0xB1);
  56. OLED_Write_Cmd(0x00);
  57. OLED_Write_Cmd(0x10);
  58. for(i=0;i<16;i++){
  59. OLED_Write_Data(s2[i]);
  60. }
  61. for(i=0;i<16;i++){
  62. OLED_Write_Data(g2[i]);
  63. }
  64. for(i=0;i<16;i++){
  65. OLED_Write_Data(k2[i]);
  66. }
  67. for(i=0;i<16;i++){
  68. OLED_Write_Data(b2[i]);
  69. }
  70. for(i=0;i<16;i++){
  71. OLED_Write_Data(c2[i]);
  72. }
  73. while(1);
  74. }

 3.显示bmp图片

  1. code unsigned char bmpImage[] = {
  2. /*-- 调入了一幅图像:C:\Users\25236\Desktop\嵌入式软件学习\2.51单片机\工具\字模软件\12864演示图片.bmp --*/
  3. /*-- 宽度x高度=128x64 --*/
  4. 0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF0,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF0,0xF0,
  5. 0xF0,0xE0,0xE0,0x60,0x70,0x70,0x30,0x30,0x38,0x18,0x18,0x18,0x18,0x18,0x18,0x1C,
  6. 0x0C,0x1C,0x1C,0x1C,0x18,0x18,0x18,0x18,0x18,0x30,0x30,0x30,0x60,0x60,0xE0,0xE0,
  7. 0xE0,0xF0,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF0,0xF0,0xE0,0xC0,0x80,0x00,
  8. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  9. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  10. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  11. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  12. 0x00,0x3E,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x1F,0x1F,0x07,0x07,0x03,
  13. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  14. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  15. 0x01,0x01,0x03,0x07,0x0F,0x1F,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,
  16. 0x7F,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0x70,0x30,0x30,0x30,0xF0,0xE0,0x00,0x00,
  17. 0x40,0xE0,0x70,0x30,0x30,0x30,0x70,0xF0,0xE0,0x00,0x00,0x00,0xF0,0xF0,0x70,0x30,
  18. 0x30,0x70,0xF0,0xE0,0x00,0x00,0xC0,0xE0,0x70,0x30,0x30,0x30,0x30,0x74,0xFF,0xFF,
  19. 0x00,0x00,0x00,0xE0,0xF0,0x30,0x30,0x30,0x70,0xF0,0xE0,0x00,0x00,0x00,0x00,0x00,
  20. 0x00,0x00,0x03,0x07,0x0F,0x1F,0xFF,0xFF,0x0F,0x01,0x00,0x00,0x00,0x80,0xE0,0xF0,
  21. 0xF8,0xF8,0xFC,0xFC,0x7E,0x7E,0x7E,0xFE,0xFC,0xF8,0x60,0x00,0x00,0x00,0x00,0x00,
  22. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xF8,0xFC,0xFC,0xFE,0x7E,0xFE,0xFC,0xF8,
  23. 0xF8,0xF0,0xE0,0x80,0x00,0x00,0x00,0x01,0x0F,0xFF,0xFF,0x1F,0x0F,0x07,0x03,0x00,
  24. 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x60,0x60,0xE0,0x60,0x7F,0x3F,0x02,0x00,
  25. 0x38,0x7D,0xFE,0x66,0xE6,0x66,0x76,0x7F,0x7F,0x00,0x00,0x00,0x7F,0x7F,0x00,0x00,
  26. 0x00,0x00,0x7F,0x7F,0x00,0x00,0x1F,0x3F,0x7A,0x60,0xE0,0xE0,0x60,0x78,0x7F,0x7F,
  27. 0x00,0x00,0x38,0x7D,0x7F,0xE6,0x46,0x66,0x76,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,
  28. 0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xE0,0x00,0x00,0x00,0x3E,0xFF,0xFF,0xFF,
  29. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x1F,0x03,0x00,0x00,0x00,0x60,0xF0,0xF8,
  30. 0xF8,0xF8,0xF0,0xF0,0x70,0x00,0x00,0x00,0x07,0x3F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
  31. 0xFF,0xFF,0xFF,0xFF,0x7F,0x00,0x00,0x80,0xE0,0xFF,0x3F,0x00,0x00,0x00,0x00,0x00,
  32. 0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  34. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  35. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  36. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x0F,0x1C,0x38,0x60,0xE0,0xC1,0x81,
  37. 0x83,0x03,0x03,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  38. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x03,0x83,
  39. 0x83,0x83,0xC1,0xE0,0x70,0x38,0x1C,0x0F,0x03,0x80,0x80,0xA0,0xB0,0xB8,0xFC,0xF7,
  40. 0xF7,0x92,0x94,0xDC,0xF8,0xD0,0xC0,0x40,0x00,0x00,0x00,0xC0,0xC2,0x46,0xFC,0x40,
  41. 0x00,0x10,0x70,0xC7,0x9E,0xC0,0xFE,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xF0,
  42. 0xA0,0xB0,0xB3,0xFF,0xB2,0x90,0xB0,0xF0,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  43. 0x80,0x80,0x84,0x84,0x84,0x86,0xB6,0xE6,0x96,0x8E,0x86,0x86,0xC0,0xC0,0x80,0x00,
  44. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  45. 0x3F,0xFF,0xFF,0x7F,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0x7C,0x0C,0x0C,0x0C,0x0C,0x0C,
  46. 0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0xFC,0xFC,0xFE,0xFE,0xFE,0xFE,0xFF,0x7F,0xFF,
  47. 0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x18,0x89,0x8C,0x96,0xB7,0xD5,0xD6,
  48. 0xD6,0xD6,0xDF,0xD7,0xCE,0x5C,0x18,0x18,0x08,0x00,0x00,0x00,0x00,0x40,0x7F,0xB0,
  49. 0xD8,0x6C,0x30,0x19,0x0F,0x1F,0x78,0xE0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x08,0x1F,
  50. 0x0C,0x0D,0x0C,0x7F,0xC4,0x84,0x86,0x87,0x80,0xF0,0xF0,0xF0,0x00,0x00,0x00,0x00,
  51. 0x01,0x01,0x01,0x01,0x31,0x60,0xC0,0xFF,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  52. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  53. 0x00,0x0F,0x7F,0xF8,0xE1,0xE1,0xC1,0xC1,0x81,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
  54. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0xC1,0x81,0xC1,0xE1,0xF5,0xFE,0x1F,
  55. 0x01,0x00,0x00,0xE0,0xC0,0x60,0x60,0xC0,0xC0,0x00,0x01,0xE1,0xC1,0x61,0x61,0xC1,
  56. 0xC1,0x81,0x01,0x01,0xE1,0xE0,0x60,0x60,0xC0,0x80,0x00,0x60,0xF8,0xF8,0x40,0x01,
  57. 0xC1,0xE0,0x60,0x60,0xE0,0xC0,0x00,0x01,0xFD,0xF9,0x00,0xF8,0xFC,0x80,0xC0,0xE0,
  58. 0x60,0x00,0x00,0x00,0x01,0x01,0x01,0xC1,0xC1,0x61,0x61,0x61,0xE0,0xC0,0x00,0xC0,
  59. 0xE0,0x60,0x60,0x60,0xC0,0x00,0x01,0xE1,0xE0,0x60,0x60,0xE0,0xC0,0x60,0x60,0xE0,
  60. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  61. 0x00,0x00,0x00,0x03,0x0F,0x0F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x03,0x07,0x03,0x03,
  62. 0x03,0x03,0x02,0x03,0x03,0x07,0x0F,0x1F,0x1F,0x1F,0x1F,0x1F,0x0F,0x07,0x00,0x00,
  63. 0x00,0x00,0x00,0xFF,0xFF,0x10,0x30,0x1F,0x0F,0x00,0x00,0xFF,0xBC,0x10,0x30,0x1F,
  64. 0x1F,0x0F,0x00,0x22,0xFF,0x18,0x10,0x10,0x1F,0x0F,0x00,0x00,0x1F,0x1F,0x10,0x08,
  65. 0x1E,0x1E,0x13,0x1B,0x1F,0x1F,0x00,0x00,0x1F,0x1F,0x00,0x1F,0x1F,0x03,0x07,0x1E,
  66. 0x18,0x00,0x00,0x18,0x18,0x00,0x04,0x0F,0x1D,0x30,0x10,0x10,0x1C,0x1C,0x00,0x0F,
  67. 0x1F,0x10,0x30,0x18,0x1F,0x07,0x00,0x1F,0x1F,0x00,0x00,0x1F,0x1F,0x00,0x00,0x1F,
  68. };
  69. void OLED_Show_Image(unsigned char *image)
  70. {
  71. unsigned char i;
  72. unsigned int j;
  73. for(i=0;i<8;i++){
  74. OLED_Write_Cmd(0xB0 + i);//page0--page7
  75. //每个page从0列
  76. OLED_Write_Data(0x00);
  77. OLED_Write_Data(0x10);
  78. //0到127列,依次写入0,每写入数据,列地址自动偏移
  79. for(j=128*i;j<128*(i+1);j++){
  80. OLED_Write_Data(image[j]);
  81. }
  82. }
  83. }
  84. void main()
  85. {
  86. //1.OLED初始化
  87. OLED_Init();
  88. //2.确认一个位置
  89. OLED_Write_Cmd(0x20);
  90. OLED_Write_Cmd(0x02);
  91. OLED_Clear();
  92. OLED_Show_Image(bmpImage);
  93. OLED_Write_Cmd(0xB0);
  94. OLED_Write_Cmd(0x00);
  95. OLED_Write_Cmd(0x10);
  96. while(1);
  97. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/598776
推荐阅读
相关标签
  

闽ICP备14008679号