[mw_shl_code=c,true]/*******************************************************************************
*******************************************************************************/
void USART1_Init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* config USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
/* USART1 GPIO config */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* USART1 mode config */
USART_InitStructure.USART_BaudRate = bound;
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);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; //????2??
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //?????2?
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //????2?
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //????????
NVIC_Init(&NVIC_InitStructure); //??NVIC_InitStruct???????????NVIC???
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //????
USART_Cmd(USART1, ENABLE);
}
/*******************************************************************************
*******************************************************************************/
void Usart_SendString(USART_TypeDef *USARTx, unsigned char *str, unsigned short len)
{
unsigned char *s=str;
unsigned short count = 0;
for(; count < len; count++)
{
USART_SendData(USARTx, *(s++));
while(USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET);
delay_us(2);
}
}
/*******************************************************************************
*******************************************************************************/
void USART1_XmtChar(unsigned char c)
{
USART_SendData(USART1, c);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
;
}
/*******************************************************************************
*******************************************************************************/
void USART1_XmtStr(unsigned char *str)
{
unsigned char *s=str;
while(*s!=' ')
{
USART1_XmtChar(*(s++));
}
}
/*******************************************************************************
*******************************************************************************/
void USART1_SendData(u8 *buf,u8 len)
{
u8 t;
for(t=0;t<len;t++) //Ñ-»··¢Ëíêy¾Y
{
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
USART_SendData(USART1,buf[t]);
}
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
}[/mw_shl_code]
主函数:
[mw_shl_code=c,true]
unsigned char ww[]="01234
";
int main(void)
{
delay_init(); //Ñóê±oˉêy3õê¼»ˉ
NVIC_Configuration(); //éèÖÃNVICÖD¶Ï·Ö×é2:2λÇàÕ¼óÅÏ輶£¬2λÏìó|óÅÏ輶
USART1_Init(9600);
// M6311_Init();
while(1)
{
USART1_XmtStr(ww);
Usart_SendString(USART1,ww,7);
USART1_SendData(ww,7);
}
}[/mw_shl_code]
有什么不对的?????三个发送函数发的字符完全不一样,且没有一个正确
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
我把库文件全部删了又去下的库文件,添加进去,就好了。
一周热门 更多>