uart0.c

来自「一个AT91SAM7X256 USART驱动实验」· C语言 代码 · 共 53 行

C
53
字号
//*----------------------------------------------------------------------------
//*         ATMEL Microcontroller Software Support  -  ROUSSET  -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name           : uart0.c
//* Object              : uart0 routines written in C
//* Creation            : JG   16/Aug/2004
//*----------------------------------------------------------------------------

// Include Standard files
#include "Board.h"


#define AT91_BAUD_RATE          115200

#define AT91B_MAIN_OSC          18432000                // Main Oscillator
#define AT91B_MCK               ((18432000*73/14)/2)    // Output PLL Clock


//*----------------------------------------------------------------------------
//* Object              : USART initialization
//* Input Parameters    : none.
//* Output Parameters   : none.
//*----------------------------------------------------------------------------
void Init_Uart0(void)
{
	AT91PS_USART COM0 = AT91C_BASE_US0;

	//* Configure PIO controllers to periph mode
 	AT91F_PIO_CfgPeriph( AT91C_BASE_PIOA,
		 ((unsigned int) AT91C_PA0_RXD0) |
		 ((unsigned int) AT91C_PA1_TXD0) |
		 ((unsigned int) AT91C_PA3_RTS0) |
		 ((unsigned int) AT91C_PA4_CTS0),
		 0);

	//* First, enable the clock of the USART
	AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC, 1<<AT91C_ID_US0);

	//* Usart Configure
	AT91F_US_Configure(COM0, AT91B_MCK, AT91C_US_ASYNC_MODE, AT91_BAUD_RATE, 0);

	//* Enable usart
	COM0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
}


⌨️ 快捷键说明

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