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

📄 mcuuarttrans.c

📁 这是我编一个DSP的USP的程序 调试通过
💻 C
字号:
/********************************************************************/ 
/*                                                                  */
/* Copyright 2003 by Lab140 UESTC.                                  */
/* All rights reserved. Property of Lab140 UESTC.                   */
/* Restricted rights to use, duplicate or disclose this code are    */
/* granted through contract.                                        */
/*                                                                  */  
/********************************************************************/
/*                                                                  */
/* FILENAME: UartTrans.c                                            */
/* This file is the function to use Uart to tansmit/receive data    */
/* to/from MCU.                                                      */                                          
/* Lastest modified by J.R.Lin on July,18th,2003.                   */
/*                                                                  */
/********************************************************************/

#include	"TL16C550C_Reg_MCU.h"
#include    "algorithm.h"

#define		BaudDesired		(long)(9600)		//38400//19200
#define		PrimaryF		(long)(3686400)
#define		BaudConst		(long)(16)
#define		BaudDiv			(long)(PrimaryF/(BaudDesired*BaudConst))


#define		endOfRxStr		('#')

unsigned char  MCUuartReceiveBuffer[6];
char MCUuartCharValue;
int  MCUuartReceiveAchar;

char  receive_key=0;
unsigned int receiveI=0;
//Name: MCUUartPrintf();
//Function: transmit a string to MCU uart
//In Para:UPBuffer
//Out Para: no
//Description: Transmit a string stored in UPbuffer to MCU uart.
void MCUUartPrintf(char * UPBuffer)
{
	int iUP=0;
	char regValue;

    while (UPBuffer[iUP]!='\0')
    {
      /* */ 	
    	do
	    {
	    	regValue=(TL16C550C_LSR_ADDR) & TL16C550C_LSR_THRE;
	    }while (regValue==0);
	    
    	TL16C550C_THR_ADDR=UPBuffer[iUP++];
    }
}

//Name: MCUUartPrintf1();
//Function: transmit a group data to MCU uart
//In Para:UPBuffer, transCount
//Out Para: no
//Description: Transmit data in UPbuffer length of  transCount
//             to MCU uart.
void MCUUartPrintf1(char * UPBuffer, int transCount)
{
	char regValue;
	int iUP=0;
	
	while(iUP!=transCount)
	{
		do
	    {
	    	regValue=(TL16C550C_LSR_ADDR) & TL16C550C_LSR_THRE;
	    }while (regValue==0);
	    
    	TL16C550C_THR_ADDR=UPBuffer[iUP++];
	}
	delay(lcdDelay);
}

//Name: MCUUartPutc();
//Function: transmit a charactor to MCU uart
//In Para:putchar
//Out Para: no
//Description: Transmit a charactor determined by putchar
//             to MCU uart.
void MCUUartPutc(char putChar)
{
	char regValue;

    do
	{
		regValue=(TL16C550C_LSR_ADDR) & TL16C550C_LSR_THRE;//0x20;
	}while (regValue==0);

    TL16C550C_THR_ADDR=putChar;
}



//Name: MCUuartInit();
//Function: MCU uart initialization.
//In Para:no
//Out Para: no
//Description: MCU uart initialization.
void MCUuartInit()
		// This program is used to initialize the UART.
{
	char regValue;
	
	
	TL16C550C_LCR_ADDR=TL16C550C_LCR_Baud;
			//  Set LCR_DLAB=1 to set baudrate register.
			
	TL16C550C_DLL_ADDR=BaudDiv;
	TL16C550C_DLM_ADDR=0;
			//	Set BaudRate to BaudDesired.
			
	TL16C550C_LCR_ADDR=TL16C550C_LCR;
			//	Set LCR_DLAB=0 to enable normal UART operation.
			
	regValue=TL16C550C_IIR_ADDR;
			//	to clear IIR.
	regValue=TL16C550C_LSR_ADDR;
			//	to clear ISR.
			
	regValue=TL16C550C_RBR_ADDR;
			//  to clear receive state
	
	TL16C550C_IER_ADDR=TL16C550C_IER;
			//	Enable receive but no transmit interrupts.
	
	// transmit test.	
	/*for (regValue=0;regValue<9;regValue++)			
	{
		ledPrintf("83207537");
		delay(2000);
		ledPrintf(" ");	
		delay(2000);
	}*/	
}


//Name: MCUuartISR();
//Function: Interrrupt Service Routine for int0.
//          Receive one charactor or a string from MCU serial port
//In Para:no
//Out Para: MCUuartCharValue (gloabol) 
//		    MCUuartReceiveAchar (gloabol)
//Description:Stored received charactor  into MCUuartCharValue, then set
//            flag MCUuartReceiveAchar to 1. Application can poll this 
//            flag to confirm a new data.
interrupt void MCUuartISR()
{
	char intValue;
	int  receive;
	int  transmit;
//	static int receiveI=0;
	
	intValue=TL16C550C_IIR_ADDR;
	        // Read the interrupt register value.
	receive=intValue & UartReceiveInt;
	transmit=intValue & UartTransInt;
	
	if (receive!=0)
	{
  	   	   
	   //Receive  a string	
	   /**/
	   MCUuartReceiveBuffer[receiveI]=TL16C550C_RBR_ADDR & 0xff;
	   receiveI++;
	   if (receiveI==McuUartBufferLen)
	   {
	      receiveI=0;
	      MCUuartReceiveAchar=1;
	      
	      receive_key=1;
	    
	   }   
	      
	}
	else if (transmit!=0)
	{
	
	}
       
}




⌨️ 快捷键说明

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