我看过了你的程序。主要问题是对TOF清零应该是对TFLG2_TOF写1,而不是写0;另外,对TCNT的写操作是无效的。我把改过的程序下载到DP256的EVB上,可以看到程序可以正确运行,LED在闪烁。由于电路板的原因,我将LED口改为了PORTB_BIT0。下面是我修改过的程序:
#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt void Int_TimerOverFlow(void){
TFLG2_TOF = 1; //clear timer overflow flag
time_count++;
if (time_count>2) {time_count=0;flag=~flag;}
}
#pragma CODE_SEG DEFAULT
void PORT_Init(void){
DDRB=0x01;
PORTB_BIT0=0; //µÆÁÁ
}
void ECT_Init(void)
{
COPCTL_CR=0;//¹Ø±Õ¿´ÃŹ·.COP(×ÔÓÉÔËÐп´ÃŹ·¶¨Ê±Æ÷)¿ØÖƼĴæÆ÷
TSCR1_TEN=0; //Í£Ö¹¶¨Ê±Æ÷
// TSCR2_TCRE=1;//¶¨Ê±Æ÷¸´Î»
TSCR2_PR = 4; //prescale factor is 16, bus clock/128=8Mhz/8
TSCR2_TOI = 1; //timer overflow interrupt enable
//TCNT = 0x0040;
TSCR1_TEN = 1; //timer enable
}
void main(void) {
PORT_Init();
ECT_Init();
EnableInterrupts;
while(1){
if(flag==0){
DDRB=0x01;
PORTB_BIT0=0;//µÆÁÁ
}
else{
DDRB=0x01;
PORTB_BIT0=1;//µÆÃð
}
}
} |