CPMUPROT =0x26; //停止保护时钟配置寄存器
CPMUCLKS =0x80; //允许PLL分频
CPMUSYNR =31; //设置分频因子
CPMUPOSTDIV=0x00; // Set the post divider register
CPMUPLL =0x10; // Set the PLL frequency modulation
while(CPMUFLG_LOCK == 0); /* Wait until the PLL is within the desired tolerance of the target frequency */
CPMUPROT=0x00; /* Enable protection of clock configuration registers */
}
//基于16M外部晶振
//byte nM 预设定的总线频率
//函数可能存在问题,仅供参考演示
void SetBusCLK_nM(byte nM)
{
MMCCTL1=0X00;
PKGCR =0X06;
DIRECT =0x00;
IVBR =0xFF;
ECLKCTL=0xC0;
CPMUPROT =0x26; //停止保护时钟配置寄存器
CPMUCLKS_PSTP=0; //
CPMUCLKS_PLLSEL=1; //应用PLL
//CPMUSYNR =nM-1; //设置分频因子
CPMUSYNR =0xc0|(nM-1); //设置分频因子
CPMUREFDIV =0x80|0x00; //pllclock=2*(1+SYNR)= MHz;
CPMUPOSTDIV=0x00; // Set the post divider register
CPMUPOSTDIV=0x00; // Set the post divider register
CPMUPLL =0x10; // Set the PLL frequency modulation
while(CPMUFLG_LOCK == 0); /* Wait until the PLL is within the desired tolerance of the target frequency */
CPMUPROT=0x00; /* Enable protection of clock configuration registers */
}
//-----------------------------------------------------
//-----PWM 初始化程序------//
void PWM_Init(void)
{
PWMPRCLK=0X00;
PWMSCLA=12;
PWMSCLB=12;
PWMCTL_CON45=1;
PWMCTL_CON67=1;
PWMCTL_CON23=1;
PWMCTL_CON01=1;
PWMCLK_PCLK1=1;
PWMCLK_PCLK5=1;
PWMCLK_PCLK3=1;
PWMCLK_PCLK7=1;
PWMPER45=10;
PWMPER23=10;
PWMPER67=200;
PWMPER01=3333;
PWMPOL_PPOL5=1;
PWMPOL_PPOL3=0;
PWMPOL_PPOL7=1;
PWMPOL_PPOL1=1;
PWMCAE =0x00;
PWMDTY67=1500;
PWME_PWME1=1;
PWME_PWME7=1;
}
/*void Motor_forward (void) //正转;占空比:duty
{
PWME_PWME7=1;
PWME_PWME3=0;
DDRP_DDRP3=1;
PTP_PTP3=0;
PWMDTY67=20;
}
void Motor_back (unsigned int duty) //反向?占空比:duty
{
PWME_PWME3=1;
PWME_PWME7=0;
DDRP_DDRP7=1;
PTP_PTP7=0;
PWMDTY23=duty;
}
void Motor_brake (void) //停机
{
PWME_PWME3=0;
PWME_PWME7=0;
DDRP_DDRP3=1;
DDRP_DDRP7=1;
PTP_PTP3=0;
PTP_PTP7=0;
}*/
void STEER( uint duty1)
{
PWMDTY01=duty1;
}
/****************定时器0初始化函数*************************/
/*void PIT0_init(void)//激光分时点亮,定时600us函数
{
PITCFLMT_PITE=0;//Close_time0();//关PIT定时
PITMTLD0=200-1;//8位定时器初值设定。160分频。频率0.4MHZ.即2.5us.
PITLD0=2000-1;//16位定时器0初值设定,定时240*2.5us=600us.
PITCE_PCE0=1;//使能通道0
PITMUX_PMUX0=0;//相应16位定时器也时基0连接
PITINTE_PINTE0=1;//开通PIT0定时器溢出中断
PITCFLMT_PITE=1;//使能PIT
}*/
/****************激光发射函数******************************/
//extern void Delay(unsigned int j);
void Open_sen(void)//3路激光发射管分时发射
{