创建一个main.c 编入:
#include "stm32f10x.h"
#include "delay.h"
#include "led.h"
#include "USART.h"
#include "stdio.h"
int main(void)
{
LED_Init();
Delay_Init();
USART1_Init();
while(1)
{
printf("hello");
//USART_SendData(USART1,'a');
DelayXms(500);
}
}
创建一个usart.c 编入:
#include "stm32f10x.h"
#include "usart.h"
#include "delay.h"
void USART1_Init(void)
{
GPIO_InitTypeDef ABC;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOE,ENABLE);
USART_DeInit(USART1);
ABC.GPIO_Pin=GPIO_Pin_9; //PA0 WAKE UP
ABC.GPIO_Mode=GPIO_Mode_AF_PP;
ABC.GPIO_Speed=GPIO_Speed_50MHz;
ABC.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &ABC);
USART_InitTypeDef USART_InitStructure;
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);
USART_Cmd(USART1,ENABLE);
}
创建一个usart.h 编入:
#ifndef _USART_H_
#define _USART_H_
void USART1_Init(void);
#endif