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

📄 sc16c.c

📁 SmartARM2400系列开发板全套资料
💻 C
字号:
#include "config.h"
#include "sc16c.h"

void SC16C_Write(uint32 addr, uint8 dat)
{
	uint32 i;
	for (i = 0; i < 100; i++);                        /*  移植到LPC2400时,总线操作须加上延时*/
	
	(*((volatile unsigned char *) addr)) = dat;
	
}

uint8 SC16C_Read(uint32 addr)
{
//	uint8 tmp32;
//	
//	tmp32 = (*((volatile unsigned char *) addr));
//	
//	return tmp32;

	uint32 i;
	for (i = 0; i < 50; i++);                        /*  移植到LPC2400时,总线操作须加上延时*/

	return (uint8)(*((volatile unsigned char *) addr));
}

/*********************************************************************************************
**	初始化SC16C652
*********************************************************************************************/
void InitSC16C(void)
{
	OSTimeDly(OS_TICKS_PER_SEC/2);
	
	SC16C_Write(CSA|SC_MCR, 0x03); /* 将UART放置到正常工作模式,禁止中断,强制DTR和RTS为0 */
//	SC16C_Write(CSA|SC_MCR, 0x10);	/* 使用局部环回模式 */
	while(SC16C_Read(CSA|SC_LSR)&0x01) /* clear RX FIFO */
	{
		SC16C_Read(CSA|SC_RHR);
	}
	SC16C_Write(CSA|SC_IER, 0x01); /* Turn on RHR interrupts – PortA */
								/* PORT A – Communication Settings */
	SC16C_Write(CSA|SC_LCR, 0x80); /* SET DLAB ON */
	SC16C_Write(CSA|SC_DLL, 0x48); /* Set Baud rate – Divisor Latch Low Byte */
								/* Default 0x03 = 38,400 BPS */
								/* 0x01 = 115,200 BPS */
								/* 0x02 = 57,600 BPS */
								/* 0x06 = 19,200 BPS */
								/* 0x0C = 9,600 BPS */
								/* 0x18 = 4,800 BPS */
								/* 0x30 = 2,400 BPS */
	SC16C_Write(CSA|SC_DLM, 0x00); /* Set Baud rate – Divisor Latch High Byte */
	SC16C_Write(CSA|SC_LCR, 0xBF); /* To access EFR reg. LCR must be set to BF */
	SC16C_Write(CSA|SC_EFR, 0xC0); /* enable enhanced features */
	SC16C_Write(CSA|SC_LCR, 0x03); /* 8 Bits, No Parity, 1 Stop Bit */
	SC16C_Write(CSA|SC_FCR, 0x4F); /* FIFO reg.: DMA mode 1, clear TX and RX fifo */

//-------------------------------------------------------------------------------------

	SC16C_Write(CSB|SC_MCR, 0x00); /* 将UART放置到回送模式 */

	while(SC16C_Read(CSB|SC_LSR)&0x01) /* clear RX FIFO */
		SC16C_Read(CSB|SC_RHR);
		
	SC16C_Write(CSB|SC_IER, 0x00); /* Turn off interrupts – Port1 */
	SC16C_Write(CSB|SC_LCR, 0x80); /* SET DLAB ON */
	SC16C_Write(CSB|SC_DLL, 0x48); /* Set Baud rate – Divisor Latch Low Byte */
								/* Default 0x03 = 38,400 BPS */
								/* 0x01 = 115,200 BPS */
								/* 0x02 = 57,600 BPS */
								/* 0x06 = 19,200 BPS */
								/* 0x0C = 9,600 BPS */
								/* 0x18 = 4,800 BPS */
								/* 0x30 = 2,400 BPS */
	SC16C_Write(CSB|SC_DLM, 0x00); /* Set Baud rate – Divisor Latch High Byte */
	SC16C_Write(CSB|SC_LCR, 0x03); /* 8 Bits, No Parity, 1 Stop Bit */
	SC16C_Write(CSB|SC_FCR, 0x07); /* FIFO reg.: DMA mode 1, clear TX and RX fifo */
}

⌨️ 快捷键说明

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