智能车制作

标题: 计时一秒的程序帮忙看看 [打印本页]

作者: lfm3399    时间: 2009-2-17 16:40
标题: 计时一秒的程序帮忙看看
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
int duan[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
int i;
void SET_PLL(void)
{ REFDV=3;
  SYNR=1;
while(CRGFLG_LOCK==0);
   CLKSEL=0x80;    //时钟初始化总线频率8MHz
}

void main(void)
{ EnableInterrupts;//开中断
  SET_PLL();
  TIOS=0X01;
//TIE=0X01;
  DDRB=0xff; // PTB as output
  TSCR1 = 0x80; // enable timer TCNT
  TSCR2 = 0x87; // TCNT prescaler setup
  PORTB=0x00;  // LEDs off
  TC0=0Xf424;
for (;;) {}
}
#pragma CODE_SEG NON_BANKED                           
void interrupt 16 TCNT_ISR(void)
{
DisableInterrupts;  //关中断
PORTB=duan[i];
i++;
if(i>9)
i=0;
TFLG2=0x80;
EnableInterrupts
}  

计时不准确,希望大家帮忙修改一下。
作者: redfox302    时间: 2009-2-20 09:40
这个程序能运行吗?
作者: whut_wj    时间: 2009-2-20 14:04
检查一下总线和分频




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