|
#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(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[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,请路过的大侠帮忙指导下,谢谢··· |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|