You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
223 lines
6.7 KiB
223 lines
6.7 KiB
/**
|
|
* @file lcd.c
|
|
* @author 1722451300@qq.com
|
|
* @brief
|
|
* @version 0.1
|
|
* @date 2021-12-15
|
|
*
|
|
* @copyright Copyright (c) 2021
|
|
*
|
|
*/
|
|
#include "lcd.h"
|
|
volatile char lcd_rxbuff[50] = {0};
|
|
volatile int32_t lcd_count = 0;
|
|
//volatile int32_t recv_lcd_data_state=0;//1就判断是不是接收完成,0不判断
|
|
//volatile int32_t from_lcd_recv_state = 0;
|
|
//volatile int32_t lcd_t8_state = 0;
|
|
extern volatile int32_t first_set_motor_speed_dsp;
|
|
volatile int32_t lcd_issue_motor_speed=0;
|
|
volatile int16_t judge_now_foreward_or_reversal_state=0;//正转0,反转1
|
|
volatile int32_t first_set_speed_state=0;
|
|
extern volatile int32_t speed_dsp_now;//当前电机的速度单位dsp
|
|
extern volatile int32_t motor_jerk_state;//1电机处于急停状态
|
|
|
|
//-----------------------------------------
|
|
//-----------------------------------------
|
|
|
|
|
|
void lcd_uart_config(void)
|
|
{
|
|
/**
|
|
* @brief LCD的芯片与上位机的通信 Pro2303LCD段
|
|
*
|
|
*/
|
|
uart1_config();
|
|
}
|
|
|
|
void send_cmd_to_lcd(volatile char buff[20], unsigned int num)
|
|
{
|
|
/**
|
|
* @brief 向LCD发送11命令
|
|
*
|
|
*/
|
|
while (num--)
|
|
{
|
|
while (!TRMT1)
|
|
;
|
|
TX1B = *buff;
|
|
buff++;
|
|
}
|
|
}
|
|
//---------------------------------------
|
|
//---------------------------------------
|
|
uint8_t g_lcd_rxbuf_isready = 0;
|
|
uint32_t g_process_recv_lcd_data_time = 0;
|
|
void recv_from_lcd_data(unsigned char data)
|
|
{
|
|
/**
|
|
* @brief 接收来自lcd的数据
|
|
*
|
|
*/
|
|
g_lcd_rxbuf_isready=true;//进入中断就让他为真
|
|
lcd_rxbuff[lcd_count++] = data;
|
|
g_process_recv_lcd_data_time= hal_get_irqticket();//记录最后的时间
|
|
}
|
|
|
|
uint32_t judge_recv_lcd_data_finish(uint32_t time)
|
|
{
|
|
/**
|
|
* @brief 接收LCD的数据完成
|
|
*/
|
|
static uint32_t recv_lcd_data_time = 0;
|
|
recv_lcd_data_time = time;
|
|
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;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @brief 对来自lcd的指令进行分析
|
|
* @param buff 指令,num 指令的字节长度
|
|
*
|
|
*/
|
|
uint8_t lcd_data_analyse(volatile char buff[20], unsigned int num)
|
|
{
|
|
volatile char str[2]={0};
|
|
volatile int32_t speed=0;
|
|
if(buff[0]!=0x5A || buff[1]!=0xA5)
|
|
{
|
|
return -1;
|
|
}
|
|
if(buff[3]==0x83)//如果是就代表着指令要发送给电机控制电机的状态
|
|
{
|
|
|
|
if(buff[4]==0x50&&buff[5]==0x20)//速度指令(包括+-设置停止四种方法)
|
|
{
|
|
lcd_issue_motor_speed = buff[7]<<8|buff[8];
|
|
lcd_issue_motor_speed = lcd_issue_motor_speed*6;//这个是最终lcd下发的电机速度单位dsp
|
|
if(first_set_speed_state==0)//第一次是进行速度的设定不需要向电机下发
|
|
{
|
|
first_set_motor_speed_dsp = lcd_issue_motor_speed;
|
|
first_set_speed_state=1;
|
|
lcd_issue_motor_speed=0;
|
|
}
|
|
else
|
|
{
|
|
lcd_issue_motor_speed = judge_foreward_or_reversal(lcd_issue_motor_speed,judge_now_foreward_or_reversal_state);//判断正转还是反转
|
|
}
|
|
}
|
|
else if(buff[4]==0x50&&buff[5]==0x00)//正转命令
|
|
{
|
|
judge_now_foreward_or_reversal_state=0;
|
|
lcd_issue_motor_speed = judge_foreward_or_reversal(first_set_motor_speed_dsp,0);//判断正转还是反转lcd_issue_motor_speed单位dsp
|
|
}
|
|
else if(buff[4]==0x50&&buff[5]==0x10)//反转命令
|
|
{
|
|
judge_now_foreward_or_reversal_state=1;
|
|
lcd_issue_motor_speed = judge_foreward_or_reversal(first_set_motor_speed_dsp,1);//判断正转还是反转
|
|
//set_motor_speed(lcd_issue_motor_speed);
|
|
}
|
|
}
|
|
else return -1;
|
|
}
|
|
|
|
void lcd_switch_anomaly_page(void)
|
|
{
|
|
/**
|
|
* @brief 电机处于异常时屏幕切换到异常界面,不可点击确定按键
|
|
* 5A A5 07 82 00 84 5A 01 00 01
|
|
*/
|
|
unsigned char anomaly_page_send_lcd_cmd[10]={0};
|
|
anomaly_page_send_lcd_cmd[0]=0x5A;
|
|
anomaly_page_send_lcd_cmd[1]=0xA5;
|
|
anomaly_page_send_lcd_cmd[2]=0x07;
|
|
anomaly_page_send_lcd_cmd[3]=0x82;
|
|
anomaly_page_send_lcd_cmd[4]=0x00;
|
|
anomaly_page_send_lcd_cmd[5]=0x84;
|
|
anomaly_page_send_lcd_cmd[6]=0x5A;
|
|
anomaly_page_send_lcd_cmd[7]=0x01;
|
|
anomaly_page_send_lcd_cmd[8]=0x00;
|
|
anomaly_page_send_lcd_cmd[9]=0x08;
|
|
send_cmd_to_lcd(anomaly_page_send_lcd_cmd,10);
|
|
}
|
|
|
|
void lcd_switch_anomaly_page_key(void)
|
|
{
|
|
/**
|
|
* @brief 电机处于异常时屏幕切换到异常界面,可点击确定按键
|
|
* 5A A5 07 82 00 84 5A 01 00 01
|
|
*/
|
|
unsigned char anomaly_page_send_lcd_cmd[10]={0};
|
|
anomaly_page_send_lcd_cmd[0]=0x5A;
|
|
anomaly_page_send_lcd_cmd[1]=0xA5;
|
|
anomaly_page_send_lcd_cmd[2]=0x07;
|
|
anomaly_page_send_lcd_cmd[3]=0x82;
|
|
anomaly_page_send_lcd_cmd[4]=0x00;
|
|
anomaly_page_send_lcd_cmd[5]=0x84;
|
|
anomaly_page_send_lcd_cmd[6]=0x5A;
|
|
anomaly_page_send_lcd_cmd[7]=0x01;
|
|
anomaly_page_send_lcd_cmd[8]=0x00;
|
|
anomaly_page_send_lcd_cmd[9]=0x07;
|
|
send_cmd_to_lcd(anomaly_page_send_lcd_cmd,10);
|
|
}
|
|
|
|
|
|
void lcd_actual_speed_set(int32_t now_speed)
|
|
{
|
|
/**
|
|
* @brief 设置屏幕上实际速度值
|
|
* 5A A5 05 82 50 90 00 64
|
|
*/
|
|
volatile unsigned char lcd_show_now_motor_speed[10]={0};
|
|
now_speed = now_speed/6;
|
|
lcd_show_now_motor_speed[0]=0x5A;
|
|
lcd_show_now_motor_speed[1]=0xA5;
|
|
lcd_show_now_motor_speed[2]=0x05;
|
|
lcd_show_now_motor_speed[3]=0x82;
|
|
lcd_show_now_motor_speed[4]=0x50;
|
|
lcd_show_now_motor_speed[5]=0x90;
|
|
//速度具体值
|
|
lcd_show_now_motor_speed[6]=(now_speed>>8)&0xff;//速度高字节
|
|
lcd_show_now_motor_speed[7]=now_speed&0xff;//速度低字节
|
|
send_cmd_to_lcd(lcd_show_now_motor_speed,8);
|
|
}
|
|
|
|
void lcd_speed_set_val(int32_t now_speed)
|
|
{
|
|
/**
|
|
* @brief 设置屏幕上速度设定值
|
|
* 5A A5 05 82 50 20 00 00
|
|
*/
|
|
unsigned char lcd_show_now_motor_speed[10]={0};
|
|
lcd_show_now_motor_speed[0]=0x5A;
|
|
lcd_show_now_motor_speed[1]=0xA5;
|
|
lcd_show_now_motor_speed[2]=0x05;
|
|
lcd_show_now_motor_speed[3]=0x82;
|
|
lcd_show_now_motor_speed[4]=0x50;
|
|
lcd_show_now_motor_speed[5]=0x20;
|
|
//速度具体值
|
|
lcd_show_now_motor_speed[6]=0x00;//速度高字节
|
|
lcd_show_now_motor_speed[7]=0x00;//速度低字节
|
|
send_cmd_to_lcd(lcd_show_now_motor_speed,8);
|
|
}
|
|
|
|
void clear_zero(void)
|
|
{
|
|
/**
|
|
* @brief 发生异常的时候清零
|
|
*
|
|
*/
|
|
lcd_actual_speed_set(0);
|
|
lcd_speed_set_val(0);
|
|
judge_now_foreward_or_reversal_state=0;
|
|
first_set_motor_speed_dsp=0;
|
|
lcd_issue_motor_speed=0;
|
|
}
|
|
|
|
|