大家灵不丁一看这个题目觉得不可思异,宣传封建迷信地来啦!!!!其实不然。
我平时常听“单田芳”讲的评书,讲到岳飞之子岳挺会一种功夫叫这个名字。大至是两个人打着打着一个人找不到另一个啦,这时找人的那位就要归位了。其实那个人功夫高躲在他的背后而已。其实在这块开发板上也可以实现。
就是我发的什么单片机再发回来,如鬼影一般,我连发了几组一组都没有错。
以下是截图:
原理就是利用收中断,在收的同时发回去。发不中断。
其中断函数十分简单:
- void USART1_IRQHandler(void)
- {
- if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
- USART_SendData(USART1,USART_ReceiveData(USART1));
- }
复制代码主函数也不太难主要声明对相应的功能API函数,即可:
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
- /*???GPIOA??*/
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
- GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_1);
- GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_1);
- /* ??PA9 ,PA10*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //??????
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
-
- /*???USART1??*/
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
- USART_InitStructure.USART_BaudRate = 9600;//???????
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//?????
- USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;//??????
- USART_InitStructure.USART_Parity = USART_Parity_No;//?????
- USART_InitStructure.USART_StopBits = USART_StopBits_1;//?????
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;//?????
- USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
- USART_Init(USART1, &USART_InitStructure);
- USART_Cmd(USART1, ENABLE);//????
-
- /* Configure the NVIC Preemption Priority Bits */
- //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
- /* Enable the USART1 Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
- //NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- while (1)
- {
- /* Set PC8 and PC9 */
-
- }
复制代码
[
本帖最后由 ddllxxrr 于 2013-11-22 18:57 编辑 ]