diff --git a/CAN.C b/CAN.C index 3351a00..b069592 100644 --- a/CAN.C +++ b/CAN.C @@ -324,11 +324,11 @@ void CAN_vInit(void) /// - priority class 3; transmit acceptance filtering is based on the list /// order (like class 1) /// - extended 29-bit identifier - /// - identifier 29-bit: 0x00000003 + /// - identifier 29-bit: 0x00000021 - //--------------MOAR5 = 0xE0000003--------------------------------------- + //--------------MOAR5 = 0xE0000021--------------------------------------- - CAN_vWriteAMData(0xE0000003); // load MO5 arbitration register + CAN_vWriteAMData(0xE0000021); // load MO5 arbitration register // CAN Address pointing to the CAN_MODATAH5 CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1) @@ -633,11 +633,11 @@ void CAN_vInit(void) /// - priority class 3; transmit acceptance filtering is based on the list /// order (like class 1) /// - extended 29-bit identifier - /// - identifier 29-bit: 0x1FFFFFF0 + /// - identifier 29-bit: 0x1FFFFF21 - //--------------MOAR9 = 0xFFFFFFF0--------------------------------------- + //--------------MOAR9 = 0xFFFFFF21--------------------------------------- - CAN_vWriteAMData(0xFFFFFFF0); // load MO9 arbitration register + CAN_vWriteAMData(0xFFFFFF21); // load MO9 arbitration register // CAN Address pointing to the CAN_MODATAH9 CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1) diff --git a/MAIN.C b/MAIN.C index a7d22fd..1146bbb 100644 --- a/MAIN.C +++ b/MAIN.C @@ -225,7 +225,7 @@ void main(void) SP = 0xC0; // Initialize Stack Pointer to 0xC0; // CanTransmit(); -// FlgCan_1 = 1;//复位后延时一段时间再调用CAN发送 +// FlgCan_1 = 1;//锟斤拷位锟斤拷锟斤拷时一锟斤拷时锟斤拷锟劫碉拷锟斤拷CAN锟斤拷锟斤拷 // USER CODE END while(1) @@ -243,6 +243,8 @@ void main(void) WDT_vRefresh(); // LedDr(); BootMain(); + RestartDataFlg1 = 0x55; + RestartDataFlg2 = 0x55; // tmp[1] = (ubyte)CntCan_1; // tmp[0] = (ubyte)(CntCan_1>>8); // CAN_vLoadData(0x2, (ulong *)(tmp)); // Add this Line diff --git a/START_XC.a51 b/START_XC.a51 index d914b3b..a0774e4 100644 --- a/START_XC.a51 +++ b/START_XC.a51 @@ -314,6 +314,21 @@ ENDIF RSEG ?C_C51STARTUP STARTUP1: + MOV DPTR,#0xF5E7 + MOVX A,@DPTR + CJNE A,#0x55,ClOCKINIT ;鍒ゆ柇鏁版嵁鏄惁鐩哥瓑锛屼笉鐩哥瓑灏卞垵濮嬪寲鏃堕挓琛ㄧず涓洪噸鏂颁笂鐢 + AJMP Restart1 + +Restart1: MOV DPTR,#0xF600 + MOVX A,@DPTR + CJNE A,#0x55,ClOCKINIT ;鍒ゆ柇鏁版嵁鏄惁鐩哥瓑锛屼笉鐩哥瓑灏卞垵濮嬪寲鏃堕挓琛ㄧず涓洪噸鏂颁笂鐢 + AJMP STARECMAIN ;涓ゆ鍒ゆ柇鐩哥瓑灏辩洿鎺ヨ烦杞埌main鍑芥暟 + + +STARECMAIN: MOV SP,#?STACK-1 + LJMP ?C_START + +ClOCKINIT: IF (XTAL <> 0) ; switch to external XTAL diff --git a/User.c b/User.c index 54885d5..2854c96 100644 --- a/User.c +++ b/User.c @@ -1,43 +1,45 @@ #include "MAIN.H" -//can信息 +//can娑堟伅 UnInfCan UnInfCan_1 = {0}; UnSwSample UnSwSample_1 = {0}; UnSwOut UnSwOut_1 = {0}; -UnRemoteControlOutput UnRemoteControlOutput_1 = {0,0,0,0,0,0,0,0};//遥控器数据发送 -UnRemoteControlOutput UnRemoteControlOutput_2 = {0,0,0,0,0,0,0,0};//遥控器数据发送 +UnRemoteControlOutput UnRemoteControlOutput_1 = {0,0,0,0,0,0,0,0};//閬ユ帶鍣ㄦ暟鎹彂閫 +UnRemoteControlOutput UnRemoteControlOutput_2 = {0,0,0,0,0,0,0,0};//閬ユ帶鍣ㄦ暟鎹彂閫 SBusData sbus_data; -//CAN发送周期 +//CAN鍙戦佽鏁 uword CntCan_1 = 0; bit FlgCan_1 = 0; -//第一次采集到有效数据指示 +//绗竴娆¢噰闆嗘暟鎹湁鏁堟爣蹇 bit FlgOneTime = 0; ubyte uart2RxFlag = 0; uword RgCanPerid = 50; ubyte can_error_cnt = 0; ubyte can_error_flg = 0; +ubyte RestartDataFlg1 _at_ 0xF5E7; +ubyte RestartDataFlg2 _at_ 0xF600; //PWM 20181227 ubyte PwmH[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //----------------------------------------------------------------------- -//RTC定时器 +//RTC瀹氭椂鍣 //----------------------------------------------------------------------- void RTCProcess(void) { //************************************************************************ -//////CAN发送周期 +//////CAN鍙戦佽鏁 if(FlgCan_1){CntCan_1++;if(CntCan_1 >= RgCanPerid){FlgCan_1=0; CntCan_1=0;}}else{CntCan_1=0;} //************************************************************************ } -// SBus 数据解析函数 +// SBus 鏁版嵁瑙f瀽鍑芥暟 SBusData* parseSBusData(const uint8_t *input_data) { - // 解析16个通道的数据,每个通道为11位 + // 瑙f瀽16涓氶亾鐨勬暟鎹紝姣忎釜閫氶亾涓11浣 sbus_data.channels[0] = (input_data[1] | input_data[2] << 8) & 0x07FF; sbus_data.channels[1] = (input_data[2] >> 3 | input_data[3] << 5) & 0x07FF; sbus_data.channels[2] = (input_data[3] >> 6 | input_data[4] << 2 | input_data[5] << 10) & 0x07FF; @@ -56,20 +58,14 @@ SBusData* parseSBusData(const uint8_t *input_data) sbus_data.channels[14] = (input_data[20] >> 2 | input_data[21] << 6) & 0x07FF; sbus_data.channels[15] = (input_data[21] >> 5 | input_data[22] << 3) & 0x07FF; - // 解析标志字节 + // 瑙f瀽鏍囧織瀛楄妭 sbus_data.flags = input_data[23]; uart2RxFlag = 1; -// for(ubyte i=0;i<8;i++) -// { -// printf( "%d ",i); -// printf( "%04x\r\n",sbus_data.channels[i]); -// } -// printf("%d\r\n",sbus_data.channels[0]); return &sbus_data; } -//can错误处理 +//can閿欒澶勭悊 void CanErrorProcess(void) { ubyte ubNSRL; @@ -119,37 +115,37 @@ void CanTransmit(ubyte index,ubyte *buf) CanTransmitbuf[4] = buf[6]; CanTransmitbuf[5] = buf[7]; - CAN_waitTransmit(index);//发送前等待上一帧发送完毕,这样不会丢帧 - CAN_vLoadData(index, (ulong *)CanTransmitbuf);// 装载数据 + CAN_waitTransmit(index);//鍙戦佸墠绛夊緟涓婁竴甯у彂閫佸畬锛屼笉鐒朵細涓㈠抚 + CAN_vLoadData(index, (ulong *)CanTransmitbuf);// 瑁呰浇鏁版嵁 CAN_vTransmit(index); } typedef enum { - STT_INIT_LIGHT, // 必须保留的初始状态 - STT_STABLE, // 稳定态 - STT_BLINK_CHECK, // 闪烁检测 - STT_BLINKING // 闪烁保持 + STT_INIT_LIGHT, // 杩涘叆淇濇寔鐨勫垵濮嬬姸鎬 + STT_STABLE, // 绋冲畾鎬 + STT_BLINK_CHECK, // 闂儊妫娴 + STT_BLINKING // 闂儊纭 } BlinkState; typedef struct { BlinkState current_state; uint8_t last_input; - uint16_t unified_timer; // 统一计时器[7](@ref) - uint8_t trans_count; // 保留必要的事件计数器 + uint16_t unified_timer; // 缁熶竴瀹氭椂鍣 + uint8_t trans_count; // 缈昏浆娆℃暟闇瑕佽褰 uint8_t stable_type; } BlinkDetector; BlinkDetector blink_detector = {0}; -/* LED状态检测核心状态机(统一计时器优化版) - * 参数: - * ctx - 状态机上下文指针(需保证非空) - * current_input- 当前输入电平(0:灭 1:亮) - * output - 输出状态指针(0:无效 1:稳定亮 2:稳定灭 3:闪烁) - * 设计原则: - * 1. 单一定时器复用机制[8](@ref) - * 2. 防御性清零策略[1](@ref) - * 3. 状态迁移原子操作[9](@ref) +/* LED鐘舵佹娴嬪嚱鏁帮紙鐘舵佹満+缁熶竴瀹氭椂鍣ㄤ紭鍖栫増锛 + * 鍙傛暟锛 + * ctx - 鐘舵佹満涓婁笅鏂囨寚閽堬紙闇淇濊瘉闈炵┖锛 + * current_input- 褰撳墠杈撳叆鐢靛钩锛0:浣 1:楂橈級 + * output - 杈撳嚭鐘舵佹寚绀猴紙0:鏃犳晥 1:绋冲畾楂 2:绋冲畾浣 3:闂儊锛 + * 鍘熺悊锛 + * 1. 缁熶竴瀹氭椂鍣ㄦ浛浠e師澶氳鏃跺櫒 + * 2. 绠鍖栫姸鎬佽浆绉婚昏緫 + * 3. 鐘舵佽縼绉诲師瀛愭搷浣 */ void detectLedState(BlinkDetector* ctx, uint8_t current_input, uint8_t* output) { @@ -157,13 +153,13 @@ void detectLedState(BlinkDetector* ctx, uint8_t current_input, uint8_t* output) switch(ctx->current_state) { - /* 关键初始状态:确保首次正确捕获输入 */ + /* 鍏抽敭鍒濆鐘舵侊細纭繚棣栨鐘舵佹纭缓绔 */ case STT_INIT_LIGHT: { - ctx->last_input = current_input; // 强制记录初始值 + ctx->last_input = current_input; // 寮哄埗璁板綍鍒濆鍊 ctx->stable_type = current_input ? 1 : 2; - ctx->current_state = STT_STABLE; // 立即进入稳定态 - ctx->unified_timer = 0; // 初始化计时器 + ctx->current_state = STT_STABLE; // 杩涘叆绋冲畾鐘舵 + ctx->unified_timer = 0; // 鍒濆鍖栬鏃跺櫒 *output = 0; break; } @@ -176,13 +172,13 @@ void detectLedState(BlinkDetector* ctx, uint8_t current_input, uint8_t* output) ctx->trans_count = 1; ctx->unified_timer = 0; ctx->last_input = current_input; - ctx->stable_type = current_input ? 1 : 2; // 同步状态类型[4](@ref) + ctx->stable_type = current_input ? 1 : 2; // 鍚屾鐘舵佸彉閲 } else if(ctx->unified_timer >= STABLE_CONFIRM_TIME) { *output = ctx->stable_type; ctx->unified_timer = 0; - ctx->stable_type = current_input ? 1 : 2; // 二次确认[10](@ref) + ctx->stable_type = current_input ? 1 : 2; // 纭鐘舵 } else { @@ -191,54 +187,54 @@ void detectLedState(BlinkDetector* ctx, uint8_t current_input, uint8_t* output) } break; } - /* 闪烁检测态:在时间窗口内统计电平跳变次数 */ + /* 闂儊鐘舵侊細鏃堕棿绐楀彛鍐呯粺璁$數骞崇炕杞鏁 */ case STT_BLINK_CHECK: { - if(ctx->unified_timer >= BLINK_WINDOW) // 达到检测窗口时长[8](@ref) + if(ctx->unified_timer >= BLINK_WINDOW) // 鍒拌揪妫娴嬬獥鍙f椂闂 { - if(ctx->trans_count >= MIN_BLINKS) // 满足最小闪烁次数 + if(ctx->trans_count >= MIN_BLINKS) // 杈惧埌鏈灏忛棯鐑佹鏁 { - ctx->current_state = STT_BLINKING;// 进入闪烁保持态 - ctx->unified_timer = 0; // 重置超时计时器 + ctx->current_state = STT_BLINKING;// 杩涘叆闂儊纭鐘舵 + ctx->unified_timer = 0; // 閲嶇疆瓒呮椂璁℃椂 } - else // 未达闪烁阈值 + else // 鏈揪闂儊闃堝 { - ctx->current_state = STT_STABLE; // 返回稳定态 - ctx->unified_timer = 0; // 跨状态复用计时器 + ctx->current_state = STT_STABLE; // 杩斿洖绋冲畾鐘舵 + ctx->unified_timer = 0; // 閲嶇疆鐘舵佽鏃跺櫒 } } - else // 窗口期内检测 + else // 妫娴嬫湡鍐 { - ctx->unified_timer++; // 窗口期计时累计 + ctx->unified_timer++; // 缁熶竴璁℃椂绱 if(current_input != ctx->last_input) { - ctx->trans_count++; // 跳变次数累计 - ctx->last_input = current_input; // 更新最新输入值 + ctx->trans_count++; // 缈昏浆娆℃暟绱 + ctx->last_input = current_input; // 鏇存柊鏈鍚庢娴嬪 } } break; } - /* 闪烁保持态:监测闪烁活动持续性 */ + /* 闂儊纭鐘舵侊細缁存寔闂儊娲诲姩鍒ゆ柇 */ case STT_BLINKING: { - // 新增输入变化检测 + // 妫娴嬬數骞冲彉鍖栬鏁 if(current_input != ctx->last_input) { - ctx->unified_timer = 0; // 重置超时计时器 + ctx->unified_timer = 0; // 閲嶇疆瓒呮椂璁℃椂 ctx->last_input = current_input; - *output = 3; // 持续输出闪烁状态 + *output = 3; // 杈撳嚭褰撳墠闂儊鐘舵 } else if(ctx->unified_timer >= BLINK_TIMEOUT) { ctx->current_state = STT_STABLE; - ctx->stable_type = current_input ? 1 : 2; // 根据最终状态更新类型[4](@ref) + ctx->stable_type = current_input ? 1 : 2; // 鏇存柊褰撳墠绋冲畾鐘舵佸彉閲 ctx->unified_timer = 0; } else { - ctx->unified_timer ++; // 仅当输入稳定时累计计时 - *output = 3; // 持续输出闪烁状态 + ctx->unified_timer ++; // 缁存寔褰撳墠绋冲畾鏃堕棿绱璁℃椂 + *output = 3; // 杈撳嚭褰撳墠闂儊鐘舵 } break; } @@ -247,7 +243,7 @@ void detectLedState(BlinkDetector* ctx, uint8_t current_input, uint8_t* output) } } -//SBUS和CAN的数据转换 +//SBUS杞珻AN鏁版嵁瑙f瀽 void sbusCanDecode(void) { float SBUS2CANdecodeTemp = 0.0; @@ -257,36 +253,18 @@ void sbusCanDecode(void) { uart2RxFlag = 0; - //转弯 - SBUS2CANdecodeTemp = (float)(sbus_data.channels[0]); - SBUS2CANdecodeTemp = (DF_ZeroValue - SBUS2CANdecodeTemp)*23;//需要变换一下符号,因为加油是正 - DF_Curvature = (int16_t)SBUS2CANdecodeTemp;//曲率 - if( (DF_Curvature > (-50)) && (DF_Curvature < 50) ) //增加回0的死区,解决会中问题。 - { - DF_Curvature = 0; - } + //閫氶亾0 - 鐩存帴鍙戦佸師濮嬪 + DF_Curvature = (int16_t)sbus_data.channels[0]; - //转速 - SBUS2CANdecodeTemp = (float)(sbus_data.channels[1]); - SBUS2CANdecodeTemp = (DF_ZeroValue - SBUS2CANdecodeTemp)*2.3;//需要变换一下符号,因为加油是正 - DF_Speed = (int16_t)SBUS2CANdecodeTemp;//转速 - if( (DF_Speed > (-50)) && (DF_Speed < 50) ) //增加回0的死区,解决会中问题。 - { - DF_Speed = 0; - } + //閫氶亾1 - 鐩存帴鍙戦佸師濮嬪 + DF_Speed = (int16_t)sbus_data.channels[1]; - //备用 - SBUS2CANdecodeTemp = (float)(sbus_data.channels[7]); - SBUS2CANdecodeTemp = (DF_ZeroValue - SBUS2CANdecodeTemp);//需要变换一下符号,因为加油是正 - DF_Reserve = (int16_t)SBUS2CANdecodeTemp;//转速 - if( (DF_Reserve > (-50)) && (DF_Reserve < 50) ) //增加回0的死区,解决会中问题。 - { - DF_Reserve = 0; - } + //閫氶亾7 - 鐩存帴鍙戦佸師濮嬪 + DF_Reserve = (int16_t)sbus_data.channels[7]; //SwA - if(sbus_data.channels[1] >= 1700)//按下 + if(sbus_data.channels[1] >= 1700)//楂樹綅 { DF_SwA = 1; } @@ -296,35 +274,35 @@ void sbusCanDecode(void) } //SwB - if(sbus_data.channels[6] >= 1700)//第三档 + if(sbus_data.channels[6] >= 1700)//绗笁妗 { DF_SwB = 2; } - else if(sbus_data.channels[6] <= 250)//第二档 + else if(sbus_data.channels[6] <= 250)//绗簩妗 { DF_SwB = 0; } - else//第一档 + else//绗竴妗 { DF_SwB = 1; } //SwC - if(sbus_data.channels[4] >= 1700)//第三档 + if(sbus_data.channels[4] >= 1700)//绗笁妗 { DF_SwC = 2; } - else if(sbus_data.channels[4] <= 250)//第二档 + else if(sbus_data.channels[4] <= 250)//绗簩妗 { DF_SwC = 0; } - else//第一档 + else//绗竴妗 { DF_SwC = 1; } //SwD - if(sbus_data.channels[5] >= 1700)//按下 + if(sbus_data.channels[5] >= 1700)//楂樹綅 { DF_SwD = 1; } @@ -333,20 +311,20 @@ void sbusCanDecode(void) DF_SwD = 0; } - if(0 == sbus_data.flags)//23通道数据 为0标志手柄连接正常 + if(0 == sbus_data.flags)//23閫氶亾鐘舵 涓0鏍囧織浣嶈〃绀洪仴鎺у櫒 { - DF_RCHSta = 1;//手柄在线 + DF_RCHSta = 1;//閬ユ帶鍣ㄥ湪绾 } else { - DF_RCHSta = 0;//手柄离线 + DF_RCHSta = 0;//閬ユ帶鍣ㄧ绾 } SBUS2CANdecodeTemp = (float)(sbus_data.channels[2]); - UnRemoteControlOutput_2.bit_data.speed = (int16_t)SBUS2CANdecodeTemp;//保留轴 + UnRemoteControlOutput_2.bit_data.speed = (int16_t)SBUS2CANdecodeTemp;//鏁版嵁 SBUS2CANdecodeTemp = (float)(sbus_data.channels[3]); - UnRemoteControlOutput_2.bit_data.curvature = (int16_t)SBUS2CANdecodeTemp;//保留轴 + UnRemoteControlOutput_2.bit_data.curvature = (int16_t)SBUS2CANdecodeTemp;//鏁版嵁 } @@ -355,7 +333,7 @@ void sbusCanDecode(void) } -//CAN发送接收 +//CAN鍙戦佹帴鏀 void CanRXTX(void) { stCAN_SWObj StrCanRx = {0}; @@ -397,7 +375,7 @@ void CanRXTX(void) // UnInfCan_1.ArrData.ArrRX[1][5] = StrCanRx.ulDATAH.ubDB[3]; // CAN_vReleaseObj(DF_SwRxPwm); -//// //接收的数据保存到PWM数据结构中20181227 +//// //鎺ユ敹鍒扮殑鏁版嵁淇濆瓨鍒癙WM鏁版嵁缁撴瀯浣20181227 //// PwmH[0 ] = (ubyte)UnInfCan_1.BitData.Pwm_01; //// PwmH[1 ] = (ubyte)UnInfCan_1.BitData.Pwm_02; //// PwmH[2 ] = (ubyte)UnInfCan_1.BitData.Pwm_03; @@ -417,7 +395,7 @@ void CanRXTX(void) } -//50ms发送一帧 +//50ms鍙戦佷竴甯 if(!FlgCan_1) { FlgCan_1 = 1; @@ -430,9 +408,9 @@ void CanRXTX(void) // UnRemoteControlOutput_2.bit_data.reserve1 = sbus_temp[1]; - if( (MATCH_CMD == UnInfCan_1.ArrData.ArrRX[0][0]) || (CHANGE_CMD == UnInfCan_1.ArrData.ArrRX[0][0]) )//对频或者切换 + if( (MATCH_CMD == UnInfCan_1.ArrData.ArrRX[0][0]) || (CHANGE_CMD == UnInfCan_1.ArrData.ArrRX[0][0]) )//瀵归鍛戒护鎴栧垏鎹 { - if(MATCH_CMD == UnInfCan_1.ArrData.ArrRX[0][0])//对频 + if(MATCH_CMD == UnInfCan_1.ArrData.ArrRX[0][0])//瀵归 { match_freq_time = MATCH_TIME; } @@ -444,15 +422,15 @@ void CanRXTX(void) switch(match_freq_sta) { case 0: - if(match_freq_cnt >= match_freq_time)//时间根据命令确定 + if(match_freq_cnt >= match_freq_time)//鏃堕棿鍒颁簡灏卞彂閫佺‘璁 { - SwOut01 = 0;//取消对频 + SwOut01 = 0;//鍙栨秷瀵归 match_freq_sta = 1; match_freq_cnt = 0; } else { - SwOut01 = 1;//对频指令 + SwOut01 = 1;//瀵归鎸囦护 match_freq_sta = 0; match_freq_cnt ++; } @@ -461,14 +439,14 @@ void CanRXTX(void) case 1: if(match_freq_cnt >= MATCH_WAIT_TIME)// { - SwOut01 = 0;//取消对频 + SwOut01 = 0;//鍙栨秷瀵归 match_freq_sta = 0; match_freq_cnt = 0; UnInfCan_1.ArrData.ArrRX[0][0] = 0; } else { - SwOut01 = 0;//对频指令 + SwOut01 = 0;//瀵归鎸囦护 match_freq_sta = 1; match_freq_cnt ++; } @@ -481,7 +459,7 @@ void CanRXTX(void) CanTransmit(DF_SwTx1,(ubyte *)&UnRemoteControlOutput_2.arr[0]); } - if( (0x40 == can_error_cnt) || (0x80 == can_error_cnt) )//20250625判断是否出现总线错误 + if( (0x40 == can_error_cnt) || (0x80 == can_error_cnt) )//20250625鍒ゆ柇鏄惁鍙戠敓鎬荤嚎閿欒 { can_error_flg = can_error_cnt; CAN_vInit(); @@ -491,18 +469,3 @@ void CanRXTX(void) } - - - - - - - - - - - - - - - diff --git a/user.H b/user.H index 4cf5f6f..3c0eb9a 100644 --- a/user.H +++ b/user.H @@ -2,19 +2,19 @@ #define _user_H_ -#define SAMPLE_INTERVAL 50 // 50ms采样周期 -#define BLINK_TIMEOUT (1000 / SAMPLE_INTERVAL) // 1秒稳定确认 -#define BLINK_WINDOW (1000 / SAMPLE_INTERVAL) // 1秒闪烁检测窗口 -#define STABLE_CONFIRM_TIME (1000 / SAMPLE_INTERVAL) // 1秒闪烁检测窗口 +#define SAMPLE_INTERVAL 50 // 50ms锟斤拷锟斤拷锟斤拷锟斤拷 +#define BLINK_TIMEOUT (1000 / SAMPLE_INTERVAL) // 1锟斤拷锟饺讹拷确锟斤拷 +#define BLINK_WINDOW (1000 / SAMPLE_INTERVAL) // 1锟斤拷锟斤拷烁锟斤拷獯帮拷锟 +#define STABLE_CONFIRM_TIME (1000 / SAMPLE_INTERVAL) // 1锟斤拷锟斤拷烁锟斤拷獯帮拷锟 #define MIN_BLINKS 2 -#define MATCH_TIME (2000 / SAMPLE_INTERVAL)//对频时间 -#define MATCH_WAIT_TIME (1000 / SAMPLE_INTERVAL)//对频完,等待时间 +#define MATCH_TIME (2000 / SAMPLE_INTERVAL)//锟斤拷频时锟斤拷 +#define MATCH_WAIT_TIME (1000 / SAMPLE_INTERVAL)//锟斤拷频锟疥,锟饺达拷时锟斤拷 -#define CHANGE_TIME (200 / SAMPLE_INTERVAL)//对频时间 +#define CHANGE_TIME (200 / SAMPLE_INTERVAL)//锟斤拷频时锟斤拷 -#define MATCH_CMD 0xDB//对频命令 -#define CHANGE_CMD 0xBD//切换命令 +#define MATCH_CMD 0xDB//锟斤拷频锟斤拷锟斤拷 +#define CHANGE_CMD 0xBD//锟叫伙拷锟斤拷锟斤拷 #define uint32_t ulong @@ -64,25 +64,25 @@ #define dfOut_15 SwOut11 //KGF15 #define dfOut_16 SwOut12 //KGF16 -#define dfPwmH 10 //PWMμ???μ???ê±??£?10£?10ms×óóò£???ì?Dèòa2aê?20181227 +#define dfPwmH 10 //PWM锟斤拷???锟斤拷???锟斤拷锟斤拷??锟斤拷?10锟斤拷?10ms锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷???锟斤拷?D锟斤拷锟斤拷a2a锟斤拷?20181227 -#define DF_ZeroValue 1000//?ù?Yò£???÷£???0ê±êy?Y?a1022 +#define DF_ZeroValue 1000//?锟斤拷?Y锟斤拷锟斤拷???锟铰★拷???0锟斤拷锟斤拷锟斤拷y?Y?a1022 -#define DF_Speed UnRemoteControlOutput_1.bit_data.speed//?ù?è -#define DF_Curvature UnRemoteControlOutput_1.bit_data.curvature//×aí? -#define DF_Reserve UnRemoteControlOutput_1.bit_data.reserve1//±£á? +#define DF_Speed UnRemoteControlOutput_1.bit_data.speed//?锟斤拷?锟斤拷 +#define DF_Curvature UnRemoteControlOutput_1.bit_data.curvature//锟斤拷a锟斤拷? +#define DF_Reserve UnRemoteControlOutput_1.bit_data.reserve1//锟斤拷锟疥á? #define DF_SwA UnRemoteControlOutput_1.bit_data.switch_a//DF_SwA #define DF_SwB UnRemoteControlOutput_1.bit_data.switch_b//DF_SwB #define DF_SwC UnRemoteControlOutput_1.bit_data.switch_c//DF_SwC #define DF_SwD UnRemoteControlOutput_1.bit_data.switch_d//DF_SwD -#define DF_RCHSta UnRemoteControlOutput_1.bit_data.enable//ê?±úê1?ü×′ì? +#define DF_RCHSta UnRemoteControlOutput_1.bit_data.enable//锟斤拷?锟斤拷锟斤拷锟斤拷1?锟斤拷锟斤拷锟戒ì? -//#define DF_RCHEmSwSta UnRCH_1.BitData.RCHBit07//?±í£?a1?×′ì?ê1?ü×′ì? +//#define DF_RCHEmSwSta UnRCH_1.BitData.RCHBit07//?锟斤拷锟斤拷锟斤拷?a1?锟斤拷锟戒ì?锟斤拷1?锟斤拷锟斤拷锟戒ì? @@ -98,10 +98,10 @@ -// ?¨ò?2¢3?ê??ˉ SBus ?a???á11ì? +// ?锟斤拷锟斤拷?2锟斤拷3?锟斤拷??锟斤拷 SBus ?a???锟斤拷11锟斤拷? typedef struct { - uint16_t channels[16]; // ′?′¢16??í¨μàμ??a???á1? - uint8_t flags; // ±ê??×??ú + uint16_t channels[16]; // 锟斤拷?锟斤拷锟16??锟斤拷锟斤拷锟教拷锟斤拷??a???锟斤拷1? + uint8_t flags; // 锟斤拷锟斤拷??锟斤拷??锟斤拷 } SBusData; @@ -109,30 +109,30 @@ typedef struct { -// ?óê?ò£???÷ê?è? +// ?锟斤拷锟斤拷?锟斤拷锟斤拷???锟铰拷?锟斤拷? typedef struct _StrRemoteControlOutput { - //-----·¢?íêy?Y0x12000023---------------------------------------------- - signed int speed : 16; // ?ú?ê - signed int curvature : 16; // ?ù?è + //-----锟斤拷锟斤拷?锟斤拷锟斤拷y?Y0x12000023---------------------------------------------- + signed int speed : 16; // ?锟斤拷?锟斤拷 + signed int curvature : 16; // ?锟斤拷?锟斤拷 - unsigned int reserve1 : 16; // ò£???á + unsigned int reserve1 : 16; // 锟斤拷锟斤拷???锟斤拷 unsigned int switch_a : 1; // SwA - unsigned int switch_b : 2; // SwB ?±í£?a1? 1êí·? 0/2ê??±í£ - unsigned int switch_c : 2; // SwC ?£ê??a1? 1×??ˉ 0/2ê?ê??ˉ - unsigned int switch_d : 1; // SwD é?μ??a1? ?è?ì°′?ù3¤°′ - unsigned int reserve2 : 1; // ±£á? - unsigned int reserve3 : 1; // ±£á? + unsigned int switch_b : 2; // SwB ?锟斤拷锟斤拷锟斤拷?a1? 1锟斤拷锟斤拷锟斤拷? 0/2锟斤拷??锟斤拷锟斤拷锟斤拷 + unsigned int switch_c : 2; // SwC ?锟疥ê??a1? 1锟斤拷??锟斤拷 0/2锟斤拷?锟斤拷??锟斤拷 + unsigned int switch_d : 1; // SwD 锟斤拷?锟斤拷??a1? ?锟斤拷?锟斤拷锟斤拷锟?锟斤拷3锟斤拷锟斤拷 + unsigned int reserve2 : 1; // 锟斤拷锟疥á? + unsigned int reserve3 : 1; // 锟斤拷锟疥á? - unsigned int enable : 8; // ê1?ü + unsigned int enable : 8; // 锟斤拷1?锟斤拷 } StrRemoteControlInput; typedef union _UnRemoteControlInput { - StrRemoteControlInput bit_data; // ê1ó??¨ò?μ??á11ì?±?á??? - uint8_t arr[sizeof(StrRemoteControlInput)]; // í¨1y?á11ì?ààDíè·?¨′óD? + StrRemoteControlInput bit_data; // 锟斤拷1锟斤拷??锟斤拷锟斤拷?锟斤拷??锟斤拷11锟斤拷?锟斤拷?锟斤拷??? + uint8_t arr[sizeof(StrRemoteControlInput)]; // 锟斤拷锟斤拷1y?锟斤拷11锟斤拷?锟斤拷锟斤拷D锟斤拷锟斤拷锟斤拷?锟斤拷锟戒óD? } UnRemoteControlOutput; @@ -141,7 +141,7 @@ typedef union _UnRemoteControlInput -//---ía2?òaê1ó?±?á?éù?÷--------------------------------------------------------------------- +//---锟斤拷a2?锟斤拷a锟斤拷1锟斤拷?锟斤拷?锟斤拷?锟斤拷锟斤拷?锟斤拷--------------------------------------------------------------------- extern UnSwOut UnSwOut_1; extern UnInfCan UnInfCan_1; extern uword CntCan_1; @@ -150,7 +150,8 @@ extern bit FlgCan_1; extern ubyte rxbuf[25]; extern ubyte uart2RxFlag; extern ubyte can_error_cnt; - +extern ubyte RestartDataFlg1; +extern ubyte RestartDataFlg2; void CanRXTX(void); void SwSample(void);