IIC的再认识

news2024/11/26 14:53:58

IIC介绍

关于IIC的基本概念,其实在学习89C52的时候已经大致了解过了,且由于STM32支持了IIC协议,所以在STM32中使用IIC可以直接调用HAL库的库函数:

HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c,
                                    uint16_t DevAddress,
                                    uint16_t MemAddress,
                                    uint16_t MemAddSize,
                                    uint8_t *pData,
                                    uint16_t Size,
                                    uint32_t Timeout)

参数一:I2C_HandleTypeDef *hi2c,I2C设备句柄

参数二:uint16_t DevAddress,目标器件的地址,七位地址必须左对齐

参数三:uint16_t MemAddress,目标器件的目标寄存器地址

参数四:uint16_t MemAddSize,目标器件内部寄存器地址数据长度

参数五:uint8_t *pData,待写的数据首地址

参数六:uint16_t Size,待写的数据长度

参数七:uint32_t Timeout,超时时间

返回值:HAL_StatusTypeDef,HAL状态(OK,busy,ERROR,TIMEOUT)

硬件介绍

同样使用之前用过的OLED,使用的是IIC协议:

那么对于之前学习的概念,可以轻易的写出对于OLED写命令写数据的函数封装:

对OLED写命令:

void OLED_writecmd(uint8_t dataCmd)
{
    HAL_I2C_Mem_Write(&hi2c1, 0x78, 0x00, I2C_MEMADD_SIZE_8BIT, &dataCmd, 1, 0xff);
}

 对OLED写数据:

void OLED_writedata(uint8_t dataData)
{
    HAL_I2C_Mem_Write(&hi2c1, 0x78, 0x40, I2C_MEMADD_SIZE_8BIT, &dataData, 1, 0xff);
}

在STM32里再次实现OLED的显示

假如我选择页寻址模式显示以下图像的话:

由于这个图片之前我在取模软件中已经取过模,所以直接拿来用了:

code unsigned char bmpPic[] = { //使用unsigned可以使得原本从负数到正数的范围扩展到两倍的正数,适用于大量无符号数存在时
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,
0x10,0x10,0x10,0x10,0x18,0x08,0x08,0x08,0x08,0x08,0xF8,0x18,0x08,0x08,0x08,0x08,
0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x38,0x0F,0x01,0x07,0x1C,0x70,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xF8,0x0F,0x01,0x01,0x0F,0x70,0xC0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xC0,0x7E,0x03,0x07,0x3C,0xE0,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x70,0x0E,0x03,0x00,0x00,0x07,0x1C,0x70,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xE0,0x1E,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x1E,
0x70,0x80,0x00,0x00,0x00,0xF0,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x1E,0xF0,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFC,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0xE0,0x3C,0x07,0x00,0x00,0x00,0x00,0x00,0x07,0x1C,0x70,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0xE0,0x3E,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x07,0x0C,0x30,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0x3E,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x0C,0x0C,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0F,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x3F,0x60,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xF0,0x1F,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x60,0x3C,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0E,
0x38,0xE0,0xE0,0x3C,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x03,0x06,0x1C,0x70,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x03,0x0E,0x08,0x08,0x08,0x0C,0x06,0x03,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

CubeMX

1. 惯例配置

2. 点击左侧的I2C1,选择I2C:

2.1 在上图下方可以看到IIC的一些配置信息,此处暂时不做修改

 

2.2 点击上图中的GPIO Setting:

所以OLED的SCLSDA应该分别接在 PB6PB7 !

3. 惯例配置生成代码:

 

 

Keil

unsigned char bmpPic[] = { //使用unsigned可以使得原本从负数到正数的范围扩展到两倍的正数,适用于大量无符号数存在时
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,
0x10,0x10,0x10,0x10,0x18,0x08,0x08,0x08,0x08,0x08,0xF8,0x18,0x08,0x08,0x08,0x08,
0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x38,0x0F,0x01,0x07,0x1C,0x70,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xF8,0x0F,0x01,0x01,0x0F,0x70,0xC0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xC0,0x7E,0x03,0x07,0x3C,0xE0,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x70,0x0E,0x03,0x00,0x00,0x07,0x1C,0x70,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xE0,0x1E,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x1E,
0x70,0x80,0x00,0x00,0x00,0xF0,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x1E,0xF0,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFC,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0xE0,0x3C,0x07,0x00,0x00,0x00,0x00,0x00,0x07,0x1C,0x70,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0xE0,0x3E,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x07,0x0C,0x30,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0x3E,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x0C,0x0C,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0F,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x3F,0x60,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xF0,0x1F,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x60,0x3C,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0E,
0x38,0xE0,0xE0,0x3C,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x03,0x06,0x1C,0x70,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x03,0x0E,0x08,0x08,0x08,0x0C,0x06,0x03,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

void OLED_writecmd(uint8_t dataCmd)
{
    HAL_I2C_Mem_Write(&hi2c1, 0x78, 0x00, I2C_MEMADD_SIZE_8BIT, &dataCmd, 1, 0xff);
}

void OLED_writedata(uint8_t dataData)
{
    HAL_I2C_Mem_Write(&hi2c1, 0x78, 0x40, I2C_MEMADD_SIZE_8BIT, &dataData, 1, 0xff);
}

void Oled_Init()
{
	OLED_writecmd(0xAE);//--display off
	OLED_writecmd(0x00);//---set low column address
	OLED_writecmd(0x10);//---set high column address
	OLED_writecmd(0x40);//--set start line address  
	OLED_writecmd(0xB0);//--set page address
	OLED_writecmd(0x81); // contract control
	OLED_writecmd(0xFF);//--128   
	OLED_writecmd(0xA1);//set segment remap 
	OLED_writecmd(0xA6);//--normal / reverse
	OLED_writecmd(0xA8);//--set multiplex ratio(1 to 64)
	OLED_writecmd(0x3F);//--1/32 duty
	OLED_writecmd(0xC8);//Com scan direction
	OLED_writecmd(0xD3);//-set display offset
	OLED_writecmd(0x00);//
	
	OLED_writecmd(0xD5);//set osc division
	OLED_writecmd(0x80);//
	
	OLED_writecmd(0xD8);//set area color mode off
	OLED_writecmd(0x05);//
	
	OLED_writecmd(0xD9);//Set Pre-Charge Period
	OLED_writecmd(0xF1);//
	
	OLED_writecmd(0xDA);//set com pin configuartion
	OLED_writecmd(0x12);//
	
	OLED_writecmd(0xDB);//set Vcomh
	OLED_writecmd(0x30);//
	
	OLED_writecmd(0x8D);//set charge pump enable
	OLED_writecmd(0x14);//
	
	OLED_writecmd(0xAF);//--turn on oled panel		
}
 
void Oled_Clear()
{
	int i;
	int j;
	
	for(i = 0; i<8; i++){
		OLED_writecmd(0xB0 + i);//依次选择每一页
		OLED_writecmd(0x00);//选择0列
	  OLED_writecmd(0x10);//选择0列
		for(j = 0; j<128; j++){
			OLED_writedata(0x00);//由于地址会自动偏移,所以只要重复写128次全0,就可以清一个PAGE
		}
	}
}
 
void print_pic(unsigned char *pic)
{
	unsigned int i;//使用unsigned可以使得原本从负数到正数的范围扩展到两倍的正数,适用于大量无符号数存在时
	unsigned int j;//使用unsigned可以使得原本从负数到正数的范围扩展到两倍的正数,适用于大量无符号数存在时
	
	for(i = 0; i<8; i++){
		OLED_writecmd(0xB0 + i);//依次选择每一page
		OLED_writecmd(0x00);//选择0列
	  OLED_writecmd(0x10);//选择0列
		for(j = 128*i; j<(128*(i+1)); j++){ 
			OLED_writedata(pic[j]);
		}
	}
}

int main(void)
{	
	Oled_Init();
	Oled_Clear();
	
	OLED_writecmd(0x20);//页寻址模式
	OLED_writecmd(0x02);//页寻址模式
	
	print_pic(bmpPic);


  while (1)
  {

  }

}

实现效果 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/764626.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SAP ABAP 报表程序实现下载文件及上传 Excel 并解析

步骤1&#xff1a; 事务代码 SMW0 选择二进制数据选项点击上方按钮。 点击新建按钮输入名称和描述&#xff0c;上传模版文件。 案例传入 EXCEL 如下&#xff1a; 创建好资源库对象结果如下。 步骤2&#xff1a;报表效果展示 点击按钮选择上传的文件。 解析 Excel 文件结果…

酷开科技大屏营销,撬动营销新增量

5G、人工智能、元宇宙等技术的发展促使数字营销的内容、渠道、传播方式发生了一系列变化&#xff1b;存量竞争下&#xff0c;增长成为企业更加迫切、更具挑战的课题&#xff0c;品牌营销活动越来越围绕“生意增长”和“提效转化”的目标展开。 如今的市场环境下&#xff0c;产…

计算机毕业论文选题推荐|软件工程|信息管理|数据分析|系列一

文章目录 导文题目导文 计算机毕业论文选题推荐|软件工程|信息管理 (***语言)==使用其他任何编程语言 例如:基于(***语言)门窗账务管理系统的设计与实现 得到:基于JAVA门窗账务管理系统的设计与实现 基于vue门窗账务管理系统的设计与实现 等等 题目 基于requests多线程…

BERT系列算法解读:(RoBERTa/ALBERT/DistilBERT/Transformer/Hugging Face/NLP/预训练模型/模型蒸馏)

BERT&#xff08;Bidirectional Encoder Representations from Transformers&#xff0c;基于Transformers的双向编码器表示&#xff09;系列算法在自然语言处理任务中是必不可少的经典模型&#xff0c;当初第一代GPT模型发布的时候&#xff0c;坐了冷板凳&#xff0c;罪魁祸首…

【C++】-list的具体使用

&#x1f496;作者&#xff1a;小树苗渴望变成参天大树&#x1f388; &#x1f389;作者宣言&#xff1a;认真写好每一篇博客&#x1f4a4; &#x1f38a;作者gitee:gitee✨ &#x1f49e;作者专栏&#xff1a;C语言,数据结构初阶,Linux,C 动态规划算法&#x1f384; 如 果 你 …

漏洞复现畅捷通CRM SQL注入

免责声明 术文章仅供参考,任何个人和组织使用网络应当遵守宪法法律,遵守公共秩序,尊重社会公德,不得利用网络从事危害国家安全、荣誉和利益,未经授权请勿利用文章中的技术资料对任何计算机系统进行入侵操作。利用此文所提供的信息而造成的直接或间接后果和损失,均由使用…

.NET SqlSuger初次使用

文章目录 前言SqlSuger测试DB Fisrt和CodeFirst 前言 我之前在B站上面发视频说如何使用EF框架去生成实体类。我当时做了Mysql,Sql server,Sqlite的适配。但是下面评论区说SqlSuger很好用&#xff0c;而且很多公司都用SqlSuger。 B站视频&#xff1a;C#如何快速开发数据库业务…

VsCode连不上Server,但SSH可以

造成的原因可能是因为Client处Vscode更新与Server端"~/.vscode-server"文件夹内的版本不匹配&#xff0c;通常来说直接删除该文件夹即可。 但是有时该文夹内有几个问价被占用&#xff1a;“resource busy”,且该文件处于内核态&#xff0c; 通过&#xff1a;“lsof…

Nginx学习之一撸到底

一、Nginx环境搭建 ❶首先创建Nginx的目录并进入&#xff1a; [rootlocalhost]# mkdir /soft && mkdir /soft/nginx/ [rootlocalhost]# cd /soft/nginx/ ❷下载Nginx的安装包&#xff0c;可以通过FTP工具上传离线环境包&#xff0c;也可通过wget命令在线获取安装包…

Python与matlab 实现图像加密--扩散加密

1、图像加密 使用扩散加密 图像加密中,扩散处理是在不改变像素点位置的条件下,将任一明文像素点的信息隐藏在尽可能多的密文像素点中。 基于异或运算的扩散处理 正向(i从1到MN)的算法与其逆算法: 逆向(i从MN到1)的算法与其逆算法: C和S是密码向量,P是明文图像 Python…

本地拉取github上的项目失败,解决办法?

1.Step1&#xff1a;可以复制github上的仓库地址&#xff1b; 比如&#xff1a; https://github.com/FISCO-BCOS/fisco-package-build-tool.git2.Step2&#xff1a;打开自己的码云&#xff0c;并登录进去&#xff0c;没有的可以注册一个&#xff0c;按照下面步骤操作&#xff…

二分模板简单记忆

时间复杂度 O ( l o g n ) O(logn) O(logn) 三个模板 整数二分&#xff08;两个&#xff09; int 答案右区间(int l, int r) {while (l < r){int mid l r >> 1;if (在答案区间(mid)) r mid;else l mid 1;}return l; }// ####################################…

Unity游戏源码分享-射击游戏Low Poly FPS Pack 3.2

Unity游戏源码分享-射击游戏Low Poly FPS Pack 3.2 项目地址&#xff1a;https://download.csdn.net/download/Highning0007/88057717

ES系列--打分机制

一、文档打分机制 当你通过关键字搜索相关文档时&#xff0c;可能会出现多个文档&#xff0c;这些文档的顺序是通过一个max_score属性的大小从高到低顺序展现出来的&#xff0c;max_score属性就是我们所说的评分。而这个评分是通过一个文档打分机制计算出来的。 二、打分原理 …

和鲸社区数据分析每周挑战【第九十八期:企业贷款审批分析】

和鲸社区数据分析每周挑战【第九十八期&#xff1a;企业贷款审批分析】 文章目录 和鲸社区数据分析每周挑战【第九十八期&#xff1a;企业贷款审批分析】一、背景描述二、数据说明三、问题描述四、数据加载五、数据清洗和预处理六、数据探索与分析1、贷款金额分布2、各州的贷款…

Vue渲染系统模块

我们想要实现一个简洁版的Mini-Vue框架&#xff0c;应该包含三个模块&#xff1a;分别是&#xff1a;渲染系统模块、可响应式系统模块、应用程序入库模块。 这篇就来写一下渲染系统模块。剩下两个模块后面有时间再更新。 vue渲染系统实现&#xff0c;应该包含三个功能&#x…

linux之Ubuntu系列(二)远程管理指令

shutdown shutdown 选项 时间 关机或重启 选项&#xff1a; -r 重新启动 提示 不指定选项和参数&#xff0c;默认表示1分钟之后 关闭电脑用SSH远程维护服务器时&#xff0c;最好不要关闭系统&#xff0c;而应该重新启动系统 -r shutdown常用示例 # 1分钟后关机 shutdown …

【C语言初阶(17)】初阶指针

文章目录 Ⅰ指针的概念Ⅱ 指针和指针类型⒈指针 - 整数⒉指针的解引用 Ⅲ 野指针⒈野指针成因⒉规避野指针 Ⅳ 指针运算⒈指针 - 整数⒉指针 - 指针⒊指针的关系运算 Ⅴ 指针和数组Ⅵ 二级指针Ⅶ 指针数组 Ⅰ指针的概念 指针的两个要点 指针是内存中一个最小单元的编号&#…

使用 torch.stft 进行短时傅里叶变换

python 常规的 stft 都是在 cpu 上进行计算&#xff0c;如果网络训练是在 GPU 上进行&#xff0c;那么就涉及到数据传输的问题&#xff0c;降低计算效率&#xff1b;而 torch 自带的 stft 可以直接在 GPU 上进行计算&#xff0c;因此可以节省计算时间。 import torch import t…