/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/*LED管脚初始化*/
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_GPIO_LED, ENABLE);
GPIO_InitStructure.GPIO_Pin = DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_LED, &GPIO_InitStructure);
GPIO_SetBits(GPIO_LED, DS1_PIN|DS2_PIN|DS3_PIN|DS4_PIN); /*关闭LED灯*/
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
/*串口参数配置*/
USART_InitStructure.USART_BaudRate = 115200; /*设置波特率为115200*/
USART_InitStructure.USART_WordLength = USART_WordLength_8b; /*设置数据位为8位*/
USART_InitStructure.USART_StopBits = USART_StopBits_1; /*设置停止位为1位*/
USART_InitStructure.USART_Parity = USART_Parity_No; /*无奇偶校验*/
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; /*没有硬件流控*/
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /*发送与接收*/
/*完成串口COM1的时钟配置、GPIO配置,根据上述参数初始化并使能*/
//STM_EVAL_COMInit(COM1, &USART_InitStructure);
STM_EVAL_COMInit(COM2, &USART_InitStructure);
printf("\n\r---------------------------------------------\n ");
printf("\n\rWWW.ARMJISHU.COM\n ");
//printf("\n\r神舟III号 串口1发送实验程序\n");
printf("\n\r神舟III号 串口2发送实验程序\n");
while (1)
{
GPIO_ResetBits(GPIO_LED, DS1_PIN);
Delay(0x3FFFFF);
GPIO_SetBits(GPIO_LED, DS1_PIN);
Delay(0x3FFFFF);
//printf("\n\r神舟III号 串口1测试程序\n");
printf("\n\r神舟III号 串口2测试程序\n");
}
}
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
//USART_SendData(EVAL_COM1, (uint8_t) ch); /*发送一个字符函数*/
USART_SendData(EVAL_COM2, (uint8_t) ch); /*发送一个字符函数*/
/* Loop until the end of transmission */
//while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)/*等待发送完成*/
while (USART_GetFlagStatus(EVAL_COM2, USART_FLAG_TC) == RESET)/*等待发送完成*/
{
}
return ch;
}
神舟III号 串口2发送实验程序
最新推荐文章于 2021-12-17 08:30:00 发布