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

📄 nios串口接收.txt

📁 本程序介绍了基于NIOSii的串口接收程序
💻 TXT
字号:
nios串口接收--中断方式
#include<string.h>
#include<fcntl.h>
#include"system.h"
#include"unistd.h"
#include "alt_types.h"

#include <unistd.h>

#include "altera_avalon_uart_regs.h"
#include "altera_avalon_pio_regs.h"
#include "sys/alt_irq.h"
#define quelen 2048            
char queue[quelen]; 
int indexc = 0;
int temp_index=0;
char ch;

static void init_uart_receiver();
static void handle_uart_interrups(void* context, alt_u32 id);


int main(void)
{
init_uart_receiver();
printf("successful");
int f=0;
while (f<1)
{
    if (temp_index!=indexc)
    { 
      printf("%c", queue[temp_index]);
      temp_index++;
    } 
}

return 0;
}

static void init_uart_receiver()
{
void* status_ptr;
IOWR_ALTERA_AVALON_UART_CONTROL(UART_BASE, 0x80);
IOWR_ALTERA_AVALON_UART_STATUS(UART_BASE, 0x0);
IOWR_ALTERA_AVALON_UART_RXDATA(UART_BASE, 0x0);
alt_irq_register(UART_IRQ,status_ptr,handle_uart_interrups);
}


static void handle_uart_interrups(void* context, alt_u32 id)
{

volatile char* status_ptr =(volatile char*)context;
*status_ptr =IORD_ALTERA_AVALON_UART_STATUS(UART_BASE);

if((IORD_ALTERA_AVALON_UART_STATUS(UART_BASE)&(0x80)) ==0x80)
{
ch =IORD_ALTERA_AVALON_UART_RXDATA(UART_BASE);

    queue[indexc] =ch;
    indexc++; 
}

IOWR_ALTERA_AVALON_UART_STATUS(UART_BASE, 0x0);
}
 

⌨️ 快捷键说明

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