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

📄 subfunc.c

📁 串口数据与文件传输程序
💻 C
字号:
#include "subFunc.h"

//***************************************************************************  
// 函数名称: hex2char				                                   		*
// 函数入口: val:待转换整型数												*
// 函数出口: 转换完毕的字符型串			      	                       		*
// 函数描述: 8位整型(0-255)转换为对应的十六进制字符型数据					*
//***************************************************************************
char *hex2char(int val)
{
    static char str[3];
    U8 temp;
	
    str[2]='\0';
    
    temp = val / 0x10;
    if(temp<=9)str[0]='0'+temp;
    else str[0]=('a'+temp-10);
    
    temp = val % 0x10;
    if(temp<=9)str[1]='0'+temp;
    else str[1]=('a'+temp-10);
	
    return str;
}

//***************************************************************************  
// 函数名称: Isr_Init				                                   		*
// 函数入口: 无																*
// 函数出口: 无							                            		*
// 函数描述: 初始化各中断控制寄存器,给中断入口函数赋值.						*
//***************************************************************************
void Isr_Init(void)
{
	 rULCON1=(0<<6)|(0<<3)|(0<<2)|(3);	// Normal,No parity,One stop bit, 8bit
	 rUCON1 |=(1<<8)|(1<<6);
	 //Clock,Tx:pulse,Rx:pulse,Rx timeout:x,Rx error int:o,Loop-back:x,Send break:x,Tx:int,Rx:int
	   
	 rULCON0=(0<<6)|(0<<3)|(0<<2)|(3);	// Normal,No parity,One stop bit, 8bit
	 rUCON0 |=(1<<8)|(1<<6);
	 //Clock,Tx:pulse,Rx:pulse,Rx timeout:x,Rx error int:o,Loop-back:x,Send break:x,Tx:int,Rx:int
	    
	    
	 rINTMSK=~(BIT_UART0 | BIT_UART1 | BIT_EINT0 | BIT_EINT2);	    
	 rINTSUBMSK=~(BIT_SUB_RXD1|BIT_SUB_ERR1);
	 rINTSUBMSK=~(BIT_SUB_RXD0|BIT_SUB_ERR0);
	    
	 pISR_UART0 = (unsigned)Irq_uart0;
	 pISR_UART1 = (unsigned)Irq_uart1;
	 pISR_EINT0 = (unsigned)Irq_extern0;
	 pISR_EINT2 = (unsigned)Irq_extern2;
	    
	 // Clear Int Pending and Unmask
	 ClearPending(BIT_UART0);
	 ClearPending(BIT_UART1);
	 ClearPending(BIT_EINT0);
	 ClearPending(BIT_EINT2);
	   
	 rSUBSRCPND=(BIT_SUB_RXD0|BIT_SUB_ERR0);
	 rSUBSRCPND=(BIT_SUB_RXD1|BIT_SUB_ERR1);
}


//***************************************************************************  
// 函数名称: GetFpgaData			                                   		*
// 函数入口: StartAddr:读取数据的首地址,dLength:读取数据的长度				*
//					dLength范围:0x08000000 - 0x080001ff						*
// 函数出口: buffer:存储读取的FPGA数据      	                       		*
// 函数描述: 从FPGA读数据,这里的SRAM是16位位宽								*
//***************************************************************************
void GetFpgaData(U32 StartAddr, U16 dLength, U16 *buffer)
{
	U16 i;
	StartAddr = (StartAddr / 2) * 2;
	for(i=0; i<dLength; i++)
	{
		buffer[i] = ((volatile unsigned short *)StartAddr)[i*2];
	}
}

//***************************************************************************  
// 函数名称: SendFpgaData			                                   		*
// 函数入口: StartAddr:数据写入的首地址,dLength:写入数据的长度				*
//			 dLength范围:0x08000000 - 0x080001ff							*
//			 buffer:存储需要写入FPGA的数据									*
// 函数出口: 无							   	 	                       		*
// 函数描述: 写数据到FPGA,这里的SRAM是16位位宽								*
//***************************************************************************
void SendFpgaData(U32 StartAddr, U16 dLength, U16 *buffer)
{
	U16 i;
	StartAddr = (StartAddr / 2) * 2;
	for(i=0; i<dLength; i++)
	{
		((volatile unsigned short *)StartAddr)[i*2] = buffer[i];
	}
}

⌨️ 快捷键说明

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