sunemnqsu 发表于 2010-9-4 16:45:40

NIOSII数码管显示出错了···

#include "stdio.h"
#include "sys/unistd.h"
#include "io.h"
#include "string.h"
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "altera_avalon_timer_regs.h"
#include "alt_types.h"
#include "sys/alt_irq.h"
//0-9
unsigned char segtab={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char led_buffer={0};
unsigned char bittab={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
static unsigned char cnt=0;

static void timer_init(void);

int main(void)
{
unsigned char i=0,j=0;
unsigned char buf;


timer_init();

while(1){
      sprintf(buf,"%08u",j++);
      for(i=0;i<8;i++){
      led_buffer=buf-'0';
      }
      usleep(500);
}
return 0;
}

static void timer_irq(void*context,alt_u32 id)
{
    IOWR_ALTERA_AVALON_PIO_DATA(SCL_BASE,0xff);
    IOWR_ALTERA_AVALON_PIO_DATA(SCL_BASE,bittab);
   
    IOWR_ALTERA_AVALON_PIO_DATA(SDA_BASE,segtab]);
    cnt++;
    if(cnt==8)
      cnt=0;
    IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE,0);
}

static void timer_init(void)
{
    IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE,0);
    IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE,200000);
    IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_0_BASE,200000>>16);
    IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE,0x07);
   
    alt_irq_register(TIMER_0_IRQ,NULL,timer_irq);
}
这是一段NIOSII数码管显示的代码,可出来的结果是8个8,请路过的大侠帮忙指导下,谢谢···
页: [1]
查看完整版本: NIOSII数码管显示出错了···