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

📄 uart.c.bak

📁 2410bios 实现简单功能 裸板传输 跑马灯 定时器
💻 BAK
字号:
#include "2410addr.h"
#include "2410lib.h"

int i =1;
static void init_uart(void)
{	
	char sendmsg[24]=		//同步字,控制字,2个信息字
	{
				0xD7,0x09,0xD7,0x09,0xD7,0x09,		
				0x41,    01,   02,    00,   00,   00,
				00, 123, 15, 159 , 45 ,0,
				01, 123, 15, 159 , 45 ,0,
	}
	rULCON1 =3;		//设置每桢长度
	rUCON1 =0x5;	      //设置非中断模式
	rUBRDIV1 =0x19;	//设置波特率	
	
	while(1)
	{
		int i=0;
		for(i=0; i<24; i++)
		{
			while(rUTRSTAT1 & 2 == 0);
  		rUTXH1 =sendmsg[i];
    	Delay(20);
    }
	}
}
/*****************************************
轮询 - not fifo
*****************************************/
/*
void uart_init()
{
	rULCON1 =3;		//设置每桢长度
	
	rUCON1 =0x25;	//设置回环,中断模式

	//DisableIrq(BIT_UART0);	//屏蔽中断
	
	//rUFCON1 =0;		//设置 Not-FIFO 模式
	
	rUBRDIV1 =0x19;	//设置波特率
}

void in_out()
{	
	int i =1;
	while(1)
	{
		while(rUTRSTAT1 & 2 == 0);
  		rUTXH1 =i++;
    	Delay(20);
		while(rUTRSTAT1 & 1 == 0);
		printf("%d\n",rURXH1);
		Delay(1000);
	}
}
*/

/*****************************************
中断 - not fifo
*****************************************/
/*
void uart_init()
{	
	rULCON1 =0x3;		//设置每桢长度
	rUCON1 =0x25;	//设置回环,中断模式
	rUBRDIV1 =0x19;	//设置波特率	

	EnableIrq(BIT_UART1);	//打开中断
	EnableSubIrq(BIT_SUB_ERR1 | BIT_SUB_TXD1 | BIT_SUB_RXD1);
	rUTXH1 =0;
}

void __irq in_out()
{

	while(rUTRSTAT1 & 2 == 0)
   		;
	rUTXH1 =i++;
	Delay(20);
	if(rSUBSRCPND & BIT_SUB_TXD1)
	{
		printf("%d\n",rURXH1);
		Delay(1000);
	}
	ClearPending(BIT_UART1);
	ClearSubPending(BIT_SUB_ERR1 | BIT_SUB_TXD1 | BIT_SUB_RXD1);
	DisableIrq(BIT_UART1);
	DisableSubIrq(BIT_SUB_ERR1 | BIT_SUB_TXD1 | BIT_SUB_RXD1);
}
*/

/*******************************************
中断,fifo
*******************************************/
/*
void uart_init()
{	
	rULCON1 =0x3;		//设置每桢长度
	rUCON1 =0x25;	//设置回环,中断模式
	rUBRDIV1 =0x19;	//设置波特率	

	EnableIrq(BIT_UART1);	//打开中断
	EnableSubIrq(BIT_SUB_ERR1 | BIT_SUB_TXD1 | BIT_SUB_RXD1);
	
	rUFCON1 =0x1;
}

void __irq in_out()
{
	static int i =1;
    while( rUFSTAT1 & 0xF )
	   		;
	if(rUFSTAT1 & (1<<9) == 0)
	{
		rUTXH1 =i++;
	}
	ClearSubPending(BIT_SUB_TXD1);
	   	
	Delay(100);
	
	if(rUFSTAT1 & 0xf)
	{
		printf("%d\n",rURXH1);
		Delay(500);
	}
	ClearPending(BIT_UART1);
	ClearSubPending(BIT_SUB_ERR1 | BIT_SUB_RXD1);
}
*/

⌨️ 快捷键说明

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