Files
JYF_STC15W4K_wireless_charge/Src/main.c

105 lines
2.1 KiB
C
Raw Normal View History

2025-03-18 22:49:46 +08:00
// System
2025-03-18 19:34:19 +08:00
#include <STC15.H>
2025-03-18 22:49:46 +08:00
#include <stdint.h>
#include <stdio.h>
2025-03-18 19:34:19 +08:00
// Driver
#include "iic.h"
2025-03-18 22:49:46 +08:00
#include "uart.h"
2025-03-18 19:34:19 +08:00
// Config
#include "config.h"
// Lib
#include "delay.h"
2025-03-18 22:49:46 +08:00
#include "ina226.h"
2025-03-18 19:34:19 +08:00
#include "oled12864_drv.h"
2025-03-18 22:49:46 +08:00
void
SystemClock_Init (void)
{
// 烧录时选择30M主频
CLK_DIV = 0x00; // 时钟不分频30MHz直接输出
2025-03-18 19:34:19 +08:00
}
2025-03-18 22:49:46 +08:00
void
main ()
{
u8 addr;
u16 read_i = 0;
u16 adder = 0;
SystemClock_Init (); // 时钟配置
EA = 1; // 开总中断
Delay_Init ();
Uart1_Init ();
printf ("IIC_Init()\r\n");
IIC_Init ();
2025-03-18 19:34:19 +08:00
2025-03-18 22:49:46 +08:00
printf ("OLED_Init()\r\n");
OLED_Init ();
2025-03-18 19:34:19 +08:00
2025-03-18 22:49:46 +08:00
printf ("INA226_Init()\r\n");
INA226_Init (0x0A, 0.05f);
2025-03-18 19:34:19 +08:00
2025-03-18 22:49:46 +08:00
DelayMs (100); // 初始化延时
2025-03-18 19:34:19 +08:00
2025-03-18 22:49:46 +08:00
printf ("OLED_ShowPrintf()\r\n");
OLED_ShowPrintf (0, 0, "Hello, oWorld!", OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_SHOW);
2025-03-18 19:34:19 +08:00
2025-03-18 22:49:46 +08:00
OLED_ShowPrintf (0, 2, "Hello, 2World!", OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_CLS);
2025-03-18 19:34:19 +08:00
2025-03-18 22:49:46 +08:00
OLED_ShowPrintf (0, 4, "Hello, 4Wo4rld!", OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_CLS);
2025-03-18 19:34:19 +08:00
2025-03-18 22:49:46 +08:00
OLED_ShowNum (4, 4, 123456789, 10, OLED_FONT_SIXTEEN, OLED_LEFT_ROLL,
OLED_SHOW);
2025-03-18 19:34:19 +08:00
2025-03-18 22:49:46 +08:00
while (1)
{
adder++;
OLED_ShowNum (8, 2, adder, 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);
2025-03-18 19:34:19 +08:00
}
2025-03-18 22:49:46 +08:00
IIC_Stop ();
DelayMs (1);
2025-03-18 19:34:19 +08:00
}
2025-03-18 22:49:46 +08:00
printf ("Scan complete.\n");
DelayMs (1000);
2025-03-18 19:34:19 +08:00
}
}
2025-03-18 22:49:46 +08:00
void
Uart1_Isr (void) interrupt 4
2025-03-18 19:34:19 +08:00
{
2025-03-18 22:49:46 +08:00
if (TI) // 检测串口1发送中断
{
TI = 0; // 清除串口1发送中断请求位
}
if (RI) // 检测串口1接收中断
{
RI = 0; // 清除串口1接收中断请求位
}
2025-03-18 19:34:19 +08:00
}