一个看起来简单的timer,搞了一个下午,还没搞定!真的不知道是什么原因了,请高手指教:
#ifndef _TIMER1_H_ #define _TIMER1_H_
#include "system.h" #include "altera_avalon_timer_regs.h"
#define PERIODL(DATA) IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE,DATA) #define PERIODH(DATA) IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_0_BASE,DATA) #define CONTROL IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE,0X0060) #define STATUS IORD_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE) #define STATUS_WR IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE,0X0000) #define TO ALTERA_AVALON_TIMER_STATUS_TO_MSK;
#endif
#include "alt_types.h" #include "timer1.h"
void main() { alt_32 t=100000000; alt_32 i=0; alt_16 sta; PERIODL(t&0x0000ffff); PERIODH((t>>16)&0x0000ffff); CONTROL; while(1) { sta=STATUS; if(sta&0x0001) { printf("a sencond passed! (%d)",i++); STATUS_WR; } } } |