中级会员
- 积分
- 400
- 威望
- 283
- 贡献
- 107
- 兑换币
- 0
- 注册时间
- 2011-2-14
- 在线时间
- 5 小时
|
#include<hidef.h>
#include<mc9s12xs128.h>
#pragma LINK_INFO DERIVATIV"mc9s12xs128b"
#define PITTIME 200000//设定为1000毫秒定时
uchar count=0,t=0;
void setbusclock(void)//32MHZ外部时钟为16MHZ
{
CLKSEL=0X00;//
PLLCTL_PLLON=1;//打开时钟
SYNR=0X40|0X03;
REFDV=0X80|0X01;
//SYNR=1;//PLLCLK=2*FOSC*(SYNR+1)/(REFDV+1)
//REFDV=1;
POSTDIV=0X00;//4:0,FPLL=FVCO/(2XPOSTDIV)
_asm(nop);//BUS CLOCK=16M
_asm(nop);
while(!(CRGFLG_LOCK));//WHEN PLL IS STEADY ,THEN USE IT
CLKSEL_PLLSEL=1;//engage PLL system;
}
void PWM_Init(void)
{
PWMPOL=0X20;
PWMCAE=0X00;
PWMCTL=0X00;
PWMPRCLK=0X20;
PWMSCLA=0X05;
PWMPER5=0X08;
}
void PIT_Init(void)//定时中断初始化函数1000MS定时中断设置
{
PITCFLMT_PITE=1;
PITFLT=1;
PITCE=1;
PITINTE=1;
PITMTLD0=160-1;
PITLD0=PITTIME-1;
}
//脉冲累加器初始化,实现脉冲测速。
//PIT7口
void initPACA(void)
{
PACTL=0X50;//PT7上升沿脉冲计数
PACNT=0X00;//累加器初始值
}
void main(void)
{
EnableInterrupts;
setbusclock();
PIT_Init();
PWM_Init();
initPACA();
for(;;)
{
}
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 66 PIT7Interrupt(void)
{ PORTB^=0xff;
PITTF_PTF0=1;
count++;
t=PACNT;
} |
|