Hey ,thank you very much for you help!Before i saw your message,i read the datasheet over and over again,then i found that when i added "CPMUPROT_PROT =0; CPMUCLKS_PLLSEL = 1;"before i set the register,the problem disappeared!!i do`nt know why because according to the datasheet,it is the default value! This is my code blow,but i found i can not set register "CPMUOSC"!when i wrote to it,the value did not change when i was debugging by TBDML,so the osc won`t work.Maybe i missed something importent...unhappy...
#include "PEE_BusClock.h"
void Set_PEE(byte _synr, byte _refdiv, byte _postdiv) {
CPMUPROT_PROT =0;
CPMUCLKS_PLLSEL = 1;
while(!CPMUCLKS_PLLSEL);
CPMUSYNR = _synr;
CPMUPOSTDIV = _postdiv;
CPMUREFDIV = _refdiv;
while (!CPMUFLG_LOCK);
CPMUOSC= CPMUOSC_OSCE_MASK+CPMUOSC_OSCBW_MASK+CPMUOSC_OSCFILT1_MASK;//enable external osc OSCE
while(!CPMUFLG_UPOSC) { //if osc up?
// you can check for timeout here with error message report
}
//while(!CPMUFLG_LOCK){ //if PLL LOCKED?
// you can check for timeout here with error message report
//}
//SET CLOCK
CPMUCLKS_PLLSEL = 1; //Bus = F(PLL)/2
//CPMUCLKS_COPOSCSEL = 1; //COP IS clocked from osc
while (CPMUCLKS != 0B10000000) {
asm nop;
}
}
//OSC = 4M
void SetBusClock16M_OSC4M() {
ECLKCTL_NECLK = 0; // enable ECLK output
Set_PEE(0X03,0X40,0X00);
}
/*
void SetBusClock24M_OSC4M() {
ECLKCTL_NECLK = 0; // enable ECLK output
Set_PEE(0X01,0X80,0X70);
}
void SetBusClock25M_OSC4M() {
ECLKCTL_NECLK = 0; // enable ECLK output
Set_PEE(0X58,0X03,0X00);
}
//OSC = 8M
void SetBusClock16M_OSC8M(){
ECLKCTL_NECLK = 0; // enable ECLK output
Set_PEE(0X01,0X80,0X00);
}
void SetBusClock24M_OSC8M(){
ECLKCTL_NECLK = 0; // enable ECLK output
Set_PEE(0X02,0X80,0X00);
}void SetBusClock25M_OSC8M(){
ECLKCTL_NECLK = 0; // enable ECLK output
Set_PEE(0X58,0X07,0X00);
}
*/