serial.c
来自「STM32F103 SD卡控制程序」· C语言 代码 · 共 39 行
C
39 行
/*----------------------------------------------------------------------------
* 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 + =
减小字号Ctrl + -
显示快捷键?