95 lines
2.4 KiB
C
95 lines
2.4 KiB
C
#include "serial_port.h"
|
||
#include "main.h"
|
||
#include "usart.h"
|
||
#include "string.h"
|
||
#include "app.h"
|
||
|
||
// HAL_UART_Transmit( &huartx, &data, timeout )//不带中断,不连续传输
|
||
// HAL_UART_Receive( &huartx, &data, timeout )
|
||
// HAL_UART_Transmit_IT( &huartx, &data, data_size )//带中断,连续传输
|
||
// HAL_UART_Receive_IT( &huartx, &data, data_size )
|
||
|
||
// HAL_SPI_Transmit( &hspix, &data, data_size,timeout )//不带中断,不连续传输
|
||
// HAL_SPI_Receive( &hspix, &data, data_size,timeout )
|
||
// HAL_SPI_Transmit_IT( &hspix, &data, data_size )//带中断,连续传输
|
||
// HAL_SPI_Receive_IT( &hspix, &data, data_size )
|
||
|
||
|
||
|
||
// 使用LP-300-SP的Type-A接口与计算机进行通信
|
||
|
||
char text_r[20] = "empty ";
|
||
char text_t[20] = "empty";
|
||
int text_s = 0;
|
||
|
||
//单片机与PC进行通信
|
||
//void Tx_RX_UART1(void)
|
||
//{
|
||
///***********************单片机状态0******************************/
|
||
// if( text_s == 0 )
|
||
// {
|
||
// if( it_1000ms_flag == 1)//0状态下每隔1秒发送一次当前的text_t
|
||
// {
|
||
// it_1000ms_flag = 0;
|
||
// HAL_UART_Transmit_IT( &huart1, (uint8_t*)text_t, 20);
|
||
//
|
||
// }
|
||
// HAL_UART_Receive_IT( &huart1,(uint8_t*)text_r,20);//读
|
||
// if( strncmp( (char*)text_r ,"start", 20 ) == 0 )//收到PC的start信号后,向PC发送"How are you"
|
||
// {
|
||
// text_s = 1;//单片机状态转为1
|
||
//
|
||
// strcpy((char*)text_t," How are you?");
|
||
// HAL_UART_Transmit_IT( &huart1, (uint8_t*)text_t, 20);
|
||
// }
|
||
//
|
||
//
|
||
// }
|
||
///***********************单片机状态0******************************/
|
||
//
|
||
//
|
||
///***********************单片机状态1******************************/
|
||
// if( text_s == 1 )
|
||
// {
|
||
// HAL_UART_Receive_IT( &huart1,(uint8_t*)text_r,20);//读
|
||
//
|
||
// if( strncmp( (char*)text_r ,"3Q", 20 ) == 0 )//收到3Q回复You are welcome
|
||
// {
|
||
// strcpy((char*)text_t,"You are welcome");
|
||
// HAL_UART_Transmit_IT( &huart1, (uint8_t*)text_t, 20);
|
||
//
|
||
// }
|
||
//
|
||
// if( strncmp( (char*)text_r ,"end", 20 ) == 0 )//收到PC的end信号后,向PC发送"See you again"
|
||
// {
|
||
// strcpy((char*)text_t,"See you again");
|
||
// HAL_UART_Transmit_IT( &huart1, (uint8_t*)text_t, 20);
|
||
//
|
||
// if( it_1000ms_flag ==1 )//等待1秒后单片机状态转为0
|
||
// {
|
||
// it_1000ms_flag = 0;
|
||
// text_s = 0;
|
||
// }
|
||
// }
|
||
// }
|
||
///***********************单片机状态1******************************/
|
||
//}
|
||
|
||
|
||
void uart_test(void)
|
||
{
|
||
|
||
if( it_1000ms_flag == 1)
|
||
{
|
||
it_1000ms_flag = 0;
|
||
|
||
//HAL_UART_Receive_IT( &huart1, (uint8_t*)text_r, 20);
|
||
|
||
//HAL_UART_Transmit_IT( &huart1, (uint8_t*)text_r, 20);
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|