标题:
模数递减计数器MDC中断程序问题(S12DG128)!
[打印本页]
作者:
lanhaigo
时间:
2007-6-29 17:09
标题:
模数递减计数器MDC中断程序问题(S12DG128)!
我作了个,MDC程序,用它做计时器,延时一秒.但是无论怎样改变预分频MCPR1,MCPR0,两次中断的时间间隔不变(即,频率不便);另外改变MCCNT的植,两次中断的时间间隔也不变!
希望各位高手指点,谢谢!!
#include
/* common defines and macros */
#include
/* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
long int counter,temp1;
byte flag;
byte value_lamp,cycle2;
#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt 26 void Timer_ISR(void){
counter++;
if(counter%25000==0) { //dalay 1s
flag = 1;
counter = 0;
temp1 = MCCNT;
MCCTL_MCZI = 0; // MDC 屏蔽中断
//MCCNT = 0xC350;
// PORTB = 0xe7;
}
/* clear RTIF bit */
//TFLG2_TOF = 1;
}
#pragma CODE_SEG DEFAULT
void main(void) {
/* put your own code here */
temp1 =0;
counter = 0;
flag = 0;
value_lamp = 0xaa;
DDRB=0xff; /* PTB as output */
PORTB=0x7e; /* LEDs off */
MCCTL_MCEN = 1; // MDC允许工作
MCCTL_MODMC = 1; // MDC连续工作方式 ,
MCCTL_MCPR0 = 1;
MCCTL_MCPR1 = 1; // [MCPR1 MCPR0] set Prescaler Rate -->
// [00]:1 [01]:4 [10]:8 [11]:16
//MCCNT = 0xc350;//计数50000 //不起作用1
EnableInterrupts;
for(;;) {
MCCTL_MCZI = 1; // MDC 允许中断
if(flag==1){
value_lamp = ~value_lamp ;
PORTB = value_lamp;
flag = 0;
}
} /* wait forever */
/* please make sure that you never leave this function */
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0