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

📄 uart0.c

📁 ucos在sc2410上的移植代码应该是可以在目标板上运行
💻 C
字号:
#include <string.h>
#include <stdlib.h>
#include "2410addr.h"
#include "2410lib.h"
#include "def.h"
#include "uart0.h"



void __irq Uart0_TxInt(void);
void Uart0_SendString(INT8 * pcTemp);



static	int	send_index=0;
static       int   send_isr_index=0;
#define   MAX_BUFSIZE	1024
static      char send_buf[MAX_BUFSIZE];

//---------------------------------------UART0 test function-------------------------------------
void __irq Uart0_TxInt(void)
{
     rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);	// Just for the safety
    if(send_index!= send_isr_index) 
    {
        WrUTXH0(send_buf[send_isr_index++]);
	    ClearPending(BIT_UART0);		// Clear master pending
	    rSUBSRCPND|=(BIT_SUB_TXD0);		// Clear Sub int pending
	    rINTSUBMSK&=~(BIT_SUB_TXD0);	// Unmask sub int
    }
    else
    {
    	ClearPending(BIT_UART0);		// Clear master pending
        rSUBSRCPND|=(BIT_SUB_TXD0);		// Clear Sub int pending
        rINTMSK|=(BIT_UART0);
        send_index=0;
        send_isr_index=0;
    }
}
void Uart0_SendString(INT8 * pcTemp)
{
	int ix=0;
	INT8U ch;
	
	while(*pcTemp!='\0')
		{
			ch=*pcTemp;
			if(ch=='\n')
				{
				ch='\r';
					send_buf[send_index++]=ch;
				}
		send_buf[send_index++]=*pcTemp;
		pcTemp++;
		}
	pISR_UART0=(unsigned)Uart0_TxInt;
	
    rULCON0=(0<<6)|(0<<3)|(0<<2)|(3);	// Normal,No parity,One stop bit, 8bit
    rUCON0 &= 0x400;	// For the PCLK <-> UCLK fuction
    rUCON0 |= (TX_INTTYPE<<9)|(RX_INTTYPE<<8)|(0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(1);
    //Clock,Tx:Def,Rx:Def,Rx timeout:x,Rx error int:x,Loop-back:x,Send break:x,Tx:int,Rx:int
    Uart_TxEmpty(0); //wait until tx buffer is empty.
    rINTMSK&=~(BIT_UART0);
    rINTSUBMSK&=~(BIT_SUB_TXD0);

}

⌨️ 快捷键说明

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