#include "system.h"
#include "altera_avalon_timer_regs.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
#include "sys/alt_irq.h"
#include "unistd.h"
#include <stdio.h>
#define seg *(volatile unsigned char *) SEG_BASE
#define bit *(volatile unsigned char *) BIT_BASE
void timer_init();
void Timer_ISR(void *context, alt_u32 id);
alt_u8 second = 0;
alt_u8 table[16] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
void timer_init()
{
alt_irq_register(TIMER_IRQ, 0, Timer_ISR);
IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_BASE, 0);
//IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_BASE, 50000000 >> 16);
// IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_BASE, 50000000 &0xffff);
IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_BASE, 7);
}
void Timer_ISR(void *context, alt_u32 id)
{
// printf("%d\n", second);
second++;
if(second == 10)
{
second = 0;
}
//seg = table[second];
IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_BASE, 0);
}
int main(void)
{
bit = 3;
timer_init();
while(1)
{
seg = table[second];
usleep(500);
//printf("%d\n", second);
}
return 0;
}
评论