- UID
- 795925
- 性别
- 女
|
现在以9S12DG128B单片机构成最小系统,设置锁相环、定时器和PWM模块,使得总线频率为24Hz,定时器模块的2到7口输出低电平,并产生PWM信号。把程序下载到MCU中,由5V的电源通过开关给单片机供电。现在的问题是上电后,所有的I/O口输出都是高电平(包括已经设置的定时器和PWM模块的输出);当按动复位键使MCU复位后,程序正常,端口按照要求正确输出。
请高人指点一下,为什么会出现这样的情况?理论上,当给单片机上电的时,MCU就应该完成初始化的过程并且while循环语句中!
程序如下:
#include <stdio.h>
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void MCUInit(void) {
DisableInterrupts;
CLKSEL &= 0x7f;
PLLCTL &= 0xbf;
SYNR = 0x05;
REFDV = 0x02;
PLLCTL |= (1<<6);
while ((CRGFLG&0x08) == 0x00);
CLKSEL |= (1<<7);
INTCR &= 0xbf;
COPCTL = 0x00;
EnableInterrupts;
}
void PWMInit(void)
{
DisableInterrupts;
PWMPOL |= (1<<1);
PWMCLK &= ~(1<<1);
PWMPRCLK = 0X00;
PWMCAE &= ~(1<<1);
PWMCTL = (1<<4);
PWMCNT01 = 0X0000;
PWMPER01 = 8000;
PWMDTY01 = 3000;
PWME |= (1<<1);
PWME |= (1<<0);
EnableInterrupts;
}
void TimerInit(void) //15
{
DisableInterrupts;
TSCR2 = 0X83;
TIOS_IOS0 = 0;
TIOS_IOS1 = 0;
DDRT = 0XFC;
PTT = 0X00;
TCTL4 = 0x0F;
// TIE_C0I = 1;
// TIE_C1I = 1;
// TSCR1_TEN = 1;
EnableInterrupts;
}
void main(void)
{
DisableInterrupts;
MCUInit();
TimerInit();
PWMInit();
EnableInterrupts;
while(1)
{
} /* wait forever */
/* please make sure that you never leave this function */
} |
|