www.pudn.com > 51ucosii.zip > STARTUP_B.a51, change:2002-06-14,size:6095b


;************************************************************************ 
;*  demoIAP_564.A51 - A sample code for SST89E564 / SST89V564 IAP 03/05/02	* 
;*  									* 
;*  This sample code provides programming routines of SST In-Application* 
;*  Programming(IAP)- are trademarks of Silicon Storage Technology, Inc.* 
;*  This sample code is for the user's reference only. SST does not	* 
;*  guarantee the functionality or the usefulness of the sample code.	* 
;*									* 
;*  In SST89E564 / SST89V564 MCU, there are two blocks of flash memory. * 
;*  This code is to write data to block 1 starting at 1000h by using IAP* 
;*  operations.                                                  	* 
;*									* 
;*  Companion SST89E564 / SST89V564 MCU datasheet/specificaions should * 
;*  be reviewed in conjunction with this sample code.			* 
;*									* 
;* 				                                        * 
;*  Note:This demo program is for SST89E564 / SST89V564 devises ONLY    * 
;************************************************************************ 
 
;************************************************************************ 
;*                                                                      * 
;* 	FlashFlex51 MCU  SFR Memory locations           		* 
;*                                                                      * 
;************************************************************************ 
SFCF		DATA    0B1H	; SuperFlash Configuration 
SFCM		DATA    0B2H	; SuperFlash Command 
SFAL		DATA    0B3H	; SuperFlash Address Low 
SFAH		DATA    0B4H	; SuperFlash Address High 
SFDT		DATA    0B5H	; SuperFlash Data 
SFST		DATA    0B6H	; SuperFlash Status 
 
;************************************************************************ 
;* 	FlashFlex51 MCU  IAP Commands           	  		* 
;************************************************************************ 
SFCM_SE    	EQU	0BH	; Sector-Erase IAP cmd 
SFCM_VB    	EQU	0CH	; Byte-Verify  IAP cmd 
SFCM_PB		EQU	0EH	; Byte-Program IAP cmd 
 
;************************************************************************ 
;* 		Variables Definition	 				* 
;************************************************************************ 
SECT_CNT   	EQU	R4	; sector count 
BYTE_CNT   	EQU	R5	; byte count or size 
ORIG_DATA       EQU	R6	; store data byte from IAP operation 
 
;************************************************************************ 
;* 		Constants Definition	 				* 
;************************************************************************ 
SIZE_SECT	EQU	80h	 ; number of bytes to be programed 
BLK1_DST_ADDR   EQU     1000h 
 
;************************************************************************ 
;* 	                     MAIN PROGRAM                             	* 
;************************************************************************ 
    
        org  00000h       	 
	ljmp main		  
 
	org  0040h 
main:	mov  PSW, #0         	; select register bank 0 
	 
 
start:	anl  SFCF,   #10111111b	; BFh--> force IAPEN=0 
	mov  SFDT,   #0         ; Enter any value other than 55h 
	mov  dptr, #BLK1_DST_ADDR  ; load destination addr. 1000h 
 
	lcall	sector_erase	   ; erase the bytes before write to them 
;=====================================================================	 
 
	mov  BYTE_CNT, #SIZE_SECT   ; set BYTE_CNT 
        mov  a, #0                  ; first data to be programmed                            
loop:                      
	mov  ORIG_DATA, a	 
	lcall byte_pgm		; write a byte from ACC to dest address 
 
	lcall verify_byte	; read back the byte written to destination 
	xrl  a, ORIG_DATA       ; compare with original data 
        jnz  ERROR		; jump to ERROR if verification fails 
 
	inc  dptr		; increment destination address 
	mov  a, ORIG_DATA       ; increment the data by 1   
	inc  a 
	djnz BYTE_CNT, loop 
	ajmp EXIT		; end of code execution 
 
;************************************************************************ 
;*              	  IAP SUBROUTINES                             	* 
;* 1. SECTOR-ERASE                                                      * 
;* 2. BYTE-PROGRAM                                                      * 
;* 3. BYTE-VERIFY                                                       * 
;************************************************************************ 
 
;=================================================================== 
;  Subroutine of Sector Erase 
;===================================================================			 
sector_erase: 
	orl   SFCF, #40h        ; enable IAP 
	mov   SFAH, dph		; load high order address byte 
	mov   SFAL, dpl		; load low order address byte 
	mov   SFCM, #SFCM_SE	; issue sector erase command 
 
busy:   mov   a,  SFST            
	jb    acc.2, busy       ; wait until flash is NOT busy. 
	 
safety:	                         
	anl   SFCF, #10111111b  ; disable IAP 
	mov   SFDT, #0          ; any value other than 55h 
	 
 	ret 
 
;=====================================================================	 
; Subroutine of Byte Program 
;===================================================================== 
byte_pgm:  
	orl   SFCF, #40h        ; enable IAP 
        mov   SFAH, dph	        ; set address to write a byte 
        mov   SFAL, dpl 
        mov   SFDT, ORIG_DATA   ; store data to be programmed 
	mov   SFCM, #SFCM_PB	; issue program-byte cmd 
 
done?:  mov   a,  SFST          
	jb    acc.2, done?      ; wait until byte-programming is done.  
 	ljmp  safety             
;===================================================================== 
; Subroutine of Byte Verify 
;=====================================================================	 
verify_byte:  
	orl   SFCF, #40h        ; enable IAP 
        mov   SFAH, dph  	; address from where to read a byte 
        mov   SFAL, dpl 
	mov   SFCM, #SFCM_VB	; issue verify_byte cmd 
	nop 
	mov   a, SFDT     	; data is stored in ACC 
 	ljmp  safety             
;===================================================================== 
 
 
ERROR: 
        mov p1, #55h              ;indicating IAP failed.  
 
EXIT:	 
	sjmp  $			 
 
 
 
	END