******************************************************************************
* @file Project/STM32F10x_StdPeriph_Template/main.c
* @author
* @version V1.0.0T
* @date 11-February-2014
* @brief Main program body
******************************************************************************
* GPIO Test 2014-02-11 0k
*
******************************************************************************
*//* Includes ------------------------------------------------------------------*/GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_10 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // 一定要设定速度
GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB
| RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD
| RCC_APB2Periph_GPIOE, ENABLE );
}GPIO_Configuration();
}for(; nCount != 0; nCount--);
}配置UART的GPIO口
* Input: NoneGPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // 一定要配置速度
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Configure USART1_Rx as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);}配置串口参数
* Input: NoneUSART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600; //- BaudRate = 9600 baudUSART_InitStructure.USART_WordLength = USART_WordLength_8b; //- Word Length = 8 Bits
USART_InitStructure.USART_StopBits = USART_StopBits_1; //- One Stop Bit
USART_InitStructure.USART_Parity = USART_Parity_No ; //- No parity
//- Hardware flow control disabled (RTS and CTS signals)
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;// - Receive and transmit enabled
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* Configure the USART1*/
USART_Init(USART1, &USART_InitStructure);
/* Enable USART1 Receive and Transmit interrupts */
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
/* Enable the USART1 */
USART_Cmd(USART1, ENABLE);}: Uart1_PutChar 发送一个字节
* Deion: printf a char to the uart.
* Input: None
* Output: None
* Return: None
*******************************************************************************//* Write a character to the USART */
USART_SendData(USART1, (u8) ch);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
{
}
return ch;
}: Uart1_PutString 发送一个字符串
* Deion: print a string to the uart1
* Input: buf为发送数据的地址 , len为发送字符的个数
* Output: None
* Return: None
*******************************************************************************/for(u8 i=0;i<len;i++)
{
Uart1_PutChar(*buf++);
}
}RCC_Configuration();
GPIO_Configuration();
USART_Configuration(); USART_SendData(USART1,str[0]);while(1)
{
//GPIO_SetBits(GPIOA, GPIO_Pin_2); //GPIO_ResetBits(GPIOA, GPIO_Pin_3); //GPIO TEST/*
GPIO_SetBits(GPIOA, GPIO_Pin_9); GPIO_ResetBits(GPIOA, GPIO_Pin_10); //GPIO TEST Delay(100); GPIO_SetBits(GPIOA, GPIO_Pin_10); GPIO_ResetBits(GPIOA, GPIO_Pin_9); //GPIO TESTDelay(100);
*/ //Uart1_PutString("abce", 4);} //while(1)
}
没有发表任何评论