打印

新手求助!!UART串口通信

[复制链接]
1589|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
marenjun|  楼主 | 2007-4-7 20:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在以前的帖子中看到的这样一段程序:
#include<stdio.h>
#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);
}

请问1.我想用这段程序实现字符串输入后并显示可以吗?
2.为什么“IOWR_ALTERA_AVALON_UART_CONTROL(UART_BASE, 0x80)”中要写入0X80,不是说CONTROL的高三位是没用的吗?
3.还有就是“alt_u32 id”中的id,需要改吗?改成什么?

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

6

主题

7

帖子

0

粉丝