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

📄 uart.c

📁 c语言写的哦,里面还带有整点报时音乐,音乐程序很简单
💻 C
字号:
volatile unsigned int *P_UART_Command1=(unsigned int*)(0x7021); 		// Command1 Port for UART
volatile unsigned int *P_UART_Command2=(unsigned int*)(0x7022); 		// Command2 Port for UART
volatile unsigned int *P_UART_Data=(unsigned int*)(0x7023);  			// Data Port for UART
volatile unsigned int *P_UART_BaudScalarLow=(unsigned int*)(0x7024); 	// Set Baud Rate scalar low
volatile unsigned int *P_UART_BaudScalarHigh=(unsigned int*)(0x7025); 	// Set Baud Rate scalar high
#include	"SPCE061V004.H"
#define P_Watchdog_Clear		(volatile unsigned int *)0x7012 
extern void UART_Init();
extern void UartSendByte();
extern void sendsixteenbit();
unsigned int UartReadByte();
//============================================================= 
// Function:     	UART_Init()
// Syntax:      	void UART_Init(void);
//=============================================================
void UART_Init(void)
{
	int a;
	
	*P_UART_BaudScalarHigh=0x14;			//波特率设置2400
	*P_UART_BaudScalarLow=0x00;

	*P_UART_Command1=0x008c;				//允许接收中断,偶校验
	*P_UART_Command2=0x00C0;                //允许发送接收
		
	a=*P_UART_Data;					// clear receiving buffer
}


//============================================================= 
// Function:     	UartSendByte()
// Syntax:      	void UartSendByte(void);
//=============================================================
void UartSendByte(unsigned int uidata)
{
	int a;
	a=*P_UART_Command2;
	a=a&0x0040;
	while(!a)						//Check bit 6 to see if TxRDY = 1
	{
		a=*P_UART_Command2;
		a=a&0x0040;
		*P_Watchdog_Clear=0x0001;
	}
	*P_UART_Data=uidata;				// send data

//	a=0x4f;
//	while(a--)
//	 {
//	  *P_Watchdog_Clear=0x0001;
//	 }
//	a=*P_UART_Data;					// clear receiving buffer

}


//============================================================= 
// Function:     	UartReadByte()
// Syntax:      	void UartReadByte(void);
//=============================================================
unsigned int UartReadByte(void)
{
	unsigned int uidata,a;
	a=*P_UART_Command2;
	a=a&0x0080;
	while(!a)						//Check bit 7 to see if RxRDY = 1
	{
		a=*P_UART_Command2;
		a=a&0x0080;
		*P_Watchdog_Clear=0x0001;
	}
	uidata=*P_UART_Data;				// read data
	return(uidata);
}

//////////////////////////////////////////////////////
//////////////发送16位数//////////////////////
//////////////////////////////////////////////////////
void sendsixteenbit(unsigned int sixteenbit)   //发送16位数
{
int a;
UartSendByte(0x0055);      //发送标志数
//delay(1);
a=0x00ff&sixteenbit;
UartSendByte(a);      //发送低位
//delay(1);
sixteenbit=sixteenbit>>8;
a=0x00ff&sixteenbit;
UartSendByte(a);      //发送高位
}

⌨️ 快捷键说明

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