C5509A启动使用定时器
#include <stdio.h> #include <csl.h> #include <csl_pll.h> #include <csl_chip.h> #include <csl_gpio.h> #include <csl_timer.h> #include <csl_irq.h> #include <csl_chiphal.h> extern VECSTART(void); // 有个文件叫做vectors.s55 和代码放在一起,不会出现找不到VECSTART这个函数了。 如果报错需要extern void VECSTART(void); void delay(); PLL_Config myConfig = { 0,1,24,1 }; TIMER_Config timCfg0 = { TIMER_CTRL, /* TCR0 */ 0xFFFFu, /* PRD0 */ 0x3000 /* PRSC */ }; Uint16 eventId0; TIMER_Handle hTimer; volatile Uint16 timer0_cnt = 0; interrupt void timer0Isr(void); void taskFxn(void); int old_intm; Uint16 tim_val; Uint16 xfchange = 0; Uint16 ms,f; void main( void ) { /*初始化CSL库*/ CSL_init(); IRQ_setVecs((Uint32)(&VECSTART)); old_intm = IRQ_globalDisable(); PLL_config(&myConfig); hTimer = TIMER_open(TIMER_DEV0,TIMER_OPEN_RESET); eventId0 = TIMER_getEventId(hTimer); IRQ_clear(eventId0); IRQ_plug(eventId0,&timer0Isr); TIMER_config( hTimer,&timCfg0 ); IRQ_enable(eventId0); IRQ_globalEnable(); TIMER_start(hTimer); GPIO_RSET(IODIR,0xFF); while(1) { } } void delay() { Uint32 j = 0,k = 0; for(j = 0;j<0xf0;j++) { for(k= 0;k<3000;k++) {} } } interrupt void timer0Isr(void) { // 7654 3210 // 0100 0000 GPIO_RSET(IODATA,0x40); delay(); // 0000 0000 GPIO_RSET(IODATA,0x00); delay(); }