# 错误操作,此提交无法运行

This commit is contained in:
jxh
2025-03-20 16:36:10 +08:00
parent 8f5aa0e0a7
commit 55eb2bed54
8 changed files with 212 additions and 39 deletions

View File

@ -2,15 +2,18 @@
#include <STC15.H>
#include <stdint.h>
#include <stdio.h>
// Driver
#include "iic.h"
#include "uart.h"
// Config
#include "config.h"
// Driver
#include "iic.h"
#include "timer.h"
#include "uart.h"
// Lib
#include "delay.h"
#include "ina226.h"
#include "keyscan.h"
#include "oled12864_drv.h"
// #include "sensor_json.h"
void
SystemClock_Init (void)
@ -22,9 +25,14 @@ SystemClock_Init (void)
void
main ()
{
uint32_t last_round_time = 0;
uint32_t this_round_time = 0;
u16 ina226_voltage = 0;
u16 ina226_current = 0;
u16 ina226_power = 0;
// char *p_json_str = NULL;
SystemClock_Init (); // 时钟配置
Timer_Init (); // 初始化定时器
@ -37,6 +45,7 @@ main ()
IIC_Init ();
OLED_Init ();
INA226_Init (0.005f, 2.0f);
Key_Init ();
DelayMs (100); // 初始化延时
@ -47,27 +56,41 @@ main ()
P2M0 |= 0x01;
P20 = 1; // P20为推挽输出
while (1)
{
OLED_ShowNum (4, 1, GetUpTime (), 10, OLED_FONT_EIGHT, OLED_LEFT_ROLL,
OLED_ShowNum (0, 1, GetUpTime (), 10, OLED_FONT_EIGHT, OLED_LEFT_ROLL,
OLED_SHOW);
ina226_voltage = (int16_t)(INA226_ReadBusVoltage () * 1000);
OLED_ShowNum (4, 2, ina226_voltage, 10, OLED_FONT_SIXTEEN,
OLED_LEFT_ROLL, OLED_SHOW);
OLED_ShowNum (0, 2, ina226_voltage, 5, OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_SHOW);
ina226_current = (int16_t)(INA226_ReadCurrent () * 1000);
OLED_ShowNum (4, 4, ina226_current, 10, OLED_FONT_SIXTEEN,
OLED_ShowNum (48, 2, ina226_current, 5, OLED_FONT_SIXTEEN,
OLED_LEFT_ROLL, OLED_SHOW);
ina226_power = (int16_t)(INA226_ReadPower () * 1000);
OLED_ShowNum (4, 6, ina226_power, 10, OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_ShowNum (0, 4, ina226_power, 5, OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_SHOW);
DelayMs (500);
// DelayMs (100); // 初始化延时
last_round_time = this_round_time;
this_round_time = GetUpTime_10Ms ();
OLED_ShowNum (4, 7, this_round_time - last_round_time, 3,
OLED_FONT_EIGHT, OLED_LEFT_ROLL, OLED_SHOW);
// p_json_str = make_sensor_json (ina226_voltage, // 电压
// ina226_current, // 电流
// ina226_power, // 功率
// 0x0CA2, // 温度
// 0x0BF6 // 湿度
// );
// printf ("data:%s",p_json_str); // 打印数据
// OLED_ShowPrintf (0, 6, p_json_str, OLED_FONT_EIGHT, OLED_LEFT_ROLL,
// OLED_SHOW);
Key_Scan ();
}
}