OLED INA226基本完成
This commit is contained in:
@@ -9,8 +9,12 @@
|
||||
|
||||
#if PCA9685_USE_SOFT_IIC == 1
|
||||
|
||||
#define PCA9685_SOFT_IIC_SCL_PIN P1_5
|
||||
#define PCA9685_SOFT_IIC_SDA_PIN P1_4
|
||||
#define PCA9685_SOFT_IIC_SCL_PIN P15
|
||||
#define PCA9685_SOFT_IIC_SDA_PIN P14
|
||||
|
||||
#define PCA9685_SDA_LEVEL(x) (PCA9685_SOFT_IIC_SDA_PIN = x)
|
||||
#define PCA9685_SCL_LEVEL(x) (PCA9685_SOFT_IIC_SCL_PIN = x)
|
||||
#define PCA9685_SDA_READ() (PCA9685_SOFT_IIC_SDA_PIN)
|
||||
|
||||
#else
|
||||
|
||||
|
||||
@@ -25,8 +25,10 @@ typedef enum
|
||||
#define IIC_SEND_OK 0
|
||||
#define IIC_SEND_FAIL 1
|
||||
|
||||
void iic_scan(void);
|
||||
void iic_init(IICN_enum iic_n, uint8 wait_time);
|
||||
uint8 iic_write_reg(uint8 dev_add, uint8 reg, uint8 dat);
|
||||
uint8 iic_write_reg_bytes(uint8 dev_add, uint8 reg, uint8 *dat, uint8 num);
|
||||
uint8 iic_read_reg(uint8 dev_add, uint8 reg, uint8 *dat);
|
||||
uint8 iic_read_reg_bytes(uint8 dev_add, uint8 reg, uint8 *dat, uint8 num);
|
||||
void iic_change_pin(IICN_enum iic_n);
|
||||
|
||||
@@ -2,19 +2,25 @@
|
||||
#define __IIC_SOFT_H__
|
||||
|
||||
#include "common.h"
|
||||
#include "gpio.h"
|
||||
// #include "gpio.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PIN_enum scl_pin; // SCL引脚
|
||||
PIN_enum sda_pin; // SDA引脚
|
||||
// PIN_enum scl_pin; // SCL引脚
|
||||
// PIN_enum sda_pin; // SDA引脚
|
||||
void (*SCL_SET)(void);
|
||||
void (*SCL_CLR)(void);
|
||||
void (*SDA_SET)(void);
|
||||
void (*SDA_CLR)(void);
|
||||
uint8 (*SDA_READ)(void);
|
||||
uint16 wait_time; // 等待时间,用于I2C总线速度控制
|
||||
} IIC_Soft_Config;
|
||||
|
||||
void soft_iic_scan(IIC_Soft_Config *config);
|
||||
void soft_iic_init(IIC_Soft_Config *config);
|
||||
|
||||
uint8 soft_iic_read_reg(IIC_Soft_Config *config, uint8 dev_addr, uint8 reg_addr, uint8 *dat);
|
||||
|
||||
void soft_iic_write_reg(IIC_Soft_Config *config, uint8 dev_addr, uint8 reg_addr, uint8 dat);
|
||||
void soft_iic_write_reg_bytes(IIC_Soft_Config *config, uint8 dev_addr, uint8 reg, uint8 *dat, uint8 len);
|
||||
uint8 soft_iic_read_reg(IIC_Soft_Config *config, uint8 dev_addr, uint8 reg_addr, uint8 *dat);
|
||||
uint8 soft_iic_read_reg_bytes(IIC_Soft_Config *config, uint8 dev_addr, uint8 reg, uint8 *buf, uint8 len);
|
||||
|
||||
#endif
|
||||
|
||||
83
Header/ina226.h
Normal file
83
Header/ina226.h
Normal file
@@ -0,0 +1,83 @@
|
||||
#ifndef __INA226_H__
|
||||
#define __INA226_H__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
#define INA226_USE_SOFT_IIC 0
|
||||
|
||||
#define INA226_NUM 1
|
||||
|
||||
#define INA226_READ_TIME_MS 1
|
||||
|
||||
#if (1==INA226_USE_SOFT_IIC)
|
||||
|
||||
#define INA226_SDA_PIN P24
|
||||
#define INA226_SCL_PIN P25
|
||||
#define INA226_SOFT_WAIT_TIME 5
|
||||
|
||||
#define INA226_SDA_LEVEL(x) (INA226_SDA_PIN = x)
|
||||
#define INA226_SCL_LEVEL(x) (INA226_SCL_PIN = x)
|
||||
#define INA226_SDA_READ() (INA226_SDA_PIN)
|
||||
|
||||
#else
|
||||
|
||||
#define INA226_IIC IIC_1
|
||||
#define INA226_HARD_WAIT_TIME 10
|
||||
|
||||
#endif
|
||||
|
||||
#define INA226_CONFIG_REG 0x00
|
||||
#define INA226_SHUNTVOT_REG 0x01
|
||||
#define INA226_BUSVOT_REG 0x02
|
||||
#define INA226_POWER_REG 0x03
|
||||
#define INA226_CURRENT_REG 0x04
|
||||
#define INA226_CALIBRATION_REG 0x05
|
||||
|
||||
#define INA226_DEF_ADDR 0x40
|
||||
#define INA226_DEF_MODE {0x44, 0x4F}
|
||||
#define INA226_DEF_CAL {0x0D, 0x1B}
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8 addr;
|
||||
float max_current_A;
|
||||
float rshunt_mOhm;
|
||||
float vot_fix_k;
|
||||
float amp_fix_k;
|
||||
uint8 mode[2];
|
||||
} INA226_Config;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float c_lsb_mA;
|
||||
uint8 cal[2];
|
||||
} INA226_Calibration;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float voltage_V;
|
||||
float current_A;
|
||||
float power_W;
|
||||
float shunt_voltage_mV;
|
||||
float energy_J;
|
||||
float quantity_C;
|
||||
uint8 org_reg[4][2];
|
||||
float past_voltage_V[10];
|
||||
float past_current_A[10];
|
||||
} INA226_Result;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
INA226_Config config;
|
||||
INA226_Calibration calibration;
|
||||
INA226_Result result;
|
||||
} INA226_t;
|
||||
|
||||
extern INA226_t ina226[INA226_NUM];
|
||||
|
||||
void INA226_Init(INA226_t *ina226, uint8 addr, uint8 mode[2], float max_current_A, float rshunt_mOhm, float amp_fix_k, float vot_fix_k);
|
||||
void INA226_Read(INA226_t *ina226);
|
||||
|
||||
#endif
|
||||
9
Header/oled_font.h
Normal file
9
Header/oled_font.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef __OLED_FONT_H__
|
||||
#define __OLED_FONT_H__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
extern const uint8 code oled_6x8[][6];
|
||||
extern const uint8 code ascii_font_8x16[][16];
|
||||
|
||||
#endif
|
||||
64
Header/oled_iic_SSD1306.h
Normal file
64
Header/oled_iic_SSD1306.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef __OLED_IIC_SSD1306_H__
|
||||
#define __OLED_IIC_SSD1306_H__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define OLED_USE_SOFT_IIC 1
|
||||
|
||||
#define OLED_ADDR 0x3C
|
||||
|
||||
#if (1==OLED_USE_SOFT_IIC)
|
||||
|
||||
#define OLED_SDA_PIN P24
|
||||
#define OLED_SCL_PIN P25
|
||||
#define OLED_SOFT_WAIT_TIME 0
|
||||
|
||||
#define OLED_SDA_LEVEL(x) (OLED_SDA_PIN = x)
|
||||
#define OLED_SCL_LEVEL(x) (OLED_SCL_PIN = x)
|
||||
#define OLED_SDA_READ() (OLED_SDA_PIN)
|
||||
|
||||
#else
|
||||
|
||||
#define OLED_IIC IIC_2
|
||||
#define OLED_HARD_WAIT_TIME 0
|
||||
|
||||
#endif
|
||||
|
||||
//定义显示方向
|
||||
//0 横屏模式
|
||||
//1 横屏模式 旋转180
|
||||
#define OLED_DISPLAY_DIR 0
|
||||
|
||||
#if (0==OLED_DISPLAY_DIR || 1==OLED_DISPLAY_DIR)
|
||||
#define X_WIDTH 128
|
||||
#define Y_WIDTH 64
|
||||
|
||||
#else
|
||||
#error "OLED_DISPLAY_DIR 定义错误"
|
||||
|
||||
#endif
|
||||
|
||||
#define Brightness 0x7f //设置OLED亮度 越大越亮 范围0-0XFF
|
||||
#define XLevelL 0x00
|
||||
#define XLevelH 0x10
|
||||
#define XLevel ((XLevelH&0x0F)*16+XLevelL)
|
||||
#define Max_Column 128
|
||||
#define Max_Row 64
|
||||
|
||||
|
||||
void oled_init(void);
|
||||
void oled_fill(uint8 dat);
|
||||
void oled_set_pos(uint8 x, uint8 y);
|
||||
void oled_putpixel(uint8 x,uint8 y,uint8 data1);
|
||||
void oled_clrpixel(uint8 x,uint8 y);
|
||||
void oled_p6x8str(uint8 x,uint8 y,const int8 ch[]);
|
||||
|
||||
void oled_uint16(uint8 x, uint8 y, uint16 num);
|
||||
void oled_int16(uint8 x, uint8 y, int16 num);
|
||||
void oled_printf_int32(uint16 x,uint16 y,int32 dat,uint8 num);
|
||||
void oled_printf_float(uint16 x,uint16 y,double dat,uint8 num,uint8 pointnum);
|
||||
void oled_dis_bmp(uint16 high, uint16 width, uint8 *p,uint8 value);
|
||||
void oled_print_chinese(uint8 x, uint8 y, uint8 size, const uint8 *p, uint8 len);
|
||||
|
||||
|
||||
#endif
|
||||
8
Header/printfs.h
Normal file
8
Header/printfs.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef __PRINTFS_H__
|
||||
#define __PRINTFS_H__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
uint32 zf_sprintf (int8 *buff, const int8 *format, ...);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user