|
|
@ -9,131 +9,6 @@ |
|
|
|
* |
|
|
|
*/ |
|
|
|
#include "app.h" |
|
|
|
extern volatile int32_t lcd_issue_motor_speed;//lcd下发的速度单位dsp |
|
|
|
extern volatile int32_t speed_dsp_now;//当前电机的速度单位dsp |
|
|
|
extern int16_t motor_off_state;//电机关闭的状态 |
|
|
|
extern volatile int16_t judge_now_foreward_or_reversal_state;//正转反转的状态 |
|
|
|
extern int32_t wait_send_to_motor_time1s;//等待发送的时间 |
|
|
|
extern int32_t first_set_speed_state; //设置速度的状态 |
|
|
|
extern volatile int32_t recv_lcd_data_state=0;//1就判断是不是接收完成,0不判断 |
|
|
|
extern volatile int32_t recv_motor_data_state=0;//1就判断是不是接收完成,0不判断 |
|
|
|
void func(void) |
|
|
|
{ |
|
|
|
volatile unsigned char str[] = "speed-1000"; |
|
|
|
|
|
|
|
send_cmd_to_motor(str,10); //发送一串字符测试 |
|
|
|
} |
|
|
|
void global_state_inquire(void) |
|
|
|
{ |
|
|
|
/** |
|
|
|
* @brief 对状态进行查询 |
|
|
|
* |
|
|
|
*/ |
|
|
|
motor_jerk_status();//判断电机是否被按下 |
|
|
|
//inquire_motor_error_state();//每1.5秒去读取电机的速度 |
|
|
|
if(motor_off_state)//判断电机是否停止的状态 |
|
|
|
{ |
|
|
|
motor_off_state=0; |
|
|
|
judge_now_foreward_or_reversal_state=0;//判断正转还是反转的标志位清零 |
|
|
|
first_set_speed_state=0;//停止以后清零,下次第一次设置速度不执行 |
|
|
|
} |
|
|
|
if(recv_lcd_data_state) |
|
|
|
{ |
|
|
|
data_from_lcd_recv_Ok(); //判断接收来自lcd的数据是否完成 |
|
|
|
} |
|
|
|
if(recv_motor_data_state) |
|
|
|
{ |
|
|
|
data_from_motor_recv_Ok(); //判断接收来自电机的数据是否完成 |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
void main() |
|
|
|
{ |
|
|
|
peripheral_config(); |
|
|
|
//start_up(); //开机提示 |
|
|
|
//func(); |
|
|
|
int32_t nowexpectspeed_main=0; |
|
|
|
int32_t setspeedthistime_main=0; |
|
|
|
while (1) |
|
|
|
{ |
|
|
|
global_state_inquire(); |
|
|
|
if(lcd_issue_motor_speed!=speed_dsp_now) |
|
|
|
{ |
|
|
|
if(lcd_issue_motor_speed>speed_dsp_now&&wait_send_to_motor_time1s>1100)//目标800,现在0 |
|
|
|
//if(lcd_issue_motor_speed>speed_dsp_now) |
|
|
|
{ |
|
|
|
wait_send_to_motor_time1s=0;//开始等待 |
|
|
|
nowexpectspeed_main = speed_dsp_now + 100; |
|
|
|
if (nowexpectspeed_main > lcd_issue_motor_speed) { |
|
|
|
nowexpectspeed_main = lcd_issue_motor_speed; |
|
|
|
} |
|
|
|
set_moter_speed_internal(nowexpectspeed_main);// 去设置的是10 |
|
|
|
//sleep_ms(500); |
|
|
|
} |
|
|
|
else if(lcd_issue_motor_speed<speed_dsp_now&&wait_send_to_motor_time1s>1100)//目标0 //现在550 差值600 |
|
|
|
//else if(lcd_issue_motor_speed<speed_dsp_now) |
|
|
|
{ |
|
|
|
wait_send_to_motor_time1s=0;//开始等待 |
|
|
|
setspeedthistime_main = speed_dsp_now - 100; |
|
|
|
if (setspeedthistime_main < lcd_issue_motor_speed) { |
|
|
|
setspeedthistime_main = lcd_issue_motor_speed; |
|
|
|
} |
|
|
|
set_moter_speed_internal(setspeedthistime_main); |
|
|
|
//sleep_ms(500); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
void peripheral_config_list(void) |
|
|
|
{ |
|
|
|
/** |
|
|
|
* @brief 外设初始化 |
|
|
|
* |
|
|
|
*/ |
|
|
|
sys_init(); |
|
|
|
led_config(); |
|
|
|
beep_config(); |
|
|
|
lcd_uart_config(); |
|
|
|
motor_uart_config(); |
|
|
|
jerk_key_config(); |
|
|
|
t21_config(); |
|
|
|
init_timer1_as_ticketustimer_in32M(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void send_cmd_to_motor_list(volatile char buff[20], unsigned int num) { |
|
|
|
/** |
|
|
|
* @brief 向电机发送命令 |
|
|
|
* @param buff 发送的命令 |
|
|
|
*/ |
|
|
|
uint16_t count = 1200; |
|
|
|
rs485_re_port |= (0x01 << 3); |
|
|
|
while (num--) { |
|
|
|
while (!TRMT0) |
|
|
|
; |
|
|
|
TX0B = *buff; |
|
|
|
buff++; |
|
|
|
} |
|
|
|
while (!TRMT0) |
|
|
|
; //等待向电机发送数据完成 |
|
|
|
rs485_re_port &= ~(0x01 << 3); |
|
|
|
} |
|
|
|
|
|
|
|
void main() |
|
|
|
{ |
|
|
|
volatile unsigned char str[] = "speed-1000"; |
|
|
|
|
|
|
|
peripheral_config_list(); |
|
|
|
send_cmd_to_motor_list(str,10); //发送一串字符测试 |
|
|
|
while (1) |
|
|
|
{ |
|
|
|
send_cmd_to_motor_list(str,10); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void peripheral_config(void) |
|
|
|
{ |
|
|
|
/** |
|
|
@ -146,7 +21,6 @@ void peripheral_config(void) |
|
|
|
lcd_uart_config(); |
|
|
|
motor_uart_config(); |
|
|
|
jerk_key_config(); |
|
|
|
t21_config(); |
|
|
|
init_timer1_as_ticketustimer_in32M(); |
|
|
|
} |
|
|
|
|
|
|
@ -167,4 +41,43 @@ void start_up(void) |
|
|
|
led_off; |
|
|
|
beep_on; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
extern volatile char lcd_rxbuff[50] = {0}; |
|
|
|
extern volatile int32_t lcd_count = 0; |
|
|
|
extern uint8_t g_lcd_rxbuf_isready;//lcd数据接收过程中为真,接收完成为假 |
|
|
|
|
|
|
|
uint32_t judge_recv_lcd_data_finish_main(uint8_t time) |
|
|
|
{ |
|
|
|
/** |
|
|
|
* @brief 接收LCD的数据完成 |
|
|
|
*/ |
|
|
|
static uint32_t recv_lcd_data_time = 0; |
|
|
|
recv_lcd_data_time = time; |
|
|
|
if(recv_lcd_data_time=0) |
|
|
|
{ |
|
|
|
recv_lcd_data_time = hal_get_ticket(); |
|
|
|
return recv_lcd_data_time; |
|
|
|
} |
|
|
|
else if (hal_has_passedms(recv_lcd_data_time) > 10) { |
|
|
|
g_lcd_rxbuf_isready=false; |
|
|
|
recv_lcd_data_time = hal_get_ticket(); |
|
|
|
send_cmd_to_lcd(lcd_rxbuff,lcd_count);//接收完成将数据发给电脑 |
|
|
|
lcd_count=0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void main() |
|
|
|
{ |
|
|
|
peripheral_config();//各种初始化包括ram清零 |
|
|
|
uint8_t record_last_time=0; |
|
|
|
while (1) |
|
|
|
{ |
|
|
|
debug_light_ctrl_process_in_main_loop();//闪灯效果 |
|
|
|
if(g_lcd_rxbuf_isready)//接收开始 |
|
|
|
{ |
|
|
|
record_last_time = judge_recv_lcd_data_finish_main(record_last_time); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|