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

📄 uart_test.c

📁 串口资料
💻 C
字号:

#include "csl_stdinc.h"
#include "stdio.h"
#include "stdlib.h"
#include "c6x.h"

//regs defined in CPLD 
#define ULF_REG          *(volatile Uint8*)0xa0000000
#define NU_REG           *(volatile Uint8*)0xb0000000

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

//uart 寄存器定义 
#define UARTa_RHR     *(volatile Uint8*) 0xa0010000
#define UARTa_IER     *(volatile Uint8*) 0xa0010001
#define UARTa_IIR     *(volatile Uint8*) 0xa0010002
#define UARTa_LCR     *(volatile Uint8*) 0xa0010003
#define UARTa_MCR     *(volatile Uint8*) 0xa0010004
#define UARTa_LSR     *(volatile Uint8*) 0xa0010005
#define UARTa_MSR     *(volatile Uint8*) 0xa0010006
#define UARTa_SPR     *(volatile Uint8*) 0xa0010007


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

void Uart_Reset();//复位整个uart芯片
void DelayFunc(); //延时
void Uarta_Init(); //初始化uarta
//Uint8 uarta_getchar();//接收数据
//void  uarta_putchar(Uint8 data);//发送数据

Uint8 hehe[16];


void main()
{
	CSR=0x0;				// Disable Maskable Interrupts Globally  
	IER = 0x0; 				
	
    //使能外部中断 INT_6   	
   	IER = 0x43;      					// IE6 = 1, NMIE = 1:   										
   	ICR = IFR | 0x80; 					// Clear IFR for INT_6;	
   	 
	
	Uart_Reset();
	Uarta_Init(); 
	
	CSR |= 0x1;       		// GIE = 1: Enabled Maskable Interrupts Globally
	
	printf("Uart Test Begin....\n");
	

    while(1);

}



interrupt void uart_isr()
{
     Uint8  Data_Temp;
     Uint8  temp0;
	//int i=0;
//	int j;
	//CSR = 0x0;
	DelayFunc();
	//for(i=0;i<16;i++)
//	while((UARTa_LSR&0x01)==0x01)
	//{
	 // hehe[i]=UARTa_RHR;
	 //DelayFunc();
     temp0=UARTa_IIR;
     Data_Temp = UARTa_RHR;
  // DelayFunc();
	//for(j=0;j<4;j++)
	//printf("  DATA : %x\n",hehe[i]);}
	printf("  DATA : %x\n",Data_Temp);
}



//reset uart 
void Uart_Reset()
{
	ULF_REG|=0x08;  
	DelayFunc();
	ULF_REG&=0xf7 ;
    DelayFunc();
}
//Delay for reset uart
void DelayFunc()
{
	Uint32 i;
	for(i=0;i<100;i++)
		asm(" NOP");
}

//Initial uarta
void Uarta_Init()
{	
	int i;
	Uint8 temp1,temp2,temp3;

	UARTa_LCR=0x03;	//8bit,1 stop bits,no parity,nomal operating condition	
	temp1=UARTa_LCR;
	
	UARTa_LCR=0x80;//set baud rate  
	//9600Hz,0x90;115200Hz,0x0c
	UARTa_RHR=0x90; //when LCR.7=1,RHR is DLL.  
	UARTa_IER=0x00;  //when LCR.7=1,IER is DLH.
	
	
	UARTa_LCR=0xbf;
	temp2=UARTa_IIR;
	UARTa_IIR=temp2+0x10;//EFR
	UARTa_LCR=0x0;
	//UARTa_IIR=0x5f;
	temp3=UARTa_MCR;
	UARTa_MCR=temp3+0x40;
	UARTa_SPR=0x44;      //SPR is TLR  
	UARTa_MCR=temp3;
	UARTa_LCR=0xbf;
	UARTa_IIR=temp2;
	UARTa_LCR=temp1;
	
	/*UARTa_LCR=0xbf;
	temp2=UARTa_IIR;
	UARTa_IIR=temp2+0x10;//EFR
	UARTa_LCR=0x0;
	temp3=UARTa_MCR;
	UARTa_MCR=temp3+0x40;
	temp4=UARTa_SPR;*/

	//UARTa_LCR=temp;
	
	UARTa_IIR=0x0f;//FCR
    UARTa_MCR=0x08;//0x08; //INT A and B pins are enabled
	UARTa_IER=0x01; //01 // Enable the RHR interrupt
	

	
    
	for(i=0;i<10;i++)
		asm(" NOP");
}








⌨️ 快捷键说明

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