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

📄 uart.h.bak

📁 code keil for PC16552D
💻 BAK
字号:
#ifndef __UART_H
#define __UART_H

#define CS1 0x81000000;
#define CS2 0x82000000;
#define CS3 0x83000000;

/* Universal Asynchronous Receiver Transmitter 3 (UART3) */
#define U3RBR           (*((volatile unsigned char *) 0x81000080))
#define U3THR           (*((volatile unsigned char *) 0x81000080))
#define U3IER           (*((volatile unsigned long *) 0x81000084))
#define U3IIR           (*((volatile unsigned long *) 0x81000088))
#define U3FCR           (*((volatile unsigned char *) 0x81000088))
#define U3LCR           (*((volatile unsigned char *) 0x8100009C))
#define U3MCR           (*((volatile unsigned char *) 0x81000090))
#define U3LSR           (*((volatile unsigned char *) 0x81000094))
#define U3MSR           (*((volatile unsigned char *) 0x81000098))
#define U3SCR           (*((volatile unsigned char *) 0x8100008C))
#define U3DLL           (*((volatile unsigned char *) 0x81000080))
#define U3DLM           (*((volatile unsigned char *) 0x81000084))
#define U3ACR           (*((volatile unsigned long *) 0x81000088))

/* Universal Asynchronous Receiver Transmitter 4 (UART4) */
#define U4RBR           (*((volatile unsigned char *) 0x81000000))
#define U4THR           (*((volatile unsigned char *) 0x81000000))
#define U4IER           (*((volatile unsigned long *) 0x81000004))
#define U4IIR           (*((volatile unsigned long *) 0x81000008))
#define U4FCR           (*((volatile unsigned char *) 0x81000008))
#define U4LCR           (*((volatile unsigned char *) 0x8100001C))
#define U4MCR           (*((volatile unsigned char *) 0x81000010))
#define U4LSR           (*((volatile unsigned char *) 0x81000014))
#define U4MSR           (*((volatile unsigned char *) 0x81000018))
#define U4SCR           (*((volatile unsigned char *) 0x8100000C))
#define U4DLL           (*((volatile unsigned char *) 0x81000000))
#define U4DLM           (*((volatile unsigned char *) 0x81000004))
#define U4ACR           (*((volatile unsigned long *) 0x81000008))


#endif  // __LPC214x_H


#define _PCLKS 11095300  // Define PCLK for configuration baudrate
#define uart4_setbaud(x) uart4_init(x)  // Define function name uart4_setbaud equal uart4_init
#define uart3_setbaud(x) uart3_init(x)  // Define function name uart3_setbaud equal uart3_init
#define 
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for Initial UART1 ----------------------------------------//
//------------------------------------------------------------------------------------------------//
extern uart4_init(unsigned int _baudrate)
extern uart3_init(unsigned int _baudrate)
extern uart4_puts(char *p)
extern uart4_puts(char *p)
{
    unsigned short u4dl;    
    u4dl = _PCLKS/(16*_baudrate);    // Calculate for U1DL value
 	U4LCR = 0x00000083;		// 8 bit data,1 stop bit,no parity bit
    U4DLL = u4dl & 0xFF;    // U1DL for low byte
    U4DLM = (u4dl>>8);      // U1DL for high byte
    U4LCR = 0x00000003;		// DLAB =0
}
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for send character 1 time via UART4-----------------------//
//------------------------------------------------------------------------------------------------//
void uart4_putc(char c)
{
	while(!(U4LSR & 0x20)); // Wait until UART1 ready to send character     
	U4THR = c;  // Send character
}
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for send string via UART1---------------------------------//
//---------------------------------------------------------------4---------------------------------//
void uart4_puts(char *p)
{
	while(*p) // Point to character
	{
		uart4_putc(*p++);   // Send character then point to next character
	}
}
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for Initial UART3 ----------------------------------------//
//------------------------------------------------------------------------------------------------//
void uart3_init(unsigned int _baudrate)
{
	unsigned short u3dl;
    u3dl = _PCLKS/(16*_baudrate); // Calculate for U0DL value

	U3LCR = 0x00000083;		// 8 bit data,1 stop bit,no parity bit
    U3DLL = u3dl & 0xFF;    // U0DL for low byte
    U3DLM = (u3dl>>8);      // U0DL for high byte
    U3LCR = 0x00000003;		// DLAB =0
}
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for send character 1 time via UART3-----------------------//
//------------------------------------------------------------------------------------------------//
void uart3_putc(char c)
{
	while(!(U3LSR & 0x20)); // Wait until UART0 ready to send character  
	U3THR = c; // Send character
}
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for send string via UART3---------------------------------//
//------------------------------------------------------------------------------------------------//
void uart3_puts(char *p)
{
	while(*p) // Point to character
	{
		uart3_putc(*p++);  // Send character then point to next character
	}
}

⌨️ 快捷键说明

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