This repository has been archived on 2024-12-31. You can view files and clone it, but cannot push or open issues or pull requests.
mfps/App/Src/app.c

107 lines
2.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "app.h"
//绿灯 NOR ;蓝灯 ERR
float X_ads1220 = 0; //读到的电压值
float X_ads1220_L = 15.0; //电压值上限
float X_ads1220_H = 1320.0; //电压值下限
float X_ads1220_prc = 0; //电压百分比(即位移百分比)
float TEMP_M1820 = 0; //温度
uint32_t move_step_5mm = 0x0000C800;
uint32_t move_step_1mm = 0x00002800;
char ocin1 = 0,ocin2 = 0; //位置开关远离为1接近为0
char oled_init_flag = 0,oled_init_result = 0;
//int i2c_error_temp = 0;
uint8_t magnet_tx[7] = {0x05,0x01,0x00,0x0A,0x00,0x0A,0xFF};
HAL_StatusTypeDef hal_check_tx;
void app_act (void)
{
//1 按键操作
// Key_Scan();//按键扫描(已放入定时器中断)
key_act(); //按键执行功能
//2 定时器
if(it_1000ms_flag == 1)
{
it_1000ms_flag = 0;
HAL_GPIO_WritePin(RS485_EN1_GPIO_Port,RS485_EN1_Pin,GPIO_PIN_SET); //使能485发送发送结束后在回调函数中拉低
hal_check_tx = HAL_UART_Transmit_IT(&huart2, magnet_tx ,7); //485发送
}
//3 串口通信测试
// uart_test();
//4 数据采集
if(it_100ms_flag)
{
it_100ms_flag = 0;
OLED_MenuTest(); //OLED显示,菜单
TEMP_M1820 = M1820_Get_Temp(); //温度采集
X_ads1220 = Xads1220_filter(20,80); //电阻尺滤波结果电压值mv
X_ads1220_prc =(X_ads1220 - X_ads1220_L)/(X_ads1220_H - X_ads1220_L);
// 串口计时
process_ttl_receive_timer();
}
//5 电阻尺 位移传感器
Xads1220_record();//采集数据用于滤波
//6 电机
// motor_protect_ocin();
Deal_Motor();
//7 串口数据处理
Deal_Uart_Data_For_Module();
motor_data[4] = rx_data2[1]; //磁条485
motor_data[5] = rx_data2[2];
motor_data[6] = rx_data2[3];
motor_data[7] = rx_data2[4];
motor_data[8] = ((uint16_t)(X_ads1220*10) & 0xff00)>> 8; //磁条长度高8位
motor_data[9] = (uint16_t)(X_ads1220*10) & 0x00ff; //磁条长度低8位
//8 位置开关
ocin1 = HAL_GPIO_ReadPin(OCIN1_GPIO_Port,OCIN1_Pin); //低电平接近,高电平远离
ocin2 = HAL_GPIO_ReadPin(OCIN2_GPIO_Port,OCIN2_Pin); //低电平接近,高电平远离
//9 LED灯状态指示
if( Motor_Run == 0 )
{
HAL_GPIO_WritePin(LED_NOR_GPIO_Port, LED_NOR_Pin, GPIO_PIN_SET);//停止状态两灯熄灭
HAL_GPIO_WritePin(LED_ERR_GPIO_Port, LED_ERR_Pin, GPIO_PIN_SET);
}
if( (Motor_Run == 1) && (motor_direc == 1) )
{
HAL_GPIO_WritePin(LED_NOR_GPIO_Port, LED_NOR_Pin, GPIO_PIN_RESET);//正向转动绿灯亮
HAL_GPIO_WritePin(LED_ERR_GPIO_Port, LED_ERR_Pin, GPIO_PIN_SET);
}
if( (Motor_Run == 1) && (motor_direc == 2) )
{
HAL_GPIO_WritePin(LED_NOR_GPIO_Port, LED_NOR_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED_ERR_GPIO_Port, LED_ERR_Pin, GPIO_PIN_RESET);//反向转动蓝灯亮
}
if( ( Motor_Run == 2 ) || ( Motor_Run == 3 ) )
{
HAL_GPIO_WritePin(LED_NOR_GPIO_Port, LED_NOR_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED_ERR_GPIO_Port, LED_ERR_Pin, GPIO_PIN_RESET);//复位移动时两灯亮
}
}