⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flash1m.asm

📁 旺宏 MXIC 28F1000 flash ROM 燒錄範例程序, 含C & ASM源碼
💻 ASM
字号:
;****************************************************************
;*   80x86 SAMPLE CODE for MX28F1000P/2000P      		*
;****************************************************************

.Model Small
.286

  Chip_Erase_CMD              =    030h
  Confirm_Chip_Erase_CMD      =    030h
  Block_Erase_CMD             =    020h
  Confirm_Block_Erase_CMD     =    0D0h
  Auto_Write_CMD              =    040h
  Read_ID_CMD   	      =    090h
  Reset_CMD		      =    0FFh

  Toggle_Bit                  =    040h
  Erase_state   	      =    0ffh

extrn   Delay_100us : Near
;Delay_100us routines is system
;dependent and should be implemented
; by caller
-----------------------------
.Code
;
;==== procedure Read_ID =========================================
;
; Read manufacturer and device ID
;
; input  : es:di - Flash address
; output : al = manufacturer ID
;          ah = device ID
Read_ID	  proc
    mov   byte ptr es:[di], Read_ID_CMD
    mov   al,es:[0]
    mov   byte ptr es:[di], Read_ID_CMD
    mov   al,es:[1]
    ret
Read_ID   endp

-----------------------------
;==== procedure Reset_STM =======================================
;
; Reset the internal state machine
;
; input  : es:di - Flash address 
; output : none
;          
Reset_STM   proc
   mov   byte ptr es:[di], Reset_CMD
   mov   byte ptr es:[di], Reset_CMD
   ret
Reset_STM   endp

-----------------------------
;==== procedure Auto Chip Erase =====================================
;
; Erase whole chip automatically, no verify operation needed
;
; input  : es:di - flash address, di is don't care.
; output : ZF    - Fail (C) / Success (S)
;
Chip_Erase   proc
   cli 					 
   mov   byte ptr es:[di], Chip_Erase_CMD
   mov   byte ptr es:[di], Confirm_Chip_Erase_CMD
   sti
   call   Erase_Polling
   ret
Chip_Erase   endp

-----------------------------
;==== procedure Block_Erase =====================================
;
; Erase one block
;
; input  : es:di - erase address
; output : ZF    - Fail (C) / Success (S)		   
;
Block_Erase   proc
   cli 					 
   mov   byte ptr es:[di], Block_Erase_CMD
   mov   byte ptr es:[di], Confirm_Block_Erase_CMD
   sti
   call   Delay_100us		
   call   Erase_Polling
   call   Reset_STM
   ret
Block_Erase   endp

-----------------------------
;==== procedure Toggle_Polling ==================================
;
; wait until Q6 stop toggling 
;
; input  : es:di - Flash address
; output : al    - status read
;
;
Toggle_Polling   proc
    mov	  ah,es:[di]
Status_Read:
    mov	  al,es:[di]
    xor   ah,al
    test  ah,Toggle_Bit
    jz    Toggle_End	  
    mov	  ah,al
    jmp   Status_Read
Toggle_End:
     ret	

Toggle_Polling   endp


-----------------------------
;==== procedure Erase_polling ===================================
; wait untill Q6 stops toggling and verify erased state (FFh)
;
; input  : es:di - Address of the block to be erase
; output : ZF    - Fail (C) / Success (S)		   
;
Erase_Polling   proc
    call   Toggle_Polling
    cmp    al, Erase_state			;if data=FFh?
    jz	   Exit_Erase_Polling
Exit_Erase_Polling:
    ret
Erase_Polling   endp	
-----------------------------
;==== procedure Byte_Program ====================================
; Write one byte to Flash
;
; input  : al    - data to be written
;          es:di - address to be written
; output : ZF    - Fail (C) / Success (S)
;
Byte_Program   proc
    call   Reset_STM
    mov	   byte ptr es:[di], Auto_Write_CMD
    mov	   es:[di], al
    mov    bl,al
    call   Toggle_Polling
    xor    al,bl
    jz     Exit_Byte_Program
    call   Reset_STM
Exit_Byte_Program:
    ret

Byte_Program   endp

-----------------------------
;==== procedure Byte_String_Program =============================
;
; Write a string of bytes
;
; input  : cx    - data string length
;          ds:si - Source address
;          es:di - Destination address
; output : ZF    - Fail (C) / Success (S)		   
;
Byte_String_Program   proc
    call   Reset_STM
write_loop:
    mov    byte ptr es:[di], Auto_Write_CMD
    movsb
    call   Toggle_Polling
    cmp    ds:[di-1], al
    jne    Program_Fail
    loop   write_loop
    ret
Program_Fail:
    call   Reset_STM
    ret

Byte_String_Program   endp        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -