各位,正在学习笙泉的单片机,我拿了例程中的程序,一块擦除的82E54(保证里面都是FF)烧写好芯片之后,运行一次,为什么用U2烧录器读出来的0X03400(起始IAP地址)还是FF?也就是说没写进去呢?
因为在我的程序里不能写不能读,没办法做这个实验,想用U2来读看一下,可读出来的还是FF,问题出在哪呢?
typedef struct IAP_Addr
{ unsigned char Low ;
unsigned char High ;
};
#define AP_End_Addr 0x033FF
#define IAP_Start_Addr 0x03400
#define IAP_End_Addr 0x037FF
#define Xtal_Freq 0x24 // Unit:MHz-------------24M晶振
#include "REG_MPC82L54.H"
void IAP_Write_512B (void) ;
void IAP_Write_Byte(unsigned int, unsigned char,unsigned char) ;
void IAP_Fail(void);
unsigned char Trigger_Check1=0x55;
void main(void)
{ P37=1;
IAP_Write_512B() ;
P37=0;//程序执行一次亮红灯,按理来说已经写好IAP才对,但0X03400里面的内容 还是FF,不明白怎么回事
while (1) {}
}
void IAP_Write_512B (void)
{ unsigned int IAP_Addr=IAP_Start_Addr;
unsigned int IAP_Addr_Up_Bundary=IAP_Start_Addr+0x0200 ;
for(;IAP_Addr<IAP_Addr_Up_Bundary;IAP_Addr++)
IAP_Write_Byte(IAP_Addr,5,0xAA) ;
}
void IAP_Write_Byte(unsigned int IAP_Addr, unsigned char Value,unsigned char Trigger_Check2)
{
ISPCR = ISPCR | 0x81 ;
IFADRH = IAP_Addr >> 8; //IAP Flash Address High Byte
IFADRL = IAP_Addr & 0xFF; //IAP Flash Address Low Byte
IFD = Value ; //Flash data buffer
IFMT = 0x02 ; //IAP Flash Mode Table (Write Mode)
if (Trigger_Check1==0x55)
SCMD = 0x46 ;
else
IAP_Fail() ;
if (Trigger_Check2==0xAA)
{ SCMD = 0xB9 ;
}
else
{ SCMD = 0x00 ;
IAP_Fail() ;
}
Trigger_Check2=0x00;
ISPCR = ISPCR & 0x7F ;
}
///////////////////////////////////////////////////
//
// IAP_Fail()
//
///////////////////////////////////////////////////
void IAP_Fail(void)
{ P24=0 ;//出错的话亮指示灯
while(1) ;
} |