我的 代码:
#include "stm32f10x.h"
#include "stdio.h"
#include "usartself.h"
// #if 1
// #pragma import(__use_no_semihosting)
// //±ê×????è?????§??????
// struct __FILE
// {
// int handle;
// };
// FILE __stdout;
// //?¨??_sys_exit()??±???????°??÷?ú????
// _sys_exit(int x)
// {
// x = x;
// }
// //???¨??fputc????
// int fputc(int ch, FILE *f)
// {
// while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
// USART_SendData(USART2,(uint8_t)ch);
// return ch;
// }
// #endif
// void Usart_Initial();
// void Delay(u8);
// int main()
// {
// Usart_Initial();
// while(1)
// {
//
// // USART_SendData (USART1 ,z);
// // while(USART_GetFlagStatus (USART1 , USART_FLAG_TXE )==RESET );
// // if(USART_GetFlagStatus (USART1 , USART_FLAG_RXNE )== SET )
// // {
// // z=USART_ReceiveData (USART1 );
// // }
//
// printf("i love you");
// }
// }
// void Delay(u8 time)
// {
// u8 i,j;
// for(i=0;i<100;i++)
// for(j=0;j<time;j++);
// }
void Usart_Initial()
{
//******GPIO Initial****
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
//***********RCC Initial
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOD |RCC_APB2Periph_AFIO ,ENABLE );
RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART2 , ENABLE );
//******USART 1***
GPIO_PinRemapConfig (GPIO_Remap_USART2 , ENABLE);
GPIO_InitStructure .GPIO_Mode = GPIO_Mode_AF_PP ;
GPIO_InitStructure .GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure .GPIO_Speed = GPIO_Speed_50MHz ;
GPIO_Init (GPIOD , &GPIO_InitStructure );
GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IN_FLOATING ;
GPIO_InitStructure .GPIO_Pin = GPIO_Pin_6;
GPIO_Init (GPIOD , &GPIO_InitStructure );
//**********USART Initail
USART_InitStructure .USART_BaudRate = 9600;
USART_InitStructure .USART_HardwareFlowControl = USART_HardwareFlowControl_None ;
USART_InitStructure .USART_Mode = USART_Mode_Rx |USART_Mode_Tx ;
USART_InitStructure .USART_Parity = USART_Parity_No ;
USART_InitStructure .USART_StopBits = USART_StopBits_1 ;
USART_InitStructure .USART_WordLength = USART_WordLength_8b ;
USART_Init (USART2 ,&USART_InitStructure );
USART_ITConfig (USART2,USART_IT_RXNE ,ENABLE );
USART_Cmd (USART2 , ENABLE );
}
这个是.h文件
#ifndef _USARTSELF_H_
#define _USARTSELF_H_
void Usart_Initial();
#endif
|