初版调试完成
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
#include "BeepAndLed.h"
|
||||
#include "beepAndLed.h"
|
||||
#include "main.h" // 包含BUZZER_ON/OFF, LED等宏定义
|
||||
|
||||
// ========== 变量定义 ==========
|
||||
static BeeperCtrl_t g_beeper = {
|
||||
.state = BEEPER_STATE_IDLE,
|
||||
.is_active = 0,
|
||||
.repeat = 0,
|
||||
.repeat_done = 0,
|
||||
.on_ms = 0,
|
||||
.off_ms = 0
|
||||
};
|
||||
|
||||
// 延时计数器(供滴答定时器使用)
|
||||
uint32_t BeepAndLedCollDelay1mSCnt = 0;
|
||||
|
||||
// ========== 硬件控制函数(根据您的实际宏定义修改)==========
|
||||
static void Beeper_HW_On(void)
|
||||
{
|
||||
BUZZER_ON(); // 请替换为您的实际宏
|
||||
LED_GREEN_OFF(); // 请替换为您的实际宏
|
||||
LED_RED_ON(); // 请替换为您的实际宏
|
||||
}
|
||||
|
||||
static void Beeper_HW_Off(void)
|
||||
{
|
||||
BUZZER_OFF(); // 请替换为您的实际宏
|
||||
LED_GREEN_ON(); // 请替换为您的实际宏
|
||||
LED_RED_OFF(); // 请替换为您的实际宏
|
||||
}
|
||||
|
||||
// ========== 实现函数 ==========
|
||||
|
||||
/**
|
||||
* @brief 蜂鸣器初始化
|
||||
*/
|
||||
void Beeper_Init(void)
|
||||
{
|
||||
Beeper_Stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 开始鸣响(非阻塞)
|
||||
* @param on_ms 鸣响时间(ms)
|
||||
* @param off_ms 间隔时间(ms)
|
||||
* @param repeat 重复次数(0表示无效)
|
||||
*
|
||||
* @example Beeper_Start(200, 100, 3); // 鸣200ms,停100ms,重复3次
|
||||
*/
|
||||
void Beeper_Start(uint16_t on_ms, uint16_t off_ms, uint8_t repeat)
|
||||
{
|
||||
if (repeat == 0) return;
|
||||
|
||||
// 如果已经在鸣响,可以选择停止并重新开始
|
||||
if (g_beeper.is_active) {
|
||||
Beeper_Stop(); // 停止当前,重新开始新的
|
||||
// return; // 或者选择忽略新请求
|
||||
}
|
||||
|
||||
// 保存参数
|
||||
g_beeper.on_ms = on_ms;
|
||||
g_beeper.off_ms = off_ms;
|
||||
g_beeper.repeat = repeat;
|
||||
g_beeper.repeat_done = 0;
|
||||
g_beeper.is_active = 1;
|
||||
|
||||
// 开启蜂鸣器
|
||||
Beeper_HW_On();
|
||||
|
||||
// 设置延时计数器(开启状态延时)
|
||||
BeepAndLedCollDelay1mSCnt = on_ms;
|
||||
g_beeper.state = BEEPER_STATE_ON;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 停止鸣响
|
||||
*/
|
||||
void Beeper_Stop(void)
|
||||
{
|
||||
// 关闭硬件
|
||||
Beeper_HW_Off();
|
||||
|
||||
// 重置状态机
|
||||
g_beeper.state = BEEPER_STATE_IDLE;
|
||||
g_beeper.is_active = 0;
|
||||
g_beeper.repeat = 0;
|
||||
g_beeper.repeat_done = 0;
|
||||
BeepAndLedCollDelay1mSCnt = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 蜂鸣器状态机更新(放在main.c的while(1)中循环调用)
|
||||
* @note 必须在滴答定时器更新BeepAndLedCollDelay1mSCnt后才能正确工作
|
||||
*/
|
||||
void BeeperLoopHandler(void)
|
||||
{
|
||||
if (!g_beeper.is_active) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (g_beeper.state) {
|
||||
case BEEPER_STATE_ON:
|
||||
// 蜂鸣器开启状态,等待计数器归零
|
||||
if (BeepAndLedCollDelay1mSCnt == 0) {
|
||||
// 延时结束,关闭蜂鸣器
|
||||
Beeper_HW_Off();
|
||||
|
||||
g_beeper.repeat_done++;
|
||||
|
||||
// 检查是否完成所有重复
|
||||
if (g_beeper.repeat_done >= g_beeper.repeat) {
|
||||
// 全部完成,结束
|
||||
g_beeper.is_active = 0;
|
||||
g_beeper.state = BEEPER_STATE_IDLE;
|
||||
} else {
|
||||
// 还有下次,进入等待状态
|
||||
BeepAndLedCollDelay1mSCnt = g_beeper.off_ms;
|
||||
g_beeper.state = BEEPER_STATE_OFF;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case BEEPER_STATE_OFF:
|
||||
// 蜂鸣器关闭等待状态(间隔时间)
|
||||
if (BeepAndLedCollDelay1mSCnt == 0) {
|
||||
// 间隔结束,开启下一次鸣响
|
||||
Beeper_HW_On();
|
||||
|
||||
BeepAndLedCollDelay1mSCnt = g_beeper.on_ms;
|
||||
g_beeper.state = BEEPER_STATE_ON;
|
||||
}
|
||||
break;
|
||||
|
||||
case BEEPER_STATE_WAIT:
|
||||
case BEEPER_STATE_IDLE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 查询是否正在鸣响
|
||||
* @return true:正在鸣响, false:空闲
|
||||
*/
|
||||
bool Beeper_IsPlaying(void)
|
||||
{
|
||||
return g_beeper.is_active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 手动开启蜂鸣器(不计入状态机)
|
||||
*/
|
||||
void Beeper_On(void)
|
||||
{
|
||||
Beeper_HW_On();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 手动关闭蜂鸣器(不计入状态机)
|
||||
*/
|
||||
void Beeper_Off(void)
|
||||
{
|
||||
Beeper_HW_Off();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 清除延时计数器(由滴答定时器调用)
|
||||
* @note 这个函数放在滴答定时器的1ms中断中调用
|
||||
*/
|
||||
void Beeper_ClearDelay(void)
|
||||
{
|
||||
if (BeepAndLedCollDelay1mSCnt > 0) {
|
||||
BeepAndLedCollDelay1mSCnt--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef __BEEPANDLED_H
|
||||
#define __BEEPANDLED_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "bsp.h"
|
||||
|
||||
// ========== 蜂鸣器状态机状态定义 ==========
|
||||
typedef enum {
|
||||
BEEPER_STATE_IDLE = 0, // 空闲
|
||||
BEEPER_STATE_ON, // 蜂鸣器开启延时中
|
||||
BEEPER_STATE_OFF, // 蜂鸣器关闭延时中
|
||||
BEEPER_STATE_WAIT // 等待下一次鸣响
|
||||
} BeeperState_t;
|
||||
|
||||
// ========== 蜂鸣器控制结构体 ==========
|
||||
typedef struct {
|
||||
BeeperState_t state; // 当前状态
|
||||
uint16_t on_ms; // 鸣响时间(ms)
|
||||
uint16_t off_ms; // 间隔时间(ms)
|
||||
uint8_t repeat; // 重复次数
|
||||
uint8_t repeat_done; // 已完成次数
|
||||
uint8_t is_active; // 是否激活
|
||||
} BeeperCtrl_t;
|
||||
|
||||
// ========== 外部可访问变量 ==========
|
||||
extern uint32_t BeepAndLedCollDelay1mSCnt; // 延时计数器(在beepAndLed.c中定义)
|
||||
|
||||
// ========== API函数 ==========
|
||||
void Beeper_Init(void); // 初始化
|
||||
void Beeper_Start(uint16_t on_ms, uint16_t off_ms, uint8_t repeat); // 开始鸣响(非阻塞)
|
||||
void Beeper_Stop(void); // 停止鸣响
|
||||
void BeeperLoopHandler(void); // 状态机更新(放在while(1)中)
|
||||
bool Beeper_IsPlaying(void); // 查询是否正在鸣响
|
||||
void Beeper_On(void); // 手动开启蜂鸣器
|
||||
void Beeper_Off(void); // 手动关闭蜂鸣器
|
||||
void Beeper_ClearDelay(void); // 清除延时计数器(供滴答定时器使用)
|
||||
#endif /* _BEEP_AND_LED_H_ */
|
||||
|
||||
@@ -221,12 +221,12 @@
|
||||
|
||||
//< LED
|
||||
#define LED_GREEN_PORTx (PortA)
|
||||
#define LED_GREEN_PINx (Pin09)
|
||||
#define LED_GREEN_PINx (Pin08)
|
||||
#define LED_GREEN_ON() PORT_SetBits(LED_GREEN_PORTx, LED_GREEN_PINx)//拉高
|
||||
#define LED_GREEN_OFF() PORT_ResetBits(LED_GREEN_PORTx, LED_GREEN_PINx)//拉低
|
||||
|
||||
#define LED_RED_PORTx (PortA)
|
||||
#define LED_RED_PINx (Pin08)
|
||||
#define LED_RED_PINx (Pin09)
|
||||
#define LED_RED_ON() PORT_SetBits(LED_RED_PORTx, LED_RED_PINx)//拉高
|
||||
#define LED_RED_OFF() PORT_ResetBits(LED_RED_PORTx, LED_RED_PINx)//拉低
|
||||
|
||||
|
||||
@@ -3,34 +3,25 @@
|
||||
#include <stdlib.h>
|
||||
#include "bsp.h"
|
||||
|
||||
|
||||
#define USE_FILE_SYSTEM 1
|
||||
#define SDCARD_BLOCK_MAX (10000)
|
||||
|
||||
#define OSC_CNT 40
|
||||
#define SLOPE_CNT 20
|
||||
|
||||
#define SLOPE_VPT 1000
|
||||
#define PRESS_VPT 3
|
||||
#define FOLLOW_VPT 10
|
||||
#define SHIELD_VPT 5000
|
||||
#define SHIELD_VPT 8000
|
||||
#define EME_STOP_VPT 4000
|
||||
#define CENTRE_VPT 2000
|
||||
#define CENTRE_VPT 8000
|
||||
#define CENTRE_SHIELD_VPT 2000
|
||||
|
||||
#define STOP_TIME_MS 500
|
||||
#define CENT_TIME_MS 200
|
||||
#define RUN_TIME_MS 0
|
||||
#define EME_START_MS 0
|
||||
#define EME_STOP_MS 2000
|
||||
#define SLOPE_START_MS 3000
|
||||
|
||||
#define TRAVEL_TIME_MS 30000
|
||||
|
||||
#define PEAK 1200 //1200mm
|
||||
#define VALLEY 720 //720mm
|
||||
|
||||
#define BDC_STOP() (SET_TWIN_BIT0(),SET_TWIN_BIT1())
|
||||
#define BDC_DOWN() (SET_TWIN_BIT0(),CLR_TWIN_BIT1())
|
||||
#define BDC_UP() (SET_TWIN_BIT1(),CLR_TWIN_BIT0())
|
||||
#define BDC_STOP() (SET_TWIN_BIT0(),SET_TWIN_BIT1())
|
||||
#define BDC_DOWN() (SET_TWIN_BIT0(),CLR_TWIN_BIT1())
|
||||
#define BDC_UP() (SET_TWIN_BIT1(),CLR_TWIN_BIT0())
|
||||
|
||||
//#define BDC_STOP() Motor_Control(MOTOR_CMD_STOP)
|
||||
//#define BDC_UP() Motor_Control(MOTOR_CMD_FORWARD)
|
||||
@@ -47,7 +38,6 @@ typedef enum {
|
||||
|
||||
/*设备阈值*/
|
||||
typedef struct{
|
||||
int32_t Slope_VPT;
|
||||
int32_t Stop_VPT;
|
||||
|
||||
int32_t LeftUpVPT;//左上设备阈值
|
||||
@@ -66,16 +56,8 @@ typedef struct{
|
||||
int32_t RightLow_Org_AdZero;//右下设备原始AD零点
|
||||
}ADTrack_t;
|
||||
typedef struct{//电机参数
|
||||
bool InitialFlag;//初始标志位
|
||||
bool RestFlag;
|
||||
bool CaliFlag;
|
||||
bool LoopOne;//循环一次标志位
|
||||
int16_t Current_height;//当前高度mm
|
||||
int16_t CaliNum;//标校数量
|
||||
int32_t LU_HeightStress[488];//左上传感器对应高度应力
|
||||
int32_t LL_HeightStress[488];//左下传感器对应高度应力
|
||||
int32_t RU_HeightStress[488];//右上传感器对应高度应力
|
||||
int32_t RL_HeightStress[488];//右上传感器对应高度应力
|
||||
}MotorPara_t;
|
||||
/*数据读取状态机*/
|
||||
typedef enum {
|
||||
@@ -97,22 +79,9 @@ typedef enum {
|
||||
APP_STATUS_IDLE,
|
||||
APP_STATUS_ON,
|
||||
APP_STATUS_OFF,
|
||||
APP_STATUS_MOTOR_INIT,
|
||||
APP_STATUS_WAIT_MOTOR_INIT,
|
||||
APP_STATUS_WAIT_MOTOR_CALI_UP,
|
||||
APP_STATUS_WAIT_MOTOR_CALI_DOWN,
|
||||
APP_STATUS_WAIT_STEADY,
|
||||
APP_STATUS_ZERO_MARKING,
|
||||
APP_STATUS_HEIGHT_CONTROL,
|
||||
}AppStatus_m;
|
||||
|
||||
typedef struct{
|
||||
__IO uint16_t rPayLen;
|
||||
__IO bool HeaderFrame;
|
||||
__IO uint16_t RxLen;
|
||||
uint8_t RxBuff[10];
|
||||
}Uart1Rx_t;
|
||||
|
||||
typedef struct{
|
||||
__IO uint16_t rPayLen;
|
||||
__IO bool HeaderFrame;
|
||||
@@ -124,25 +93,20 @@ typedef struct {
|
||||
AppStatus_m Status;//状态
|
||||
ReadStatus_m RStatus;
|
||||
AppPara_T Para;
|
||||
Uart1Rx_t RxUart1Data;
|
||||
Uart3Rx_t RxUart3Data;
|
||||
|
||||
ADTrack_t ADTrack;
|
||||
MotorPara_t MotorPara;
|
||||
uint32_t TD1mSDelayCnt;
|
||||
uint32_t Read1mSDelayCnt;
|
||||
uint32_t Uart1Delay1mSCnt;
|
||||
uint32_t Read1mSDelayCnt;
|
||||
uint32_t Uart3RxTimeOut1mSCnt;
|
||||
uint32_t StopCollDelay1mSCnt;
|
||||
uint32_t RunCollDelay1mSCnt;
|
||||
uint32_t CentCollDelay1mSCnt;
|
||||
uint32_t EmergencyDelay1mSCnt;
|
||||
uint32_t SlopeCollDelay1mSCnt;
|
||||
uint32_t CailUp1mSCnt;
|
||||
uint32_t HeightContRolCnt;
|
||||
uint8_t FeedDogDlyCnt;
|
||||
|
||||
bool CaliZeroFlag;//校零标志位
|
||||
bool SideFlag;//侧压标志位
|
||||
bool UpFlag;//上升标志位
|
||||
bool DownFlag;//下降标志位
|
||||
bool StopFlag;//停止标志位
|
||||
@@ -165,8 +129,6 @@ typedef struct {
|
||||
int32_t LeftLowCS1237_SlopeArray[SLOPE_CNT];
|
||||
int32_t RightUpCS1237_SlopeArray[SLOPE_CNT];
|
||||
int32_t RightLowCS1237_SlopeArray[SLOPE_CNT];
|
||||
|
||||
bool WaitFlag;
|
||||
}AppDetect_t;
|
||||
extern AppDetect_t App;
|
||||
|
||||
|
||||
+227
-503
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user