智能车制作
标题:
怎么破!?测试程序出不了中断,无法正常测速
[打印本页]
作者:
天授
时间:
2010-5-22 16:06
标题:
怎么破!?测试程序出不了中断,无法正常测速
用编译器单步后,发现出不了中断~~for中根本不执行
求达人~~!!
int flag;
int n;
int x;
unsigned int sudu;
static unsigned int waittime ;
void delay(int x)
{
int i,j,k;
for(i=0;i<125;i++)
for(j=0;j<125;j++)
for(k=0;k<x;k++);
}
void duoji(int anger)
{
PWMDTY01=1000 + (anger + 45) * (1000 / 90);
}
static void PWM_Init(void)
{
PWMCTL_CON01=1; //0和1联合成16位PWM;
PWMCAE_CAE1=0;
PWMCAE_CAE3=0;
PWMCAE_CAE2=0; //选择输出模式为左对齐输出模式
PWMCNT01 = 0;
PWMCNT3 = 0;
PWMCNT2 = 0; //计数器清零;
PWMPOL_PPOL1=1;
PWMPOL_PPOL3=1;
PWMPOL_PPOL2=1; //先输出高电平,计数到DTY时,反转电平
PWMPRCLK = 0X40; //clockA不分频,clockA=busclock=16MHz;CLK B 16分频:1Mhz
PWMSCLA = 8;
PWMSCLB = 50; //对clock SA 进行2*8=16分频;pwm clock=clockA/16=1MHz;
PWMCLK_PCLK1 = 1;
PWMCLK_PCLK3 = 1;
PWMCLK_PCLK2 = 1; //选择clock SA做时钟源
PWMPER01 = 20000; //周期20ms; 50Hz;(可以使用的范围:50-200hz)
PWMDTY01 = 1500;
PWMPER3 = 200;
PWMPER2 = 200;
PWMDTY3 = 0;
PWMDTY2 = 0;
PWME_PWME1 = 1;
PWME_PWME3 = 1;
PWME_PWME2 = 1;
}
void setbusclock(void) //PLL setting
{
CLKSEL=0X00; //disengage PLL to system
PLLCTL_PLLON=1; //turn on PLL
SYNR=1;
REFDV=1; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=32MHz;
_asm(nop); //BUS CLOCK=16M
_asm(nop);
while(!(CRGFLG_LOCK==1)); //when pll is steady ,then use it;
CLKSEL_PLLSEL =1; //engage PLL to system;
}
//--------------------定时器初始化------------------//
void ECT0_Init(void)
{
TIOS=0x01; //定时器通道0设置为输出比较
TC0=0x1388; //赋初值,当TCNT从0计数到此值时第一次进入中断
TCTL2=0x02; //其他七路与定时器断开 执行的动作时:0通道输出清零
TSCR2=0x07; //溢出中断禁止 32M/128=4微秒,计一个数用4微秒
TSCR1=0x80; //使能定时器
TIE=0x01; //通道0输出比较中断允许
}
void Pulse_int(void) //脉冲累加器初始化
{
// TSCR1_TEN =1;
PACTL_PAEN =0;
PACTL_PAMOD=0 ;
PACTL_PEDGE=0 ;
PACTL_PAOVI=0;
PACTL_PAI = 1;
PACNT=0;
PAFLG_PAOVF=1;
PAFLG_PAIF =1;
PACTL_PAEN =1;
}
unsigned int speed_get(void)
{ unsigned int speed;
speed = PACNT;
PACNT = 0;
return speed;
}
unsigned int speed(unsigned int m)
{ unsigned int s;
s=10*m/105;//转每秒
return s;
}
//-----------------------主函数------------------------//
void main(void)
{
unsigned int y=0;
Pulse_int();
setbusclock();
ECT0_Init();
PWM_Init();
flag=1;
x=0;
n=0;
sudu=0 ;
waittime=0;
DDRA=0xFF;
EnableInterrupts;
for(;;)
{ //EnableInterrupts;
if(flag==1)
{
n++;
}
if(n==10)
{ flag=0;}
if(flag==0)
{ n--;}
if(n==0)
{ flag=1;}
x=10*n-25;
// duoji(x);
if(flag==1)
{
PWMDTY2=0;
PWMDTY3 =20*n;
}
if(flag==0)
{
PWMDTY3=0;
PWMDTY2 =20*n;
}
delay(1);
y=speed(sudu);//获得速度
if(y>=50)//大于50转每秒
{
n=0;
}
}
}
//-----------------------中断函数处理-------------------//
#pragma CODE_SEG NON_BANKED
void interrupt 8 Timer0_ISR(void) //8为定时器通道0的中断标号
{
unsigned int m;
TFLG1_C0F=1;//清中断标志位
//DisableInterrupts;
m=TCNT;
TC0=m+5000; //5000*4us=20ms定时时间
waittime++;
if(waittime>=10)
{ PORTA_PA0=~PORTA_PA0;//led灯
sudu=speed_get();
waittime=0;
}
}
#pragma CODE_SEG DEFAULT
复制代码
作者:
jiutian0396
时间:
2010-5-27 08:42
你试一下中断函数里关中断看看,还有就是主函数中应该先关中断,再初始化,再开中断
作者:
素情王子
时间:
2010-6-27 13:16
作者:
mashaokang1111
时间:
2010-7-15 21:40
改prm文件了么....??
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2