中级会员
- 积分
- 207
- 威望
- 185
- 贡献
- 22
- 兑换币
- 0
- 注册时间
- 2008-1-19
- 在线时间
- 0 小时
|
本人打算用8位脉冲累加器PACB。将PWM0口与PT1口相连,即用PWM0产生脉冲,用ECT1口进行脉冲累加,然后用串口将其显示出来。这样可以吗?以下是我的全部源程序。<BR>但在试验时遇到一个问题:点击RUN不能执行,即马上复位。点击STEP单步执行,可以执行,每进入中断就发一个数,但发送的数据好象有误。如果取消脉冲累加,就完全正常了。这是怎么回事?<BR><BR><BR><BR>#include <HIDEF.H>/* common defines and macros */<BR>#include <MC9S12DG128.H>/* derivative information */<BR>#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"<BR><BR>void init_PWM(void)<BR>{<BR>WME=0X00;<BR>PWMPRCLK=0x01; <BR>PWMSCLA=100; <BR>PWMCLK=0x01; <BR>PWMPOL=0x01; <BR>PWMCAE=0x00; <BR>PWMPER0=200; <BR>PWMDTY0=100; <BR>PWME=0x01; <BR>}<BR><BR>void init_SCI(void)<BR>{<BR>SCI0BDH=0x00;<BR>SCI0BDL=0x34; <BR>SCI0CR1=0; <BR>SCI0CR2=0x0C; <BR>}<BR><BR>void init_ECT (void)<BR>{<BR>TSCR1_TEN=0; <BR>TSCR2=0x07; <BR>TIOS_IOS0=1; <BR>TC0=0x7A12; <BR>TIE_C0I=1; <BR><BR>TIOS_IOS1=0; <BR>TCTL4=0x04; <BR>PBCTL_PBEN=0; //16位脉冲累加器B禁止<BR>PACN1=0; //PACN清零<BR>ICPAR_PA1EN=1; //设置八位脉冲累加器PA1EN<BR>PBCTL_PBOVI=1; //肞A1EN中断使能 <BR><BR>DLYCT=0x01; //延时<BR>TSCR1_TEN=1; <BR>}<BR><BR>void interrupt 8 READCOUNT(void)<BR>{<BR>TFLG1_C0F=1; //比较中断标志清零<BR>TC0+=0X7A12; <BR>while(!(SCI0SR1_TDRE))<BR>; <BR>SCI0DRL=PACN1;<BR>}<BR><BR>void main(void) <BR>{<BR>init_SCI();<BR>init_PWM();<BR>init_ECT();<BR>EnableInterrupts;<BR>for(;;)<BR>{} <BR>}<BR> |
|