- UID
- 815357
|
我刚开始接触MC9S12XEP100,在使用ECT时想利用Timer产生一个定时中断,从而实现LED的流动闪烁。现在定时中断不能进入,那位使用过S12X系列的朋友帮忙看看我程序哪里有问题,谢谢啦!下面是我写的程序,模仿龙丘的写的:
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
unsigned int counter;
// PLL初始化子程序 BUS Clock=16M
void setbusclock(void)
{
CLKSEL=0x00; // disengage PLL to system
PLLCTL_PLLON=1; // turn on PLL
SYNR=0x00 | 0x03; // VCOFRQ[7:6];SYNDIV[5:0]
// fVCO= 2*fOSC*(SYNDIV + 1)/(REFDIV + 1)
// fPLL= fVCO/(2 × POSTDIV)
// fBUS= fPLL/2
// VCOCLK Frequency Ranges VCOFRQ[7:6]
// 32MHz <= fVCO <= 48MHz 00
// 48MHz < fVCO <= 80MHz 01
// Reserved 10
// 80MHz < fVCO <= 120MHz 11
REFDV=0x40 | 0x00; // REFFRQ[7:6];REFDIV[5:0]
// fREF=fOSC/(REFDIV + 1)
// REFCLK Frequency Ranges REFFRQ[7:6]
// 1MHz <= fREF <= 2MHz 00
// 2MHz < fREF <= 6MHz 01
// 6MHz < fREF <= 12MHz 10
// fREF > 12MHz 11
// pllclock=2*osc*(1+SYNR)/(1+REFDV)=32MHz;
POSTDIV=0x00; // 4:0, fPLL= fVCO/(2xPOSTDIV)
// If POSTDIV = $00 then fPLL is identical to fVCO (divide by one).
_asm(nop); // BUS CLOCK=16M
_asm(nop);
while(!(CRGFLG_LOCK == 1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
void delay_ms(int ms)
{
int ii,jj;
if (ms < 1) ms = 1;
for(ii = 0; ii < ms; ii++)
for(jj = 0; jj < 2670; jj++); //busclk:16MHz--1ms
}
void Timer_Init(void)
{
ECT_TSCR1 = 0x80;//TIMER INT ENABLED
ECT_TSCR2 = 0x84;//16分频
counter = 0;
}
void main(void)
{
/* put your own code here */
setbusclock();
EnableInterrupts;
DDRA = 0x0F;
PORTA = 0x00;
for(;;)
{
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 16 Timer_Overflow(void)
{
ECT_TFLG2_TOF = 1; //清定时器溢出标志位
counter++;
if(counter == 10)
{
PORTA = ~PORTA;
counter = 0;
}
} |
|