#include "stm32f10x.h"
#include "stm32f10x_usart.h"
#include "SysTickDelay.h"
void GPIO_config(void);
void USART_config(void);
unsigned char txbuf1[50] = "******************************************\r\n";
unsigned char txbuf2[50] = "* 感谢您使用芯达STM32开发板!^_^ *\r\n";
unsigned char txbuf3[50] = "\r\n Please input any word :\r\n ";
unsigned char txbuf4[50] = "* *\r\n";
int main(void)
{
int i,tempstate=0;
GPIO_config();
USART_config();
SysTick_Initaize();
for(i=0;txbuf1[i]!='\0';i++)
{
USART_SendData(USART1, txbuf1[i]);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
} //一行星号
for(i=0;txbuf1[i]!='\0';i++)
{
USART_SendData(USART1, txbuf1[i]);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
} //再一行星号
for(i=0;txbuf4[i]!='\0';i++)
{
USART_SendData(USART1, txbuf4[i]);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
} //头尾只有一个星号
for(i=0;txbuf2[i]!='\0';i++)
{
USART_SendData(USART1, txbuf2[i]);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
} //一行字符
for(i=0;txbuf4[i]!='\0';i++)
{
USART_SendData(USART1, txbuf4[i]);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
} //头尾只有一个星号
for(i=0;txbuf1[i]!='\0';i++)
{
USART_SendData(USART1, txbuf1[i]);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
} //一行星号
for(i=0;txbuf1[i]!='\0';i++)
{
USART_SendData(USART1, txbuf1[i]);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
} //一行星号
for(i=0;txbuf3[i]!='\0';i++)
{
USART_SendData(USART1, txbuf3[i]);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
} //输入字符
while(1)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1);
delay_ms(1000);
tempstate = USART_GetFlagStatus(USART1, USART_FLAG_RXNE);
if(tempstate==SET)
{
USART_SendData(USART1, USART_ReceiveData(USART1));
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
delay_ms(1000);
}
}
}
void GPIO_config()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //usart1发送数据引脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //usart1接收数据引脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //LED
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void USART_config()
{
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
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_Tx | USART_Mode_Rx;
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
USART_Cmd(USART1, ENABLE);
}
利用软件调试时,程序一直在while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);不出来了,请各位高手看一下是不是配置有什么问题啊!!!我就是仿照一个例程来写的试一下,看看能不能输出,结果悲剧啊!!! |