uart.c

来自「老外写得最新arm 库很多值得学习的基于mcu得c函数写法」· C语言 代码 · 共 52 行

C
52
字号
/*! \file uart.c \brief UART driver for ARM ADuC7000 16450. */
//*****************************************************************************
//
// File Name	: 'uart.c'
// Title		: UART driver for ARM ADuC7000 16450
// Author		: Pascal Stang - Copyright (C) 2005
// Created		: 2/5/2005
// Revised		: 2/5/2005
// Version		: 0.1
// Target MCU	: Analog Devices ARM ADuC7000 Series
// Editor Tabs	: 4
//
// This code is distributed under the GNU Public License
//		which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************

#include "aduc7026.h"

#include "global.h"
#include "uart.h"

//! enable and initialize the uart
void uartInit(uint16_t baud, uint32_t mode)
{
	// set port pins for UART
	GP1CON = 0x11;

	COMCON0 = 0x80;
//	COMDIV0 = 0x0C;
	COMDIV0 = 0x0B;
	COMDIV1 = 0x00;
	COMCON0 = 0x07;
}

int uartSendByte(int data)
{
	while(!(COMSTA0 & 0x20))		// wait for TX buffer to empty
		continue;					// also either WDOG() or swap()

	COMTX = (uint8_t)data;
	return (uint8_t)data;
}

int uartGetByte(void)
{
	if(COMSTA0 & 0x01)				// check if character is available
		return COMRX;				// return character
	return -1;
}

⌨️ 快捷键说明

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