Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/31/07 00:55
Read: times


 
#143793 - about the IAP function of P89V51RD2BN
Now I worked on P89V51RD2BN
I have some program and hope someone to help me .
When I program the P89V51RD2 with its ISP via scom ,It worked well.But When I program the program via the IAP routine through SCOM ,it doesn't work . it notify that "unable to connect at the specifed rate,try reducint the baut rate and reset the device into ISP mode ". I can't enter ISP mode and can't program via scom any more.

someone tell me that I had called IAP API from block 0 ,when I call IAP API of P89V51RD2BN which then wrok on block 1 so that I have overwritten parts of the bootload of P89V51RD2BN.
But I have call IAP API above 0x1FFF .I have located Function_Test() at 0x4000.
I don't know what happened .

So will anybody tell me when to call IAP API of P89V51RD2BN



Attach file is the hex file of problem

So any one help me .Thanks in advance.
/* Following is my program*/

#include " reg52.h"
#define uint unsigned int
#define uchar unsigned char
typedef uint WORD
typedef uchar BYTE

#define SCON8B 0xd0
#define SCON9B 0xf0


sfr FCF = 0xB1;
sfr FFS = 0xB2;
sfr FAL = 0xB3;
sfr FAH = 0xB4;
sfr FDAT = 0xB5;
sfr FST = 0xB6;

/***************************************************
name: IAP_Wait
function: wait untill IAP operation finishing
Input: none
Output:none
***************************************************/
void IAP_Wait( void )
{
while ( (FST & 0x04) != 0 ); //check bit FST.2 1:busy 0:idle
}

/**********************************************************
name: IAP_Read(WORD addr)
function: read the data at the flash address
Input: flash address
Output:data readed from flash
***********************************************************/
BYTE IAP_Read(WORD addr)
{
BYTE c;
FCF |= 0x40; //SETB FCF.6
FAH=addr>>8; // get the higher 8 bit of the address
FAL=addr&0x00ff; //get the lower 8 bit of the address
FFS = 0x0C; //select funtion number 3:read user code or data
c = FDAT;
return c; //rerun user code or data
}


/**********************************************************
name: IAP_Program()
function: program the data or code into specified flash address
Input: flash address
Output:status of IAP program operation 0: sucess,1:fail
***********************************************************/
bit IAP_Program(BYTE addr,BYTE dat)
{
BYTE d;

FCF |= 0x40; //SETB FCF.6

FAH=addr>>8; // get the higher 8 bit of the address

FAL=addr&0x00ff; //get the lower 8 bit of the address
FDAT = dat;
FFS = 0x0E; //select IAP function number02 :program user code by byte
IAP_Wait(); //wait for finishing of IAP operation
d = IAP_Read(addr); //verity the data or code with the byte which was programed just now
if ( d == dat )
return 0;
else
return 1;
}



/**********************************************************
name: IAP_SectorErase( WORD sector )
function: Erase the flash by sector
Input: sector number 0< sector number <511
Output:none
***********************************************************/
void IAP_SectorErase(WORD sector)
{
WORD addr;
if ( sector >= 512 ) return;
// addr.i = sector * 128;
addr=sector*128;
FCF |= 0x40; //SETB FCF.6
// FAH = addr.CharPart.H;
FAH = addr>>8; // get the higher 8 bit of the address
// FAL = addr.CharPart.L;
FAL= addr&0x00ff; //get the lower 8 bit of the address
FFS = 0x0B; //select IAP function number 08:Erase user code in sector
IAP_Wait(); //wait for finishing of IAP operation
}



//function : send byte one time
void SendChar(unsigned char c)
{
SBUF = c;
while (!TI);
TI = 0;

}

//function: serial port intialize set buadroat at 57600
void Init_Serial(void)
{
SCON = scon9b; /*Timer 1 is being used to generate baud rates.*/
TMOD = 0x21; //T/C0 mode 1 timer; T/C1 mode2 timer
TH1 = 0xFF; //57600
PCON = 0x80; /* buad rate *2 */
TR1 = 1; /*TCON.6*/
ES = 1; /*IE.4 */
IP = 0x0;
EA=0; // close interrupt

}



/* test the basic IAP operation of P89V51RD2BN
basic operation: program read erase
*/
void Function_Test( void )
{
IAP_SectorErase(128); //Erase sector 128
IAP_SectorErase( 129 ); //Erase sector 129
TestFlag=IAP_Program( 0x6000,0xaa ); // program 0xaa at 0x6000
if( !TestFlag )
{
SendChar( 0xaa ); // to notify that operation of programing ,vetifying ,reading are all correct
}
else
{
SendChar( 0xbb ); //to notify that operation of IAP is failing
}
}





void main()
{
Init_Serial(); // initialize the serial com
Function_Test(); // call the function to test the basic IAP operation
while( 1 )
{
SendChar( 0xcc );
Delayms( 1000);
}
}

List of 2 messages in thread
TopicAuthorDate
about the IAP function of P89V51RD2BN            01/01/70 00:00      
   but that _is_ really the problem            01/01/70 00:00      

Back to Subject List