| 大神们    帮忙看看   求指教!!!!!!!!!
[mw_shl_code=c,true]#include"stm32f10x.h"
#define LED2ON GPIO_ResetBits(GPIOE,GPIO_Pin_5)
#define LED3ON GPIO_ResetBits(GPIOB,GPIO_Pin_5)
u16 num;
int  RXD,TXD;
static __IO uint32_t TimingDelay;
void Delay(__IO uint32_t nTime);
void Systick_Init()
{
  if (SysTick_Config(SystemCoreClock / 1000))
  { 
    while (1);
  }
}
void GPIO_INIT()
{
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
	
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
	
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
	
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);[/mw_shl_code]
[mw_shl_code=c,true]GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; [/mw_shl_code]
[mw_shl_code=c,true]  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOE, &GPIO_InitStructure);
}
void USART_INIT()
{
  USART_InitTypeDef USART_InitStructure;
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);//USART2?±??APB1
  USART_DeInit(USART2);
  USART_InitStructure.USART_BaudRate = 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(USART2,&USART_InitStructure);
  USART_Cmd(USART2,ENABLE);
  USART_ITConfig(USART2, USART_IT_TXE, ENABLE);  
  USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);  
}
void NVIC_INIT()
{
  NVIC_InitTypeDef NVIC_InitStructure;
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
  NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}
int main()
{
	Systick_Init();
	GPIO_INIT();
	USART_INIT();
        NVIC_INIT();
	while(1)
	{
		  if(RXD==1)
			{
				 switch(num)
				 {
					case 0  ED2ON;break;
					case 1  ED3ON;break;	
                                        default:break;					 
                                  }
				 RXD=0;
				 USART_ClearFlag(USART2,USART_FLAG_RXNE);
                        }
            }
}
void Delay(__IO uint32_t nTime)
{ 
  TimingDelay = nTime;
  while(TimingDelay != 0);
}
void TimingDelay_Decrement(void)
{
  if (TimingDelay != 0x00)
  { 
    TimingDelay--;
  }
}
void USART2_IRQHandler(void)  
{  
   
  if (USART_GetITStatus(USART2, USART_IT_TXE) != RESET) // Transmit the string in a loop  
  { 
    USART_ClearFlag(USART2,USART_FLAG_TXE);	
    TXD=1;		      
  }  
   
  if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) // Received characters modify string  
  {  	
    RXD=1;		
    num = USART_ReceiveData(USART2);  
  }  
}
[/mw_shl_code]
 |