void USART_Configuration(void)
{
/* ¶¨Òå USART ³õʼ»¯½á¹¹Ìå USART_InitStructure */
USART_InitTypeDef USART_InitStructure;
/* ¶¨Òå USART ³õʼ»¯½á¹¹Ìå USART_ClockInitStructure */
USART_ClockInitTypeDef USART_ClockInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/*
* ²¨ÌØÂÊΪ115200bps;
* 8λÊý¾Ý³¤¶È;
* 1¸öֹͣ룬ÎÞУÑé;
* ½ûÓÃÓ²¼þÁ÷¿ØÖÆ;
* ½ûÖ¹USARTʱÖÓ;
* ʱÖÓ¼«ÐÔµÍ;
* ÔÚµÚ2¸ö±ßÑز¶»ñÊý¾Ý
* ×îºóһλÊý¾ÝµÄʱÖÓÂö³å²»´Ó SCLK Êä³ö£»
*/
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(USART1 , &USART_ClockInitStructure);
USART_InitStructure.USART_BaudRate = 115200;
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);
/* ʹÄÜ USART1 */
USART_Cmd(USART1 , ENABLE);
}
/*******************************************************************************
* º¯ÊýÃû : fputc
* º¯ÊýÃèÊö : ½«printfº¯ÊýÖض¨Î»µ½USATR1
* ÊäÈë²ÎÊý : ÎÞ
* Êä³ö½á¹û : ÎÞ
* ·µ»ØÖµ : ÎÞ
*******************************************************************************/
int fputc(int ch, FILE *f)
{
USART_SendData(USART1, (u8) ch);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
return ch;
}
不好意思,注释乱码了,代码是可以用的我已试过 |