📄 uart.c
字号:
#include "stm32f10x_lib.h"
/*******************************************************************************
* Function Name : USART_Configuration
* Description : Configures the USART1.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* Enable USARTx clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* USART1 configuration ----------------------------------------------------*/
/* USART1 configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Receive and transmit enabled
- Hardware flow control disabled (RTS and CTS signals)
*/
USART_InitStructure.USART_BaudRate = 9600;
// 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_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART1, &USART_InitStructure);
// 根据USART_InitStructure中指定的参数初始化外设USARTx寄存器
/* Enable USART1 Receive and Transmit interrupts */
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
/* Enable USART1 */
USART_Cmd(USART1, ENABLE);
}
/*******************************************************************************
* Function Name : SerialPutChar
* Description : Print a character on the HyperTerminal
* Input : - c: The character to be printed
* Output : None
* Return : None
*******************************************************************************/
void SerialPutChar(char c)
{
USART_SendData(USART1, c);
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
}
/*******************************************************************************
* Function Name : Serial_PutString
* Description : Print a string on the HyperTerminal
* Input : - s: The string to be printed
* Output : None
* Return : None
*******************************************************************************/
void Serial_PutString(u8 *s)
{
while (*s != '\0')
{
SerialPutChar(*s);
s ++;
}
}
/*unsigned char To_16jz(unsigned int ndata) //将ASCII码转换为16进制数
//0x64的ASCII码是54 52 其中6的ASCII是54,4的ASCII是52所以要将5452还原成0x64
{unsigned char ndata1,ndata2,ndata3;
ndata1=ndata&0X00FF;
if((ndata1>=0X30)&&(ndata1<=0X39))
ndata1=ndata1&0X0F;
else
if((ndata1>=0X41)&&(ndata1<=0X46))
ndata1=ndata1-0X41+0X0A;
ndata2=(ndata&0XFF00)>>8;
if((ndata2>=0X30)&&(ndata2<=0X39))
ndata2=ndata2&0X0F;
else
if((ndata2>=0X41)&&(ndata2<=0X46))
ndata2=ndata2-0X41+0X0A;
ndata3=(ndata2<<4)|ndata1;
return(ndata3);
} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -