高级会员
- 积分
- 555
- 威望
- 351
- 贡献
- 134
- 兑换币
- 4
- 注册时间
- 2010-11-25
- 在线时间
- 35 小时
|
程序如下,进不了中断,不知为什么
请指教!
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
volatile uint speed_back=0,temp=0;
void delay_ms(uint ms)
{
volatile uint x=0;
while(ms--)
{
for(x=2800;x>0;x--)
{
_asm(nop);
_asm(nop);
_asm(nop);
_asm(nop);
_asm(nop);
_asm(nop);
}
}
}
void Init_PLL(void)
{
CLKSEL = 0X00; //disengage PLL to system
PLLCTL_PLLON = 1; //turn on PLL
SYNR = (0xc0|0x18); //SYDIV=0X18=24
REFDV = (0x40|0x07); //REFDIV=0X07=7
POSTDIV = 0x00; //pllclock=2*osc*(1+SYDIV)/(1+REFDIV)=100MHz;
_asm(nop); //BUS CLOCK=50M
_asm(nop);
_asm(nop);
_asm(nop);
_asm(nop);
_asm(nop);
_asm(nop);
_asm(nop);
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL = 1; //engage PLL to system;
}
//500us one interrupt
void Init_PIT_Timer(void)
{
PITCFLMT=0X00;
PITCE|=0X07;
PITMUX|=0X04;//BASED 0 timer2 based 1
PITMTLD1=49; //
PITLD2=2499; //temer 2 2.5MS一次中断
PITTF|=0x07; //clear interrupt falg
PITINTE|=0X07;//ENABLE TIMER0 INTERRUPT
PITCFLMT|=0X80;
//time-out period = (PITMTLD + 1) * (PITLD + 1) / fBUS.
//For example, for a 50 MHz bus clock, the maximum time-out period equals:
//256 * 65536 * 20 ns = 419.43 ms.
}
void Init_Event_Count(void)
{
PACTL = (1<<6);//脉冲累加器启动,外部发生一次下降沿就计数一次。外部编码器连接到IOC7.
//在中断里读取PACNT的值就是脉冲个数。读取后清零PACNT。
}
void UART_Init(void)
{
SCI0CR2 = 0x0C;
SCI0BDH = 0x00;
SCI0BDL = 0xa2;
/****************************************************
当波特率为19200,主频为50MHZ时:
SCI0BDH=0x00;
SCI0BDL=0xa2;
实际波特率是:19170
当波特率为9600,主频为50MHZ时:
SCI0BDH=0x01;
SCI0BDL=0x46;
实际波特率是:9585
****************************************************/
}
void UART_Send(uchar data)
{
while(!(SCI0SR1&0x80));//keep waiting when not empty
SCI0DRL = data;
}
void main(void) {
Init_PLL();
UART_Init();
Init_Event_Count();
Init_PIT_Timer();
/* put your own code here */
EnableInterrupts;
for(;;) {} /* wait forever */
/* please make sure that you never leave this function */
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 68 timer2(void)
{
_asm(MOVB #$07,PITTF); //clear interrupt falg
temp++;
if(temp>3) //10MS 读取一次速度
{
speed_back = PACNT;//返回速度值
PACNT = 0;//速度归零
UART_Send(speed_back&0X00FF);
speed_back=0;
temp=0;
}
}
#pragma CODE_SEG DEFAULT |
|