|
void delays(unsigned int cy)
{
unsigned int i;
for(i = 0; i < cy; i++) {
NOP(); NOP(); NOP(); NOP();
NOP(); NOP();
}
}
// cm : clock source select
// CLK_32MRC : internal 32MHz RC
// CLK_32KRC : internal 32KHz RC
// CLK_MOSC : external 400K~32MHz crystal
// CLK_KOSC : external 32K~400K crystal
// cps : clock per-scalar
// CLK_DIV0 : no scalar
// CLK_DIV2 : clk/2
// CLK_DIV4 : clk/4
// CLK_DIV8 : clk/8
// ...
// CLK_DIV256: clk/256
void clock_init(unsigned char cm, unsigned char cps)
{
volatile unsigned char ctmp;
PMCR = 0x80; // PMCE enable
PMCR |= cm; // enable clock source
delays(32);
ctmp = PMCR;
ctmp &= 0x9f;
if(cm == CLK_MOSC)
ctmp |= 0x20;
PMCR = 0x80; // PMCE enable
PMCR = ctmp; // set clock source
delays(1);
// configure clock pre-scalar
CLKPR |= 0x80;
CLKPR |= cps;
delays(1);
}
我想把时钟改为外部的12M晶振,可总是有问题,能帮我看一下问题出在那吗? |
|