智能车制作

标题: 测速模块!!!!为什么单调时观察不到PORTB的数值变化呢? 程序在下面? [打印本页]

作者: huleishygirl    时间: 2011-4-6 00:34
标题: 测速模块!!!!为什么单调时观察不到PORTB的数值变化呢? 程序在下面?
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

unsigned int   Input_Num;

//----------------------时钟初始化------------------------------//
void PLL_Init(void)      //PLLCLK=2*OSCCLK*(SYNR+1)/(REFDV+1)
{                     //锁相环时钟=2*16*(2+1)/(1+1)=48MHz
  REFDV=1;            //总线时钟=48/2=24MHz
  SYNR=2;
  while(!(CRGFLG&0x08));
  CLKSEL=0x80;
}
//--------------------通道0输入捕捉初始化-------------------//
void ECT0_Init(void)            
{                          
  TSCR2=0x06;                   //禁止溢出中断,分频系数64(24/64MHz)
  TIOS_IOS0=0;                  //通道0为输入捕捉
  TCTL4=0x01;                   //捕捉上升沿
  TIE_C0I=1;                     //通道0输入捕捉中断允许
  TSCR1=0x80;                   //使能定时器
}

//----------------------主函数-------------------------//
void main(void)
{
  PLL_Init();
  ECT0_Init();
  DDRB=0XFF;
  PORTB=0X00;
  
  
  EnableInterrupts;
  //for(;;)
  {
  } /* wait forever */
  /* please make sure that you never leave this function */
}
//--------------------转速计算:-------------------------------//
//
//智能车转速子函数
//
//----------------------------------------------------------------//
#pragma CODE_SEG NON_BANKED    //定时器通道0输入捕捉中断         
void interrupt 8 Timer0_Onput(void)
{
  TFLG1_C0F=1;//清中断标志位      
  Input_Num++;
  PORTB=Input_Num;//Input_Num;
  
  if(Input_Num>=255)
  {
    Input_Num=0;
  }   
}   

作者: 很高很瘦    时间: 2011-9-19 09:21
哥们你用实时中断试试




欢迎光临 智能车制作 (http://dns.znczz.com/) Powered by Discuz! X3.2