智能车制作
标题:
请问PIT的用法
[打印本页]
作者:
jchen5471
时间:
2010-1-17 15:58
标题:
请问PIT的用法
/现象
B灯闪动,周期是INTVERAL*(0.01)ms,可用来记时.
//demo by whut_wj
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
#define INTVERAL 10000
void SetBusClock(void)
{
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR=2;
REFDV=1; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=48MHz;
_asm(nop); //BUS CLOCK=24M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
void Dly_ms(int ms) //24M时为1ms
{
int i,j;
for(i=0;i<ms;i++)
for(j=0;j<0x7ff;j++);
}
void PitInit(void)
{
PITCFLMT_PITE=0; //disable PIT
PITCE_PCE0=1; //enable timer channel 0
PITMTLD0=240-1; //time base 240 clock cycles ,it's 0.1M Hz
PITMUX=0X00; // ch0 connected to micro timer 0
PITLD0=INTVERAL-1; //INTVERAL micro time bases
PITINTE_PINTE0=1; //enable interupt channel 0
PITCFLMT_PITE=1; //enable PIT
//PITCNT0,类似于自由记数器,只不过一直是递减,TCNT是一直递增
}
void main(void)
{
EnableInterrupts;
SetBusClock();
PitInit();
DDRB=0xff;
for(;;)
{
}
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 66 PIT0Interrupt(void)
{
PORTB^=0xff;
PITTF_PTF0=1;
}
该程序是定时1s,可是做出来后效果却不是为什么
作者:
fi2005
时间:
2010-1-21 19:34
你的定时时间是0.1S
作者:
jiangjie1229
时间:
2011-4-23 19:11
24M/240=0.1MHZ 0.1M/10000=10HZ 即0.1s
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2