数码管的加减计数都是正常的 alt_irq_register的返回值为0,正常。并且在alt_irq全局变量中发现timer0已经被分配了中断向量irq1。 现在的问题是中断服务#include "time.h" #include "unistd.h" #include "altera_avalon_timer_regs.h" #include "sys/alt_irq.h" #include "stdio.h" #include "stddef.h" #include "system.h" #include "altera_avalon_pio_regs.h" #include "alt_types.h" static unsigned int TH1; unsigned char temp_TH1=0xff; unsigned char temp_TL1=0xea; static unsigned char PIN_MSC=1;
void isr(void * context, alt_u32 id) { while(1); IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE, 0); PIN_MSC=~PIN_MSC; *(unsigned int *)BEEP_BASE =PIN_MSC; TH1=temp_TH1; TH1=(TH1<<8 | temp_TL1)*8; IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE,TH1); IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_0_BASE,0); IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE, ALTERA_AVALON_TIMER_CONTROL_ITO_MSK|ALTERA_AVALON_TIMER_CONTROL_START_MSK ); } #define data *(unsigned int *)SEGDATA_BASE #define com *(unsigned int *)SEGCOM_BASE unsigned char chcode(unsigned char x) { unsigned char da="0"; switch(x) { case 0x00: da="0x40";break;//0 case 0x01: da="0x79";break;//1 case 0x02: da="0x24";break;//2 case 0x03: da="0x30";break;//3 case 0x04: da="0x19";break;//4 case 0x05: da="0x12";break;//5 case 0x06: da="0x03";break;//6 case 0x07: da="0x78";break;//7 case 0x08: da="0x00";break;//8 case 0x09: da="0x10";break;//9 case 0x0a: da="0x08";break;//a case 0x0b: da="0x03";break;//b case 0x0c: da="0x27";break;//c case 0x0d: da="0x21";break;//d case 0x0e: da="0x06";break;//e case 0x0f: da="0x0e";break;//f } return da; }
int main (void) __attribute__ ((weak, alias ("alt_main")));
int alt_main (void) { alt_u8 led = 0x2; int k; unsigned char a="0",b=0xff,c,d,e,f; unsigned int i,j;
//设置定时器为自由运行模式 IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE, ALTERA_AVALON_TIMER_CONTROL_ITO_MSK | ALTERA_AVALON_TIMER_CONTROL_CONT_MSK | ALTERA_AVALON_TIMER_CONTROL_START_MSK); //开始中断注册操作 k=alt_irq_register(TIMER_0_IRQ, TIMER_0_BASE, isr); IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE, 0xffff); IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_0_BASE, 0xff); IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE, ALTERA_AVALON_TIMER_CONTROL_ITO_MSK|ALTERA_AVALON_TIMER_CONTROL_START_MSK ); IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE, 1); *(unsigned int *)TIMER_0_BASE=1; //IOWR_ALTERA_AVALON_TIMER_IENABLE(TIMER_0_BASE, 1); //*(unsigned int *)TIMER_0_BASE=1; if(k!=0) { while(1); } while(1) { e=chcode((a&0xf0)>>4); f=chcode(a&0xf); a=a+1; c=chcode((b&0xf0)>>4); d=chcode(b&0xf); b=b-1; for(i=0;i<6000;i++) {
if(i%500==0) { // led=0x2 | (0x1 & PIN_MSC); led=0x1 & PIN_MSC; *(unsigned int *)LED_BASE = led; } else if(i%500==250) { led=0x1 & PIN_MSC; *(unsigned int *)LED_BASE = led; } if(PIN_MSC==0) { while(1); } /* if(i%50==0) { *(unsigned int *)BEEP_BASE = 0; } else if(i%50==25) { *(unsigned int *)BEEP_BASE = 1; } */ com=0; data=e; com=0x08; for(j=0;j<3000;j++) { // IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE, 1); } com=0; data=f; com=0x04; for(j=0;j<3000;j++) { // IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE, 1); } com=0; data=c; com=0x02; for(j=0;j<3000;j++) { // IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE, 1); } com=0; data=d; com=0x01; for(j=0;j<3000;j++) { // IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE, 1); } }
} return 0; }
|