⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serial.c

📁 RT-Thread是发展中的下一代微内核嵌入式实时操作系统
💻 C
字号:
/* * File      : serial.c * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2006, RT-Thread Development Team * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://openlab.rt-thread.com/license/LICENSE * * Change Logs: * Date           Author       Notes * 2006-03-13     Bernard      first version */#include <rtthread.h>#include <rthw.h>#include "s3c4510.h"#define	USTAT_RCV_READY         0x20   /* receive data ready */ #define	USTAT_TXB_EMPTY         0x40   /* tx buffer empty */void rt_serial_init(void);/** * @addtogroup S3C4510 *//*@{*//** * This function is used to display a string on console, normally, it's  * invoked by rt_kprintf * * @param str the displayed string */void rt_console_puts(const char* str){	while (*str) 	{		rt_serial_putc (*str++);	}}/** * This function initializes serial */void rt_serial_init(){	rt_uint32_t divisor = 0;	divisor = 0x500; /* 19200 baudrate, 50MHz */	UARTLCON0 = 0x03;	UARTCONT0 = 0x09;	UARTBRD0  = divisor;	UARTLCON1 = 0x03;	UARTCONT1 = 0x09;	UARTBRD1  = divisor;	for(divisor=0; divisor<100; divisor++);}/** * This function read a character from serial without interrupt enable mode  * * @return the read char */char rt_serial_getc(){	while ((UARTSTAT0 & USTAT_RCV_READY) == 0);	return UARTRXB0;}/** * This function will write a character to serial without interrupt enable mode * * @param c the char to write */void rt_serial_putc(const char c){	/*		to be polite with serial console add a line feed		to the carriage return character	*/	if (c=='\n')rt_serial_putc('\r');	/* wait for room in the transmit FIFO */	while(!(UARTSTAT0 & USTAT_TXB_EMPTY));	UARTTXH0 = (rt_uint8_t)c;}/*@}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -