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

📄 simple_rx_isr.c

📁 altera串口源代码程序
💻 C
字号:
//
#include "buffer.h"  // defines RXBUFSIZE and TXBUFSIZE
#include "excalibur.h"

//Global variables
unsigned char RxBuf[RXBUFSIZE];	// the receiver buffer.
int RxHead = 0;			// the circular buffer index
int RxTail = 0;
unsigned char TxBuf[TXBUFSIZE];	// the transmit buffer.
int TxHead = 0;			// the circular buffer index
int TxTail = 0;

void simpleReceiver1(int context);
unsigned char _getchar();

int main(void)
	{
	int context = 0;
	unsigned char rxchar;
	
	nr_installuserisr(na_uart1_irq, simpleReceiver1, context); // install UART ISR (receiver)
	na_uart1->np_uartcontrol = np_uartcontrol_irrdy_mask; // enable rrdy interrupt
	
	while(1)
		{
		rxchar = _getchar();
		printf("\nfrom RxBuf: %c \n",rxchar);
		}

	return 0;
	}


// pass an int to make it compatible with nr_installuserisr2 routine
// contents of third argument ("context") in nr_installuserisr is passed to ISR
void simpleReceiver1(int data)
	{
	// put new char into buffer from UART
	RxBuf[RxHead] = na_uart1->np_uartrxdata; 
	// clear the errors and interrupts
	na_uart1->np_uartstatus=0; 

	if ((++RxHead) > (RXBUFSIZE-1))		
		{
		RxHead = 0;
		}
	}

⌨️ 快捷键说明

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