智能车制作

标题: 定时器 [打印本页]

作者: xbhan_06    时间: 2009-3-27 15:58
标题: 定时器
int tim0 = 0,timer_num0 = 0,timer_num = 0;
byte stop_sign = 0,power_sign = 0;
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt MDC_USE(void)     //定时器中断函数
{            
  MCCNT = 40;     
  MCFLG = 0x80;   
  tim0++;            
  if(tim0==20000)      
  {     
    tim0=0;
    PORTB_BIT0=~PORTB_BIT0;   
  }  
  
  timer_num0++;
  if(timer_num0==2000)      
     PORTB = 0X80;      
  if(!stop_sign)
  {
    if(timer_num==0)        // OPEN THE photoelectric cell
    {         
        PORTB = 0X40;
    }
    timer_num++;         
    if(timer_num==21)         
    {               
        timer_num=0;
        PORTB = 0X20;
    }
  }
  else
  {                     
   
  }  
}
#pragma CODE_SEG DEFAULT
void MDCInit(void)
{
  MCCTL = MCCTL&0Xfb;
  MCCTL = 0Xe1;         
  MCCTL = MCCTL|0X04;   
  MCCNT = 40;     
  MCCTL = MCCTL|0X08  ;
}

void main(void)
{
  DDRB = 0XFF;
  MDCInit();
  EnableInterrupts;
  for(;;)
  {} /* wait forever */
  /* please make sure that you never leave this funct
定时器跑不起来,有没有高手解决一下?




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