- UID
- 825548
|
程序如下,没有写进去,FCCF位一直是1,为什么??
哪有问题了??
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#define UINT8 unsigned char
#define UINT16 unsigned int
/****************总线时钟设置 busfre=8MHz*******************/
void PLL_Init (void) //FEI-->FBE--> PBE-->PEE busfre=8MHz
{
SOPT1=0x00;
MCGC2=0x36;//00110110
//BDIV=00 总线频率=?/1
//RANGE=1 选择高频范围
//HGO=1 高增益模式
//LP=0 旁路模式激活PLL、FLL
//EREFS=1 选择振荡器
//ERCLKEN=1 外部时钟使能
//EREFSTEN=0 停止状态时禁用
while(!MCGSC_OSCINIT); //循环检测 EREFS选择的晶体初始化完成
MCGC1=0xB8; //10111000 ///////////////FEI-->FBE ///////////////////
//CLKS=10 选择外部参考时钟
//RDIV=111 4MHz/128=31.25KHz
//IREFS=0 选择外部参考时钟
while(MCGSC_IREFST); //循环检测 外部参考是否是当前时钟参考
while((MCGSC_CLKST)^(0x02)); //循环检测
MCGC2_LP=1;
MCGC1=0x90; //10010000 ////////////////FBE-->BLPE//////////////////
//CLKS=10
//RDIV=010 4MHz/4=1MHz
//IREFS=0
MCGC3=0x44; //01000100
//PLLS=1
//VDIV=0100 1MHz*16=16MHz
MCGC2_LP=0; //////////////BLPE-->PBE////////////////////////
while(!MCGSC_PLLST);
while(!MCGSC_LOCK); //循环检测
MCGC1=0x10; //00010000 ///////////////PBE-->PEE//////////////////
//CLKS=00 选择PLL输出为系统时钟源
//RDIV=010 4MHz/4=1MHz
while((MCGSC_CLKST)^(0x03)); // 循环检测
// MCGOUT=1MHz*16/1=16MHz busfre=MCGOUT/2=8MHz
}
void FCLK_Init()
{
FCDIV=39; //PRDIV8=0,DIV=39 fFCLK=200kHz
}
UINT8 Page_Erase(UINT8 Adress)
{
if(FSTAT&0x10) //check to see if FACCERR is set
{
FSTAT=FSTAT|0x10; //write 1 to FACCERR to clear
}
(*((volatile UINT8*)(Adress)))=0xaa; //write to somewhere in flash
FCMD=0x40; // set command type sector erase
FSTAT=FSTAT|0x80; //put FCBEF at 1
_asm NOP;
_asm NOP;
_asm NOP;
_asm NOP; //wait four cycles
if(FSTAT&0x30) //check to see if FACCERR or FPVIOL are set
{
return 0x00; //if so ,Error
}
while (!(FSTAT&0x40)); //wait for command to complete
return 0x01;
}
UINT8 Program_Byte(UINT16 Adress,UINT8 data)
{
if(FSTAT&0x10) //check to see if FACCERR is set
{
FSTAT=FSTAT|0x10; //write 1 to FACCERR to clear
}
(*((volatile UINT16*)(Adress)))=data; //write data to somewhere in flash
FCMD=0x20; // set command type byte program
FSTAT=FSTAT|0x80; //put FCBEF at 1
_asm NOP;
_asm NOP;
_asm NOP;
_asm NOP; //wait four cycles
if(FSTAT&0x30) //check to see if FACCERR or FPVIOL are set
{
return 0x00; //if so ,Error
}
while (!(FSTAT&0x40)); //wait for command to complete
return 0x01;
}
void main(void)
{
UINT8 temp1,temp2;
PLL_Init();
FCLK_Init();
DisableInterrupts;
temp1=Page_Erase(0xFF00);
temp2=Program_Byte(0xFF00,0x00);
for(;;);
} |
|