📄 serial.c
字号:
/*----------------------------------------------------------------------------
* R T L F l a s h F i l e S y s t e m E x a m p l e
*----------------------------------------------------------------------------
* Name: SERIAL.C
* Purpose: Serial Input Output for STmicroelectronics STM32
* Rev.: V3.14
*----------------------------------------------------------------------------
* This code is part of the RealView Run-Time Library.
* Copyright (c) 2004-2007 KEIL - An ARM Company. All rights reserved.
*---------------------------------------------------------------------------*/
#include <stm32f10x_lib.h> /* STM32F10x Library Definitions */
/*----------------------------------------------------------------------------
* sendchar: Write a character to Serial Port
*---------------------------------------------------------------------------*/
int sendchar (int ch) {
if (ch == '\n') {
while (!(USART1->SR & USART_FLAG_TXE));
USART1->DR = '\r';
}
while (!(USART1->SR & USART_FLAG_TXE));
return (USART1->DR = (ch & 0x1FF));
}
/*----------------------------------------------------------------------------
* getkey: Read a character from Serial Port
*---------------------------------------------------------------------------*/
int getkey (void) {
while (!(USART1->SR & USART_FLAG_RXNE));
return ((int)(USART1->DR & 0x1FF));
}
/*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -