金牌会员
- 积分
- 1252
- 威望
- 764
- 贡献
- 366
- 兑换币
- 344
- 注册时间
- 2009-12-5
- 在线时间
- 61 小时
|
/现象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,可是做出来后效果却不是为什么 |
|