📄 ex_support.c
字号:
/***********************************************************
* 函数库说明:底层硬件初始化驱动函数库 *
* 版本: *
* 作者: *
* 创建日期: *
* -------------------------------------------------------- *
* [硬件说明] *
* 处理器: *
* 系统时钟: *
* -------------------------------------------------------- *
* [支 持 库] *
* 支持库名称:PF_Config.h *
* 需要版本: ----- *
* 声明库说明:硬件平台配置声明库 *
* *
* 支持库名称:EX_Support.h *
* 需要版本: ----- *
* 声明库说明:底层硬件初始化驱动声明库 *
* *
* 支持库名称:LIB_Config.h *
* 需要版本: ----- *
* 支持库说明:库函数配置声明库 *
* -------------------------------------------------------- *
* [版本更新] *
* 修改: *
* 修改日期: *
* 版本: *
* -------------------------------------------------------- *
* [版本历史] *
* -------------------------------------------------------- *
* [使用说明] *
***********************************************************/
/********************
* 头 文 件 配 置 区 *
********************/
# include "PF_Config.h"
# include "EX_Support.h"
# include "LIB_Config.h"
# include "PROC_Communication.h"
/********************
* 系 统 宏 定 义 *
********************/
/*------------------*
* 常 数 宏 定 义 *
*------------------*/
#ifndef MM_K
# define MM_K (3840.0 / (PI * 61))
#endif
/*------------------*
* 动 作 宏 定 义 *
*------------------*/
/********************
* 模块结构体定义区 *
********************/
/********************
* 函 数 声 明 区 *
********************/
void Delay_MS(uint16 wTime);
void Insert_Timer0_OVF_ISR_Code(void);
void Driver_INIT(void);
/********************
* 模块函数声明区 *
********************/
/********************
* 模块变量声明区 *
********************/
static uint16 s_wSystemDelayTimerCounter = 0;
/********************
* 全局变量声明区 *
********************/
uint16 g_wSystemTimer = 0;
uint32 g_dNowMotorPosition = 0x7fffffff;
uint32 g_dAimMotorPosition = 0x7fffffff;
uint32 g_dGoDistance = 0;
BOOL g_bIfMarkDistance = FALSE;
/***********************************************************
* 函数说明:软件驱动初始化函数 *
* 输入: 无 *
* 输出: 无 *
* 调用函数:无 *
***********************************************************/
void Driver_INIT(void)
{
//*在这里插入你的各类软件驱动初始化代码*//
CMOS_INIT();
}
/***********************************************************
* 函数说明:系统毫秒延时函数 *
* 输入: 需要延时的时间长度 *
* 输出: 无 *
* 调用函数:无 *
***********************************************************/
void Delay_MS(uint16 wTime)
{
s_wSystemDelayTimerCounter = wTime;
while(s_wSystemDelayTimerCounter);
}
/***********************************************************
* 函数说明:定时器0中断处理程序代码插入函数 *
* 输入: 无 *
* 输出: 无 *
* 调用函数:无 *
***********************************************************/
void Insert_Timer0_OVF_ISR_Code(void)
{
//uint8 Temp = 0;
//uint8 n = 0;
//uint8 Bytes[sizeof(CMD_FRAME)+1];
int16 nTempDistance = 0;
static BOOL s_bIfSendSuccess = FALSE;
//static uint8 Counter = 0;
g_wSystemTimer++;
if (s_wSystemDelayTimerCounter)
{
s_wSystemDelayTimerCounter--;
}
if (!(g_wSystemTimer & 0x01ff))
{
PORTC ^= BIT(PC0);
/*
Bytes[0] = 0xAA;
Counter = MIN(Counter + 1,20);
TYPE_CONVERSION(&Bytes[1],CMD_FRAME).IfBrake = FALSE;
TYPE_CONVERSION(&Bytes[1],CMD_FRAME).Speed = Counter;
TYPE_CONVERSION(&Bytes[1],CMD_FRAME).Distance = 0;
Temp = 0;
for (n = 0;n < UBOUND(Bytes);n++)
{
SERIAL_OUT(Bytes[n]);
Temp ^= Bytes[n];
}
SERIAL_OUT(Temp);
*/
}
/*
if (!(g_wSystemTimer & 0x0f))
{
REFRESH_SP027
g_dAimMotorPosition++;
}
Set_DISP_BUFF
(
SET_DWORD_DIV_8(g_dNowMotorPosition).BYTECL,
SET_DWORD_DIV_8(g_dNowMotorPosition).BYTEBH,
SET_DWORD_DIV_8(g_dNowMotorPosition).BYTEBL,
SET_DWORD_DIV_8(g_dNowMotorPosition).BYTEAH,
SET_DWORD_DIV_8(g_dNowMotorPosition).BYTEAL
);
*/
if (!(g_wSystemTimer & 0x03))
{
REFRESH_SP027
}
if (!(g_wSystemTimer & 0x0f))
{
if ((g_bIfBrake) || (g_wDistance == 0))
{
if ((g_wDistance == 0) && (!g_bIfBrake))
{
g_dAimMotorPosition += g_cSpeed;
}
else
{
g_dAimMotorPosition = g_dNowMotorPosition;
}
g_dGoDistance = 0;
g_bIfMarkDistance = FALSE;
s_bIfSendSuccess = TRUE;
}
else
{
if (!g_bIfMarkDistance)
{
if (g_cSpeed < 0)
{
g_dGoDistance = g_dNowMotorPosition - (int32)((float)g_wDistance * (float)MM_K);
}
else
{
g_dGoDistance = g_dNowMotorPosition + (int32)((float)g_wDistance * (float)MM_K);
}
g_bIfMarkDistance = TRUE;
}
else
{
nTempDistance = g_dGoDistance - g_dNowMotorPosition;
if (nTempDistance < 0)
{
if (g_cSpeed < 0)
{
//合法速度
if (ABS(nTempDistance) <= ABS(g_cSpeed))
{
//完成动作
g_dAimMotorPosition = g_dGoDistance;
//需要发送完成信号
s_bIfSendSuccess = FALSE;
}
else
{
g_dAimMotorPosition += g_cSpeed;
}
}
/*
else
{
//非法速度
//g_dGoDistance = 0;
//g_bIfMarkDistance = FALSE;
}
*/
}
else if (nTempDistance > 0)
{
if (g_cSpeed <= 0)
{
//非法数据
//g_dGoDistance = 0;
//g_bIfMarkDistance = FALSE;
}
else if (g_cSpeed > 0)
{
//合法速度
if (ABS(nTempDistance) <= ABS(g_cSpeed))
{
//完成动作
g_dAimMotorPosition = g_dGoDistance;
//需要发送完成信号
s_bIfSendSuccess = FALSE;
}
else
{
g_dAimMotorPosition += g_cSpeed;
}
}
}
if (!s_bIfSendSuccess)
{
s_bIfSendSuccess = TRUE;
SERIAL_OUT(0xAC);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -