新手入门
- 积分
- 38
- 金钱
- 38
- 注册时间
- 2015-9-25
- 在线时间
- 2 小时
|
5金钱
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* ?????®??1 ?¨USART1?© ?±??*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO| RCC_APB2Periph_GPIOB, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE);
/*?®??GPIO????????*/
/* ?????®??1 ?¨USART1 Tx (PA.09)?©*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* ?????®??1 USART1 Rx (PA.10)*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* ?®??1?¤×÷?????¨USART1 mode?©???? */
USART_InitStructure.USART_BaudRate = 9600;//??°??è????9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_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;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);//?????®??
}
/*
* ????????fputc
* ?è?? ?????¨?òc??????printf??USART1
* ???? ????
* ???? ????
* ?÷?? ????printf?÷??
*/
int fputc(int ch, FILE *f)
{
/* ??Printf????·??ù?®?? */
USART_SendData(USART1, (unsigned char) ch);
while( USART_GetFlagStatus(USART1,USART_FLAG_TC)!= SET);
return (ch);
}
|
|