1# xinuaile2003
MPC82G516A 的IAP出厂设置应该是从0xF000开始,IAP=3KB容量,如果你有U1 writer,可以从上选择MPC82G516A看到,你要使用超过3KB的IAP的话,只好再用U1 writer重新设定咯,不然就要找一下他们的代 ...
hhtseng 发表于 2009-10-6 09:59 
我已经查到了出厂设置的IAP空间是从0xF000 - 0xFBFF的3K空间,我的操作空间是0xF000 - 0xF1FF,可是就是无法实现IAP操作。到官网下载了示例代码,也是同样的效果,写完N个数据之后,读出时,数据总是最后一次写入的值,该值我认为是最后一次保存在IFD寄存器当中的。
以下是官网下的示例代码,我只是在主函数把单个写入,单个读出改成多个一起写入,然后一起读出。
///////////////////////////////////////////////////
//
// FILE: MPC89_IAP_Demo.c
// AUTHOR: Neo (Hsin-Chih Lin)
// COPYRIGHT: (c) Megawin Technology Co., Ltd.
// CREATED: 2008.5.20
// PURPOSE: Demo IAP & UART Function
//
///////////////////////////////////////////////////
//#include "REG_MPC89L51-515.H"
//#include "REG_MPC82L54.H"
#include "REG_MPC82G516.H"
//#define IAP_ADDRESS 0x1000//MPC89x51
//#define IAP_ADDRESS 0x2000//MPC89x52
//#define IAP_ADDRESS 0x4000//MPC89x54
//#define IAP_ADDRESS 0x8000//MPC89x58
//#define IAP_ADDRESS 0x1800//MPC82x52 default value
//#define IAP_ADDRESS 0x3400//MPC82x54 default value
#define IAP_ADDRESS 0xF000//MPC82G516 default value
void Erase_IAP(unsigned int);
void Write_IAP(unsigned int, unsigned char);
unsigned char Read_IAP(unsigned int);
///////////////////////////////////////////////////
//
// MainLoop()
//
///////////////////////////////////////////////////
void main(void)
{
unsigned int IAP_Address , Count_Address;
unsigned int i;
unsigned char Uart_Data;
IAP_Address = IAP_ADDRESS; //Set IAP start address
P1 = 0x7f; //Turn off all LED
Erase_IAP(IAP_Address); //Erase One page (512 bytes)
for(i=0;i<128;i++)
{
Count_Address=IAP_Address+i;
Write_IAP(Count_Address,i); //Write IAP a byte
}
for(i=0;i<128;i++)
{
Count_Address=IAP_Address+i;
Uart_Data=Read_IAP(Count_Address); //Read IAP a byte
}
P1=0x00; //Turn on all LED
while (1)
{
;
}
}
///////////////////////////////////////////////////
//
// Function:Erase_IAP()
// Erase One page (512 bytes)
//
///////////////////////////////////////////////////
void Erase_IAP(unsigned int IAP_Address)
{
IFADRH = IAP_Address >> 8; //IAP Flash Address High Byte
IFADRL = IAP_Address & 0xFF; //IAP Flash Address Low Byte
IFMT = 0x03 ; //IAP Flash Mode Table (Erase Mode)
ISPCR = 0x84 ; //Enable IAP to change flash
SCMD = 0x46 ; //Trigger IAP memory
SCMD = 0xB9 ;
}
///////////////////////////////////////////////////
//
// Function:Write_IAP()
// Write to IAP address one byte
//
///////////////////////////////////////////////////
void Write_IAP(unsigned int IAP_Address, unsigned char Value)
{
IFADRH = IAP_Address >> 8; //IAP Flash Address High Byte
IFADRL = IAP_Address & 0xFF; //IAP Flash Address Low Byte
IFD = Value ; //Flash data buffer
IFMT = 0x02 ; //IAP Flash Mode Table (Write Mode)
ISPCR = 0x84 ; //Enable IAP to change flash
SCMD = 0x46 ;
SCMD = 0xB9 ;
}
///////////////////////////////////////////////////
//
// Function:Read_IAP()
// Read one byte from IAP address
//
///////////////////////////////////////////////////
unsigned char Read_IAP(unsigned int IAP_Address)
{
IFADRH = IAP_Address >> 8; //IAP Flash Address High Byte
IFADRL = IAP_Address & 0xFF; //IAP Flash Address Low Byte
IFMT = 0x01 ; //IAP Flash Mode Table (Read Mode)
ISPCR = 0x84 ; //Enable IAP to change flash
SCMD = 0x46 ;
SCMD = 0xB9 ;
return(IFD); //Return Flash data
}
|