91 lines
2.8 KiB
C
91 lines
2.8 KiB
C
#include "common.h"
|
|
#include "delay.h"
|
|
#include "oled_iic_SSD1306.h"
|
|
#include "ina226.h"
|
|
#include "tim.h"
|
|
#include "iic.h"
|
|
#include "iic_soft.h"
|
|
#include "printfs.h"
|
|
#include "pwm.h"
|
|
|
|
|
|
uint8 mode[2] = INA226_DEF_MODE;
|
|
// uint8 m5[2] = {0x0D, 0x1B};
|
|
// int8 s_buff[30];
|
|
// uint8 ttt = 0;
|
|
// extern IIC_Soft_Config ina226_soft_config;
|
|
|
|
void main()
|
|
{
|
|
board_init(); // 初始化板子
|
|
// delay_ms(1000);
|
|
// printf("System Init...\r\n");
|
|
P05 = 0;
|
|
oled_init();
|
|
INA226_Init(&ina226[0], INA226_DEF_ADDR, mode, 20, 5, 1.0683, 1.002393);
|
|
|
|
pit_timer_ms(TIM_1,INA226_READ_TIME_MS);
|
|
|
|
pwm_init(PWMA_CH1P_P60,100000,5000);
|
|
|
|
// oled_fill(0xff);
|
|
|
|
// iic_init(IIC_1,10);
|
|
// ttt += iic_write_reg_bytes(0x40, 0x00, mode, 2);
|
|
// ttt += iic_write_reg_bytes(0x40, 0x05, m5, 2);
|
|
// // printf("ttt: %d",ttt);
|
|
P06 = 0;
|
|
// iic_scan();
|
|
while(1)
|
|
{
|
|
// soft_iic_scan(&ina226_soft_config);
|
|
// uint8 vot[2] = {0};
|
|
// uint8 cru[2] = {0};
|
|
// uint8 pow[2] = {0};
|
|
// int16 vott, crut, powt;
|
|
// float votf, cruf, powf;
|
|
// // // iic_scan();
|
|
// iic_read_reg_bytes(0x40, 0x02, vot, 2);
|
|
// iic_read_reg_bytes(0x40, 0x04, cru, 2);
|
|
// iic_read_reg_bytes(0x40, 0x03, pow, 2);
|
|
// zf_sprintf(s_buff, "VOT: %d,%d\r\n", 45, 1234);
|
|
// // printf("%s", s_buff);
|
|
// // printf("VOT: %d,%d\r\n", (int32)(vot[0] << 8 | vot[1]), 1234);
|
|
// vott = (int16)(vot[0] << 8 | vot[1]);
|
|
// votf = (float)vott * 1.25 /1000.0f;
|
|
|
|
// crut = (int16)(cru[0] << 8 | cru[1]);
|
|
// cruf = (float)crut * 0.30518 /1000.0f;
|
|
|
|
// powt = (int16)(pow[0] << 8 | pow[1]);
|
|
// powf = (float)powt * 0.30518*25 /1000.0f;
|
|
|
|
oled_printf_float(0, 0, ina226[0].result.voltage_V,2,4);oled_p6x8str(55, 0, "V");
|
|
oled_printf_float(0, 1, ina226[0].result.current_A,2,4);oled_p6x8str(55, 1, "A");
|
|
oled_printf_float(0, 2, ina226[0].result.power_W,2,4);oled_p6x8str(55, 2, "W");
|
|
oled_printf_float(0, 3, ina226[0].result.energy_J,5,2);oled_p6x8str(55, 3, "J");
|
|
oled_printf_float(0, 4, ina226[0].result.energy_J/3600.0f,5,3);oled_p6x8str(55, 4, "Wh");
|
|
oled_printf_float(0, 5, ina226[0].result.quantity_C,5,2);oled_p6x8str(55, 5, "C");
|
|
// // oled_int16(0, 0, (int16)(vot[0] << 8 | vot[1]));
|
|
// oled_int16(0, 1, vot[0]);
|
|
// oled_int16(40, 1, vot[1]);
|
|
// oled_int16(80, 1, ttt);
|
|
// oled_int16(0, 2, -12345);
|
|
// oled_printf_float(0, 0, 45.6,2,4);oled_p6x8str(55, 0, "V");
|
|
// oled_p6x8str(0,3,s_buff);
|
|
// // printf("System Running...\r\n");
|
|
// // USB_SendData("wewe",4);
|
|
P53 ^= 0x01;
|
|
// if(P53)
|
|
// {
|
|
// oled_fill(0xff);
|
|
// }
|
|
// else
|
|
// {
|
|
// oled_fill(0x00);
|
|
// }
|
|
// delay_ms(1000);
|
|
}
|
|
}
|
|
|