如果MCU做为主机SCL就做为输出,做从机SCL就做为输入。
主机:
当MCU作为主机发送数据流程从数据缓冲寄存器里拿到移位寄存器。在从移位寄存器一位一位发送。
当MCU作为主机接收数据流程先放到移位寄存器。在从移位寄存器放到数据缓冲寄存器。然后读取即可。读取的是一个字节。
从机:对主机发送的地址进行判断。CRC计算/校验。
对于10位地址分两次发。7位地址一次就可以了。
CLK2的决定(以低电平为准)线与功能。
主机2SDA发起。主机1靠边站。
2. OLED IIC通信配置。
首先OLED要选择通信模式。可以IIC,SPI通信。
把 BS0,BS1,BS2分别设置成 0,1,0就是选择IIC通信。
64行分成8页。相当于一页有8行。
一页。6行来显色。
后等待I2C总线寻址。
lm75a_temp.h
#ifndef __LM75A_TEMP_H
#define __LM75A_TEMP_H
#include "gd32f10x.h"
#include "i2c.h"
#define LM75A_I2C_ADDR 0x9E //LM75A的唯一从机地址
#define LM75A_TEMP_REG 0x00 /* 温度寄存器的指针地址 */
#define LM75A_CONF_REG 0x01 /* 配置寄存器(Conf)*/
#define LM75A_THYST_REG 0x10 /* 滞后寄存器(Thyst) */
#define LM75A_TOS_REG 0x11 /* 过热关断寄存器(Tos) */
float lm75a_get_temp(void); //获取温度传感器的温度值
void lm75a_read_temp_reg(uint8_t lm75a_id, uint8_t *p); //读温度寄存器的值
#endif
lm75a_temp.c
#include "lm75a_temp.h"
// 读温度传感器的温度寄存器的值并转换为温度值
float lm75a_get_temp(void){
float temp_result;
//读温度寄存器值
uint8_t byte_data[2];
lm75a_read_temp_reg(LM75A_I2C_ADDR, byte_data);
//将温度寄存器值转为温度值
uint16_t temp_reg = byte_data[0]<<3 | byte_data[1]>>5;
if((temp_reg & 0x0400) == 0){
temp_result = temp_reg * 0.125;
}else{
temp_reg = (~((temp_reg&0x03ff)-1)) & 0x03ff; //补码到原码转换
temp_result = temp_reg * (-0.125);
}
return temp_result;
}
/***
功能:读温度寄存器的值
输入:
uint8_t lm75a_id: lm75a的iic从机地址
uint8_t *p:读取结果存放的位置
返回:无
*****/
void lm75a_read_temp_reg(uint8_t lm75a_id, uint8_t *p){
/******给LM75A写温度寄存器的指针字节********/ // 使用了I2C0(主模式)写功能,
while(i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)); // 如果I2C0繁忙,空等
i2c_start_on_bus(I2C0); // 在I2C0上生成一个起始位
while(!i2c_flag_get(I2C0, I2C_FLAG_SBSEND)); // 如果起始位还没有发送,空等
i2c_master_addressing(I2C0, lm75a_id, I2C_TRANSMITTER); //发送地址,发送模式
while(!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)); // 如果地址还没有发送,空等
i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); /* 清除I2C_FLAG_ADDSEND标志位 */
while(!i2c_flag_get(I2C0, I2C_FLAG_TBE)); // I2C_FLAG_TBE标志是否空闲
i2c_data_transmit(I2C0, LM75A_TEMP_REG); // 发送温度传感器的地址
while(!i2c_flag_get(I2C0, I2C_FLAG_TBE)); // I2C_FLAG_TBE标志是否空闲
i2c_stop_on_bus(I2C0); // 停止信号
while(I2C_CTL0(I2C0) & 0x20); // 判断STOP是否发送完成
/******读LM75A温度寄存器里面的两个字节的值********/ //使用了I2C0(主模式)读功能
i2c_ackpos_config(I2C0, I2C_ACKPOS_NEXT); //设置应答的位置配置 (下一个)
while(i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)); // 如果I2C0繁忙,空等
i2c_start_on_bus(I2C0); // 在I2C0上生成一个起始位
while(!i2c_flag_get(I2C0, I2C_FLAG_SBSEND)); // 如果起始位还没有发送,空等
i2c_master_addressing(I2C0, lm75a_id, I2C_RECEIVER); //发送地址,接收模式
i2c_ack_config(I2C0, I2C_ACK_DISABLE); /* 从机是否发送ACK应答 */
while(!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)); /* 地址是否发送完成 */
i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); /* 清除I2C_FLAG_ADDSEND标志位 */
//从I2C_DATA读值
while(!i2c_flag_get(I2C0, I2C_FLAG_BTC)); // 字节是否传输完成
while(!i2c_flag_get(I2C0, I2C_FLAG_RBNE)); // 如果I2C_DATA为空,空等
*p = i2c_data_receive(I2C0);
while(!i2c_flag_get(I2C0, I2C_FLAG_RBNE)); // 如果I2C_DATA为空,空等
*(p+1) = i2c_data_receive(I2C0);
i2c_stop_on_bus(I2C0);
while(I2C_CTL0(I2C0) & 0x200);
i2c_ackpos_config(I2C0, I2C_ACKPOS_CURRENT); // 重新设置应答的位置
i2c_ack_config(I2C0, I2C_ACK_ENABLE);
}
oled_i2c.h
#ifndef __OLED_H
#define __OLED_H
#include "gd32f10x.h"
#include "i2c.h"
#define OLED_I2C_ADDR 0x78
#define OLED_I2C_CMD_ADDR 0x00
#define OLED_I2C_DATA_ADDR 0x40
#define MAX_COLUMN 132
void i2c_write_byte(uint8_t i2c_addr, uint8_t i2c_data);
void oled_write_command(uint8_t oled_cmd);
void oled_write_data(uint8_t oled_data);
void oled_init(void);
void oled_display_white(void); // OLED 白屏显示
void oled_clear_all(void); // OLED 清屏显示
void oled_fill(uint8_t fill_data); // 单一色度填充OLED屏
void oled_set_pos(uint8_t x, uint8_t y); // 设置坐标
void oled_show_char(uint8_t x, uint8_t y, uint8_t chr, uint8_t char_size); // 显示字符
void oled_show_string(uint8_t x, uint8_t y, uint8_t *str, uint8_t char_size); // 显示字符串
void oled_show_error(uint8_t x, uint16_t y, uint8_t *err); // 显示错误提示
#endif
oled_i2c.c
#include "oled_i2c.h"
#include "oled_font.h"
/**
* 功能:
* 输入:
* 1)uint8_t i2c_addr,
* 2)uint8_t i2c_data
**/
void i2c_write_byte(uint8_t i2c_addr, uint8_t i2c_data){
while(i2c_flag_get(I2C0, I2C_FLAG_I2CBSY));
i2c_start_on_bus(I2C0);
while(!i2c_flag_get(I2C0, I2C_FLAG_SBSEND)); // 进入主机模式
i2c_master_addressing(I2C0, OLED_I2C_ADDR, I2C_TRANSMITTER);
while(!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)); // 判断地址发送出去
i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); // 清除ADDSEND位
while(SET != i2c_flag_get(I2C0, I2C_FLAG_TBE)); // 进入数据发送状态(命令或者数据地址)
i2c_data_transmit(I2C0, i2c_addr);
while(!i2c_flag_get(I2C0, I2C_FLAG_BTC));
i2c_data_transmit (I2C0, i2c_data); // (要发的命令或者数据指令的具体数据)
while(!i2c_flag_get(I2C0, I2C_FLAG_BTC));
i2c_stop_on_bus (I2C0);
while(I2C_CTL0(I2C0)&0x0200);
}
/**
* 功能:
* 输入:oled_cmd:oled的控制命令
**/
void oled_write_command(uint8_t oled_cmd){
i2c_write_byte(OLED_I2C_CMD_ADDR, oled_cmd);
}
/**
* 功能:
* 输入:oled_data:要发送给oled的数据
**/
void oled_write_data(uint8_t oled_data){
i2c_write_byte(OLED_I2C_DATA_ADDR, oled_data);
}
/**
* 功能:
* 输入:无
**/
void oled_init(void){
oled_write_command(0xAE);// 0xAE:关显示,0xAF:开显示
oled_write_command(0x00);// 设置开始地址的低字节
oled_write_command(0x10);// 设置开始地址的高字节
oled_write_command(0xd5);// 命令头,设置显示时钟分频比/振荡器频率
oled_write_command(0x80);// 设置分割比率,设置时钟为100帧/秒
oled_write_command(0xa8);// 命令头,设置多路复用率(1 to 64)
oled_write_command(0x3f);// --1/64 duty
oled_write_command(0xd3);// 命令头,设置显示偏移移位映射RAM计数器(0x00~0x3F)
oled_write_command(0x00);// 不偏移
oled_write_command(0x00);// 写入页位置(0xB0~7)
oled_write_command(0x40);// 显示开始线
oled_write_command(0x8d);// VCC电源
oled_write_command(0x14);// --set(0x10) disable
oled_write_command(0xa1);// 设置段重新映射
oled_write_command(0xc8);// 设置Y轴扫描方向,0xc0上下反置 ,0xc8正常(上边为0行)
oled_write_command(0xda);// 命令头,--set com pins hardware configuration
oled_write_command(0x12);
oled_write_command(0x81);// 对比度,指令:0x81,数据:0~255(255最高)
oled_write_command(0xff);
oled_write_command(0xd9);// 命令头,--set pre-charge period
oled_write_command(0xf1);// Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
oled_write_command(0xdb);// 命令头,--set vcomh
oled_write_command(0x30);// Set VCOM Deselect Level
oled_write_command(0x20);// 水平寻址设置
oled_write_command(0x00);
oled_write_command(0xa4);// 0xa4:正常显示,0xa5:整体点亮
oled_write_command(0xa6);// 0xa6:正常显示,0xa7:反色显示
oled_write_command(0xAF);// 0xAE:关显示,0xAF:开显示
}
// OLED显示单一色度
void oled_fill(uint8_t fill_data){
uint8_t i=0, n;
for(i = 0; i < 8; i++){
oled_write_command (0xB0+i); //设置页地址(0~7)
oled_write_command (0x00); //设置显示位置—列低地址
oled_write_command (0x10); //设置显示位置—列高地址
for(n = 0; n < 132; n++){
oled_write_data(fill_data);
}
}
}
// OLED 白屏显示
void oled_display_white(void){
oled_fill(0xFF);
}
// OLED 清屏显示
void oled_clear_all(void){
oled_fill(0x00);
}
// OLED打开
void oled_on(){
oled_write_command(0xAF); // 开启显示
oled_write_command(0x8D); // 设置电荷泵
oled_write_command(0x14); // 开启电荷泵
}
// OLED关闭
void oled_off(){
oled_write_command(0xAF); // 开启显示
oled_write_command(0x8D); // 设置电荷泵
oled_write_command(0x10); // 关闭电荷泵
}
// OLED设置显示位置
void oled_set_pos(uint8_t x, uint8_t y){
oled_write_command(0xB0 + y);
oled_write_command((x & 0xf0) >> 4 | 0x10 );
oled_write_command((x & 0x0f) | 0x01 );
}
// 显示char字符
void oled_show_char(uint8_t x, uint8_t y, uint8_t chr, uint8_t char_size){
uint8_t c_index = 0, i = 0;
c_index = chr - ' '; // 获取chr在字模数组中的序号
if(char_size == 16){
if(x > MAX_COLUMN - 8){ //如果超出了屏幕的显示宽度,则换到下一行重新开始
x = 0;
y += 2;
}
oled_set_pos(x, y);
for(i = 0; i < 8; i++){
oled_write_data(F8X16[c_index*16 + i]);
}
oled_set_pos(x, y+1);
for(i = 0; i < 8; i++){
oled_write_data(F8X16[c_index*16 + i + 8]);
}
}else if(char_size == 8){
if(x > MAX_COLUMN - 6){ //如果超出了屏幕的显示宽度,则换到下一行重新开始
x = 0;
y += 1;
}
oled_set_pos(x, y);
for(i = 0; i < 6; i++){
oled_write_data(F6x8[c_index][i]);
}
}else{
oled_show_error(x, y, (uint8_t *)"wrong char_size setted.");
}
}
// 显示字符串
void oled_show_string(uint8_t x, uint8_t y, uint8_t *str, uint8_t char_size){
uint8_t i = 0;
while(str[i] != '\0'){
oled_show_char(x, y, str[i], char_size);
if(char_size == 16){
x += 8;
if(x > MAX_COLUMN - 8){
x = 0;
y += 2;
}
}else if(char_size == 8){
x += 6;
if(x > MAX_COLUMN - 8){
x = 0;
y += 1;
}
}
i++;
}
}
// 在(x,y)处显示“error!”信息
void oled_show_error(uint8_t x, uint16_t y, uint8_t *err){
oled_show_string(x, y, err, 16);
}
oled_font.h
#ifndef __OLED_FONT_H
#define __OLED_FONT_H
//常用ASCII表
//偏移量32
//ASCII字符集
//偏移量32
//大小:12*6
/************************************6*8的点阵************************************/
const unsigned char F6x8[][6] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp
0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// !
0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// "
0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// #
0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $
0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// %
0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// &
0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// '
0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// (
0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// )
0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// *
0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// +
0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// ,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// -
0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// .
0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// /
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2
0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5
0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7
0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8
0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// :
0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ;
0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// <
0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// =
0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// >
0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ?
0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @
0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A
0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B
0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C
0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E
0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F
0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G
0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I
0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J
0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L
0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P
0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R
0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S
0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T
0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W
0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X
0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y
0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z
0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [
0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55
0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ]
0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^
0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _
0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// '
0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a
0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b
0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c
0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d
0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e
0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f
0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g
0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h
0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i
0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j
0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k
0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l
0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m
0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n
0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o
0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p
0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q
0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r
0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s
0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t
0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x
0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y
0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z
0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines
};
/****************************************8*16的点阵************************************/
const unsigned char F8X16[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};
#endif
main.c
#include
#include "systick.h"
#include "usart_comm.h"
#include "i2c.h"
#include "lm75a_temp.h"
#include "oled_i2c.h"
int main(){
systick_config();
i2c_init();
oled_init();
oled_clear_all();
oled_show_string(24, 0, (uint8_t *)"hello", 16);
float temp_result = 0.0;
char temp_string[80];
while(1){
temp_result = lm75a_get_temp(); /* 获取温度 */
sprintf(temp_string, "temperature is: %.3f C.", temp_result);
oled_show_string(0, 2, (uint8_t *)temp_string, 16); /* 显示到OLED */
delay_1ms(1000); //等待1s
}
}
OLED具体初始化设置看手册。