Files
JYF_STC15W4K_wireless_charge/Src/main.c
2025-03-19 17:25:17 +08:00

103 lines
2.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// System
#include <STC15.H>
#include <stdint.h>
#include <stdio.h>
// Driver
#include "iic.h"
#include "uart.h"
// Config
#include "config.h"
// Lib
#include "delay.h"
#include "ina226.h"
#include "oled12864_drv.h"
void
SystemClock_Init (void)
{
// 烧录时选择30M主频
CLK_DIV = 0x00; // 时钟不分频30MHz直接输出
}
void
main ()
{
u16 ina226_voltage = 0;
u16 ina226_current = 0;
u16 ina226_power = 0;
u16 loop_counter = 0;
SystemClock_Init (); // 时钟配置
EA = 1; // 开总中断
Delay_Init ();
Uart1_Init ();
printf ("IIC_Init()\r\n");
IIC_Init ();
printf ("OLED_Init()\r\n");
OLED_Init ();
printf ("INA226_Init()\r\n");
INA226_Init (0.005f, 2.0f);
DelayMs (100); // 初始化延时
printf ("OLED_ShowPrintf()\r\n");
OLED_ShowPrintf (0, 0, "Hello, oWorld!", OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_SHOW);
OLED_ShowPrintf (0, 2, "Hello, 2World!", OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_CLS);
OLED_ShowPrintf (0, 4, "Hello, 4Wo4rld!", OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_CLS);
P2M1 &= 0xFE; // P20为推挽输出
P2M0 |= 0x01;
P20 = 1; // P20为推挽输出
OLED_ShowNum (4, 4, 123456789, 10, OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_SHOW);
while (1)
{
loop_counter++;
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);
}
}
void
Uart1_Isr (void) interrupt 4
{
if (TI) // 检测串口1发送中断
{
TI = 0; // 清除串口1发送中断请求位
}
if (RI) // 检测串口1接收中断
{
RI = 0; // 清除串口1接收中断请求位
}
}