智能车制作
标题:
定时器输出比较为啥效果不对呢
[打印本页]
作者:
汐恋枫
时间:
2013-10-28 20:46
标题:
定时器输出比较为啥效果不对呢
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include<MC9S12XS128.h>
static unsigned int a=0;
///锁相环
void PLL_Init(void) //PLLCLK=2*OSCCLK*(SYNR+1)/(REFDV+1)
{ //锁相环时钟=2*16*(2+1)/(1+1)=48MHz
REFDV=1; //总线时钟=48/2=24MHz
SYNR=2;
while(!(CRGFLG&0x08));
CLKSEL=0x80;
}
void delayms(void) {
unsigned int i;
for(i=0;i<1335;i++);
}
//定时器初值
void ECT0_init(void)
{
TIOS=0x01;
TSCR2=0x86; //分频 24/64 相当于 2.67us
TSCR1=0x80;
TC0=37500; // 37500*2.67us=10ms定时时间
TIE=0x01;
TCTL2=0x02;
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
//#pragma CODE_SEF __NEAR_SEG NON_BANKED
interrupt 8 void Timer0_ISR(void)
{
// unsigned int m;
a=a+1;
// m=TCNT;
//TC0=m+37500;
TFLG1_C0F=1;
// DisableInterrupts ;
if(a>=100)
{
PORTB=~PORTB;
//PORTB=0xfb;
a=0;
// delayms();
}
}
#pragma CODE_SEG DEFAULT
void main(void)
{
/* put your own code here */
PLL_Init();
ECT0_init();
DDRB=0xff;
PORTB=0x00;
EnableInterrupts;
for(;;) {
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2