我把时间调长了还是那个样子,郁闷的不行了
能不能帮我看看程序啊 谢谢各位大侠!!!!
我用的是清华的dg128的开发板
#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
int k,l;
int PWM1(int ad)
{
int ux;
PWME_PWME1 = 0x01;
PWMPRCLK = 0x04;
PWMCLK=0x03;
PWMSCLA=20;
PWMPOL_PPOL1 =0x01;
PWMCNT1 = 0;
PWMPER1 = 255;
ux=15+ad;
PWMDTY1 = ux;
}
PWM0(int add){
int us;
PWME_PWME0 = 0x00;
PWMPRCLK = 0x04;
PWMCLK=0x03;
PWMSCLA=20;
PWMPOL_PPOL0 =0x01;
PWMPER0 = 255;
PWMCNT0 = 0;
PWME_PWME0 = 0x01;
us=20+add ;
PWMDTY0 =us;
}
void findway(void) {
switch(PORTA)
{
case 0x40:k=-4,l=30,PORTB=0XFD;break; //-6
case 0x20:k=-2,l=20,PORTB=0XFB;break; //-4
case 0x10:k=-1,l=10,PORTB=0XF7;break; //-2
case 0x08:k=0,l=0,PORTB=0XEF;break; //0
case 0x04:k=1,l=10,PORTB=0XDF;break; //2
case 0x02:k=2,l=20,PORTB=0XBF;break; //4
case 0x01:k=4,l=30,PORTB=0X7F;break; //6
default: k=k,PORTB=0X00;
}
}
void MCU_init(void)
{
RTICTL = 0xE4;
CRGFLG = 0x80;
CRGINT = 0x80;
}
void interrupt RTI_Int()
{
CRGFLG=0x80;
PWM0(k);
}
void main(void) {
MCU_init();
EnableInterrupts;
for(;;) {
findway();
PWM1(l);
}
}
|