最近在学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[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char led_buffer[8]={0};
unsigned char bittab[8]={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[20];
timer_init();
while(1){
sprintf(buf,"%08u",j++);
for(i=0;i<8;i++){
led_buffer=buf[7-i]-'0';
}
usleep(500000);
}
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[cnt]);
IOWR_ALTERA_AVALON_PIO_DATA(SDA_BASE,segtab[led_buffer[cnt]]);
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 ,请问这到底是怎么一回事啊???希望路过的都发表下意见,谢谢···