读取电流电压

This commit is contained in:
jxh
2025-03-19 17:25:17 +08:00
parent 1b6044ebd1
commit d93e502437
3 changed files with 26 additions and 31 deletions

View File

@ -22,9 +22,11 @@ SystemClock_Init (void)
void
main ()
{
u8 addr;
u16 read_i = 0;
u16 adder = 0;
u16 ina226_voltage = 0;
u16 ina226_current = 0;
u16 ina226_power = 0;
u16 loop_counter = 0;
SystemClock_Init (); // 时钟配置
@ -40,7 +42,7 @@ main ()
OLED_Init ();
printf ("INA226_Init()\r\n");
INA226_Init (0x0A, 0.05f);
INA226_Init (0.005f, 2.0f);
DelayMs (100); // 初始化延时
@ -63,34 +65,26 @@ main ()
while (1)
{
adder++;
loop_counter++;
OLED_ShowNum (8, 2, adder, 10, OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_ShowNum (8, 0, loop_counter, 10, OLED_FONT_SIXTEEN, 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);
ina226_current = (int16_t)(INA226_ReadCurrent () * 1000);
OLED_ShowNum (4, 4, ina226_current, 10, 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_SHOW);
DelayMs (1000);
read_i = (int16_t)(INA226_ReadBusVoltage () * 1000);
OLED_ShowNum (4, 6, read_i, 10, OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_SHOW);
printf ("Scanning I2C bus...\r\n");
for (addr = 0x08; addr <= 0x78; addr++)
{ // 有效地址范围
IIC_Start ();
IIC_SendByte (addr << 1); // 发送写命令
if (IIC_WaitAck ())
{
printf ("Device found at: 0x%02X\n", addr);
}
IIC_Stop ();
DelayMs (1);
}
printf ("Scan complete.\n");
DelayMs (1000);
}
}