main.c

来自「基于STM32串口-CAN函数包.其中,串口以中断形式接受,C」· C语言 代码 · 共 61 行

C
61
字号
#include<stm32f10x_lib.h>
#include<stdio.h>
//申明调用外部函数
extern void SetupClock  (void);
extern void SetupUART   (void);
extern int GetKey (void) ;
extern int SendChar (int ch) ;
//申明内部函数
void NVIC_Configuration(void);

void Init(void) ;


int receved_code=0;
main()			 
{Init();
 printf("how are you!!\nwelecome !");
 while (1)
   {receved_code=GetKey();
 
   if(receved_code==0x05)
   		printf("yes,have receved!\n");
	else
	   ;
   }
}
  void Init(void)
   {SetupClock();
    NVIC_Configuration();
    SetupUART();
   }


   /*******************************************************************************
   * Function Name	: NVIC_Configuration
   * Description	: Configures the nested vectored interrupt controller.
   * Input			: None
   * Output 		: None
   * Return 		: None
   *******************************************************************************/
   void NVIC_Configuration(void)
   {
  NVIC_InitTypeDef NVIC_InitStructure;

#ifdef  VECT_TAB_RAM  
  /* Set the Vector Table base location at 0x20000000 */ 
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); 
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */ 
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
#endif

  /* Enable the USART1 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?