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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/12/06 03:48
Read: times


 
#126263 - IAP code example...
Responding to: ???'s previous message
Hello Arvind,

I am cutting and pasting some code snippets which I have used to store and recover passwords and other parameters.

You will have to adapt this to the P89V51RD2, if there are any changes, mostly they may be minor.

If I remember correctly, the orgiginal sources are from Flash Magic website and Philips application notes. Flash Magic website has wealth of information on IAP.

The code may not be complete. Place each of them in different souces files.

;===========================================================================
; 05/06/2002 - Modular 'C' SOURCE CODE for various products
;===========================================================================
; MODULE : This is the flash asm module
; FILENAME : flash.a51
; PROGRAMMER : John D. Maniraj
; HISTORY : 05/07/2004
; DISCRIPTION : This code will read and write to flash
; HARDWARE : Worked on 06/07/2004
; uCONTROLLER : 89C51RD2BN
;===========================================================================
$NOMOD51

; module name
NAME FLASHA

; segments in this library
?PR?_WriteFlashByte?FLASHA SEGMENT CODE
?PR?_ReadFlashByte?FLASHA SEGMENT CODE

; function names and global variables
PUBLIC _WriteFlashByte
PUBLIC _ReadFlashByte

; SFRs and sbits required
DPH DATA 083H
DPL DATA 082H
AUXR1 DATA 0A2H
EA BIT 0AFH
CMOD DATA 0D9H
ACC DATA 0E0H
IE DATA 0A8H

;============================================================================
;write flash byte
;============================================================================
RSEG ?PR?_WriteFlashByte?FLASHA
_WriteFlashByte:
PUSH IE ; save interrupts
CLR EA ; disable interrupts
MOV A,CMOD
MOV R2,A ; store copy of CMOD
JNB ACC.6,?IAPTAG11 ; if watchdog enabled then disable
ANL CMOD,#0BFH
?IAPTAG11:
ORL AUXR1,#020H ; enable bootrom
MOV R0,#20 ; osc frequency 20MHz
MOV R1,#02H
MOV DPH,R4 ; address to program
MOV DPL,R5
MOV A,R7 ; data to write
CALL 0FFF0H ; call iap routine
MOV R7,A ; id in accumulator
ANL AUXR1,#0DFH ; disable bootrom
MOV CMOD,R2 ; restore CMOD (restore watchdog state)
POP IE ; restore interrupts to initial state
RET
;============================================================================
;read flash byte
;============================================================================
RSEG ?PR?_ReadFlashByte?FLASHA
_ReadFlashByte:
PUSH IE ; disable interrupts
CLR EA
MOV A,CMOD
MOV R2,A ; store copy of CMOD
JNB ACC.6,?IAPTAG12 ; if watchdog enabled then disable
ANL CMOD,#0BFH
?IAPTAG12:
ORL AUXR1,#020H ; enable bootrom
MOV R0,#20 ; osc frequency 20MHz
MOV R1,#03H
MOV DPH,R6 ; address to program
MOV DPL,R7
CALL 0FFF0H ; call iap routine
MOV R7,A ; id in accumulator
ANL AUXR1,#0DFH ; disable bootrom
MOV CMOD,R2 ; restore CMOD (restore watchdog state)
POP IE ; restore interrupts to initial state
RET
END
;============================================================================


//===========================================================================
// 05/06/2002 - Modular 'C' SOURCE CODE for various products
//===========================================================================
// MODULE : This is the flash module
// FILENAME : flash.c
// PROGRAMMER : John D. Maniraj
// HISTORY : 05/07/2004
// DISCRIPTION : This code will read and write to flash
// HARDWARE :
// uCONTROLLER : 89C51RD2BN,89C669
//===========================================================================
#define _FLASH_ // this module
//===========================================================================
extern Byte WriteFlashByte(Byte FlashData, Word FlashAddress);
extern Byte ReadFlashByte(Word FlashAddress);
//===========================================================================
//Function prototypes
//===========================================================================
void WriteFlashWord(Word FiveDigitNumber, Word FlashAddress,Byte Segment);
Word ReadFlashWord(Word FlashAddress,Byte Segment);
//===========================================================================
void WriteFlashWord(Word FiveDigitNumber, Word FlashAddress)
{
static volatile Byte data HighByte;
static volatile Byte data LowByte;
LowByte=FiveDigitNumber;HighByte=FiveDigitNumber>>8;
WriteFlashByte(LowByte,FlashAddress);
WriteFlashByte(HighByte,FlashAddress+1);
}
//===========================================================================
Word ReadFlashWord(Word FlashAddress)
{
static volatile Byte data HighByte;
static volatile Byte data LowByte;
LowByte=ReadFlashByte(FlashAddress);
HighByte=ReadFlashByte(FlashAddress+1);
return((HighByte*256)+LowByte);
}
//===========================================================================

Hope this helps.

Regads,
John.

PS: When I place it here, the assembly code's neat formating is gone, I will try to post it again.

List of 50 messages in thread
TopicAuthorDate
how to write in EEPROM in P89V51RD2 ?            01/01/70 00:00      
   there is no such thing as an EEPROM            01/01/70 00:00      
   eh?            01/01/70 00:00      
      I mean FLASH ...            01/01/70 00:00      
         FlashMagic            01/01/70 00:00      
            I have flash magic            01/01/70 00:00      
               that IS what FlashMagic does            01/01/70 00:00      
                  All of them ...            01/01/70 00:00      
                     I'm at a loss            01/01/70 00:00      
                  Probs is password storing ...            01/01/70 00:00      
                     you have not, see above            01/01/70 00:00      
                        just give me an idea            01/01/70 00:00      
                           datasheet            01/01/70 00:00      
                     clear question will help            01/01/70 00:00      
         read the ... datasheet            01/01/70 00:00      
            P89V51 IAP (access)            01/01/70 00:00      
         Unfortunate terminology!            01/01/70 00:00      
   I read data sheet            01/01/70 00:00      
      read about IAP!!!            01/01/70 00:00      
         IAP code example...            01/01/70 00:00      
            this is NOT for P89V51RD2!            01/01/70 00:00      
               Use 89S52 / 89S8252            01/01/70 00:00      
                  I\'d guess...            01/01/70 00:00      
            few questions ...            01/01/70 00:00      
               Do you read my posts?            01/01/70 00:00      
   I have tried but failed ...            01/01/70 00:00      
      corrupted???            01/01/70 00:00      
         Dont know            01/01/70 00:00      
            How do you know that they are corrupted?            01/01/70 00:00      
            Refer the application notes for the P89V51RD2            01/01/70 00:00      
               Detail Problem ...            01/01/70 00:00      
                  think!            01/01/70 00:00      
                     program ...            01/01/70 00:00      
                        ehm....            01/01/70 00:00      
                           Well confused!            01/01/70 00:00      
                              one has to start somewhere...            01/01/70 00:00      
                                 Flowcharts            01/01/70 00:00      
                                    I don't think it's a good idea...            01/01/70 00:00      
                        Jan ... Guide me more            01/01/70 00:00      
                           where to place the code            01/01/70 00:00      
                  BIBLE TIME            01/01/70 00:00      
                     BASICs            01/01/70 00:00      
                        A very basic question            01/01/70 00:00      
                           to Arvind            01/01/70 00:00      
                           if you mean BASIC52/RD2 v1.4beta4...            01/01/70 00:00      
      the dangers of uncharted waters withou a pilots            01/01/70 00:00      
         maybe            01/01/70 00:00      
            I would not dare that            01/01/70 00:00      
               sunset...            01/01/70 00:00      
                  Mr. Shrivastava you are Wasting other's time            01/01/70 00:00      

Back to Subject List