中级会员
- 积分
- 411
- 威望
- 285
- 贡献
- 72
- 兑换币
- 0
- 注册时间
- 2010-10-2
- 在线时间
- 27 小时
|
本帖最后由 E08610318 于 2010-10-2 10:54 编辑
我改了下,大家直接复制就可以了:
//现象B灯闪动,周期是1s,可用来记时.
//demo by whut_wj
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
#define INTVERAL 100
unsigned int i=1;
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 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;
PORTB=0Xff;
for(;;)
{
}
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 66 PIT0Interrupt(void)
{
PITTF_PTF0=1;
i++;
if(i==1000){
PORTB=~PORTB;
i=1;
}
} |
|