智能车制作
标题:
求大神帮助xs128,tim捕获功能的一个程序
[打印本页]
作者:
风烟群起
时间:
2015-1-23 16:10
标题:
求大神帮助xs128,tim捕获功能的一个程序
通过pp1发出pwm脉冲作为pt0信号,通过中断使pb口的外接led闪烁,结果没闪,求大神帮助
作者:
风烟群起
时间:
2015-1-23 16:11
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#define LEDCPU PORTB
#define LEDCPU_dir DDRB
#define BUS_CLOCK 32000000
#define OSC_CLOCK 16000000
unsigned int delaytime;
unsigned int time1;
unsigned int time2;
//锁相环初始化
void INIT_PLL(void)
{
CLKSEL &=0X7F;
PLLCTL &=0X8F;
CRGINT &=0XDF;
#if(BUS_CLOCK==40000000)
SYNR=0X44;
#elif(BUS_CLOCK==32000000)
SYNR=0X43;
#elif(BUS_CLOCK==24000000)
SYNR=0X42;
#endif
REFDV=0X81;
PLLCTL=PLLCTL|0X70;
asm NOP;
asm NOP;
while(!(CRGFLG&0X08));
CLKSEL|=0X80;
}
//etc模块初始化
void initialize_ect(void)
{
TSCR1_TFFCA=1;
TSCR1_TEN=1;
TIOS=0XFE;
TCTL4=0X01;
TIE=0X01;
TSCR2=0X07;
TFLG1=0XFF;
TFLG2=0XFF;
}
//pwm初始化
void init_pwm(void)
{
PWMCTL_CON01=1;
PWMPOL_PPOL1=1;
PWMPRCLK=0X55;
PWMSCLA=100;
PWMSCLB=100;
PWMCLK=0X02;
PWMCAE=0X00;
PWMPER01=500;
PWMDTY01=250;
PWME_PWME1=1;
}
#pragma CODE_SEG_NEAR_SEG NON_BANKED
interrupt void capture(void)
{
if(TFLG1_C0F==1)
TFLG1_C0F=1;
time1=time2;
time2=TC0;
delaytime=time2-time1;
LEDCPU=~LEDCPU;
}
#pragma CODE_SEG DEFAULT
void main(void) {
DisableInterrupts;
INIT_PLL();
initialize_ect();
init_pwm();
LEDCPU_dir=0XFF;
EnableInterrupts;
LEDCPU=0X00;
for(;;){}
}
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2