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

📄 samsungflashv11.asm

📁 使用单片机扩展三星FLASH
💻 ASM
📖 第 1 页 / 共 3 页
字号:
    [R_Addr25] = r2
    
	POP R1,R5 FROM [SP];
	retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SP_StopReadSamsungFlash
//-- 语法: SP_StopReadSamsungFlash()
//-- 参数: 无
//-- 返回值: 无
//--------------------------------------------------------------------
_SP_StopReadSamsungFlash: .proc

	PUSH R1,R1 TO [SP];
    R1 = [R_PageBin];//C_PageBin; 
    [R_CurrPage] = R1;
    R1=0;  
    [R_ReadIndex] = R1;  
    [R_CurrAddr]=R1;
	POP R1,R1 FROM [SP];
	retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SP_GetColAddr
//-- 语法: SP_GetColAddr()
//-- 参数: 无
//-- 返回值: R1=Column Addr
//--------------------------------------------------------------------
_SP_GetColAddr: .proc

    PUSH BP,BP TO [SP];
   
    R1=[R_CurrAddr];
   
    POP BP,BP FROM [SP];
    retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SP_GetPage
//-- 语法: SP_GetPage()
//-- 参数: 无
//-- 返回值: R1=Page low  R2=Page high
//--------------------------------------------------------------------
_SP_GetPage: .proc

    PUSH BP,BP TO [SP];
    
    R1=[R_CurrPage];
    r2 = [R_Addr25];
    POP BP,BP FROM [SP];
    retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SP_GetBlock
//-- 语法: SP_GetBlock()
//-- 参数: 无
//-- 返回值: R1=Block
//--------------------------------------------------------------------
_SP_GetBlock: .proc

    PUSH BP,BP TO [SP];
    
    R1=[R_CurrPage];
    R1= R1 LSR 4;   
    POP BP,BP FROM [SP];
    retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SP_FillSamsungFlash
//-- 语法: SP_FillSamsungFlash(Data)
//-- 参数: R1=Data
//-- 返回值: 无
//--------------------------------------------------------------------
_SP_FillSamsungFlash: .proc

    PUSH BP,BP TO [SP];
    BP = SP + 1
    R1=[BP+3]
    call F_FillSamsungFlash   
	POP BP,BP FROM [SP];
	retf
.endp

F_FillSamsungFlash:   
    push R2,R5 to [SP];
    // Fill the data to buffer
    R2=[R_WriteIndex];
    R3=T_PageBuffer;
    R3+=R2;
    [R3]=R1;
    //..... Update Buffer used and Addr	
    R2=R2+1;
    [R_WriteIndex]=R2;
    R2 =[R_CurrAddr];
    R2+=2;
    [R_CurrAddr]=R2;
    //..... Check buffer full
    R2=[R_WriteIndex]
    cmp R2,C_MaxPageBuffer;
    jb ?L_Done
    // ..... Get Status
?L_WaitForProgramFlash:
    call _SamsungGetStatus_1;    
    R2=R1&0x40;    // ..... Check busy/ready       
    jz ?L_WaitForProgramFlash
    //R2=R1&0x0001;     // Check success/failure
    //jz ?L_ProgramFlash
    //  ... Handle Program Error here according to you file system ...
    // ..... Program Flash
?L_ProgramFlash:
    R1=[R_CurrAddr];
    R1-=C_MaxPageBufferBytes;
    R2=[R_CurrPage];
    R3= T_PageBuffer;
    R4= C_MaxPageBufferBytes;
    
	call F_SamsungWritePageW;
	
	R2=[R_CurrAddr];	
	cmp R2, C_PageSize;
    jb ?L_LowerPage
	R1=0;	
	[R_CurrAddr]=R1;
	R2=[R_CurrPage];	    
	R2+=1;
	[R_CurrPage]=R2;
		
?L_LowerPage:
    R1=0;
    [R_WriteIndex]=R1;
?L_Done:	
	pop R2,R5 from [SP]
retf	
//--------------------------------------------------------------------
//-- 函数名: _SP_ExtractSamsungFlash
//-- 语法: SP_ExtractSamsungFlash()
//-- 参数: 无
//-- 返回值: R1=Data
//-- 2004.12.25  Edit by Xinqiang Zhang for change IO
//--------------------------------------------------------------------
_SP_ExtractSamsungFlash: .proc
    PUSH BP,BP TO [SP];
    BP = SP + 1
    call F_ExtractSamsungFlash  
	POP BP,BP FROM [SP];
	retf
.endp

F_ExtractSamsungFlash:  
    push R2,R5 to [SP]
    // ..... Buffer check
    R2=[R_ReadIndex]
    R1 = [R_ReadIndex_First]
    cmp R2,R1//C_MaxPageBuffer
    
    jb ?L_ExtractBuffer  // Data in buffer , go read it
    // ..... Get Status
///////////////////////////////////////////
//debug    
?L_WaitForReadFlash:
    call _SamsungGetStatus_1;    
    R1&=0x40      // ..... Check busy    
    jz ?L_WaitForReadFlash
//	r1=0xfff
//?L_WaitForReadFlash:
//	r1-=1
//	jnz ?L_WaitForReadFlash

////////////////////////////////////////
    // ..... Read Flash
    R1= [R_CurrAddr];
    R2= [R_CurrPage];
    cmp R1 ,C_PageSize;
   
    jb ?L_LowerPage ;
    R1=0;
    [R_CurrAddr]=R1;
    // Next Page
    R2+=1;
    [R_CurrPage]=R2;
    jnz ?L_LowerPage
    r2 = 0x0001
    [R_Addr25] = r2
   
?L_LowerPage:
    R3 = T_PageBuffer;
    R4= [R_ReadIndex_Secon]//C_MaxPageBufferBytes;  
    R4 = R4 lsl 1 

    call  F_SamsungReadPageW;
    
    // Update Data
    R1=0
    [R_ReadIndex]=R1; 
    R1 = [R_ReadIndex_Secon]
    [R_ReadIndex_First] = r1
    r1 = 64
    [R_ReadIndex_Secon] = r1
    
?L_ExtractBuffer:
    R3=[R_CurrAddr];
    R3+=2;
    [R_CurrAddr]=R3;
    R1=T_PageBuffer;
    R2=[R_ReadIndex];
    R2+=R1;
    R1=[R2];   // returned value    
    //..... Update Buffer used and Addr
    R2=[R_ReadIndex];
    R2+=1;
	[R_ReadIndex]=R2;
  
	pop R2,R5 from [SP];
retf
//--------------------------------------------------------------------
//-- 函数名: _SP_GetFlashStatus
//-- 语法: SP_GetStatus()
//-- 参数: 无
//-- 返回值: R1 = Status.
//--------------------------------------------------------------------
_SP_GetFlashStatus: .proc
    PUSH BP,BP TO [SP];
    call _SamsungGetStatus_1;
	POP BP,BP FROM [SP];	
    retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SamsungGetStatus
//-- 参数: 无
//-- 返回值: R1 = Status.
//--------------------------------------------------------------------
_SamsungGetStatus: //.proc
	push R2, R5 to [SP]
    M_SaveIoSetting;
	//......init port A0-A7 as output.......
	M_InitIOAOut;
	//......send 命令 ....................
	R5 = SP
	R2 = [R5+1]					//portA
	R3 = [R5+2]					//portB
	R4 = (CLE_BIT|RE_BIT)
	R4 |= R3
	[Port_IOB_Data] = R4
	R5 = 0x0070  				//read0 命令 
	R5 |= R2
	[Port_IOA_Data] = R5
	R4 |= WE_BIT
	[Port_IOB_Data] = R4		//WE高电平 
	R4 = (WE_BIT|RE_BIT)		//CLE低电平 , WE高电平 , RE高电平 
	R4 |= R3
	[Port_IOB_Data] = R4
	//.....init port A0-A7 as input..........
	M_InitIOAIn;
	//.......................................
	R4 = WE_BIT					//RE低电平 
	R4 |= R3
	[Port_IOB_Data] = R4
//	nop
	R1 = [Port_IOA_Data]		
	R1 &= 0x00FF
	M_RetrieveIoSetting;
	pop R2, R5 from [SP]
	retf
//.endp
 
//--------------------------------------------------------------------
//-- 函数名: _SP_SamsungReadByte
//-- 语法: SP_SamsungReadByte(column address, page address)
//-- 参数: R1 = column address (0 - 527)
//--            R2 = page address (A9 - A22)
//-- 返回值: R1 = Byte value.
//--------------------------------------------------------------------
_SP_SamsungReadByte: .proc
    PUSH BP,BP TO [SP];
    BP = SP + 1
 	R1=[BP+3]
	R2=[BP+4]
  
    call _SamsungReadByte;

    R1=R3;
	POP BP,BP FROM [SP];
	retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SamsungReadByte
//-- 参数: R1 = column address (0 - 527)
//--            R2 = page address (A9 - A22)
//-- 返回值: R3 = Byte value.
//2004.12.23 Edit by xinqiang zhang for change the IO
//--------------------------------------------------------------------
_SamsungReadByte: //.proc
	push R1, R2 to [SP]
	push R4, R5 to [SP]
    M_SaveIoSetting_1;
	//......init port A0-A7 as output........
	M_InitIOAOut_1;
	//......send 命令 .....................
    call MM_SendReadCmd
    //M_SendReadCmd R1,R2,R3,R4;
	//.....init port A0-A7 as input..........
    M_InitIOAIn_1;
	//......start of reading data............
	R1 = 25                                                  //edit by hongyan
?waitLp:
	R1 -= 1
	jnz ?waitLp					
	R4 |= WE_BIT					//RE低电平 
	[Port_IOB_Data] = R4
//	nop
//	nop
//	nop
	R3 = [Port_IOB_Data]
	R3 &= 0xff00//0x00FF
	M_RetrieveIoSetting_1;
	r3 = r3 lsr 4
	r3 = r3 lsr 4
	pop R4, R5 from [SP]
	pop R1, R2 from [SP]
	retf
//.endp
//--------------------------------------------------------------------
//-- 函数名: _SP_SamsungReadPageW
//-- 语法: SP_SamsungReadPageW(column address, page address,address of buffer,# of bytes to be stored)
//-- 参数: R1 = column address (0 - 527)
//--            R2 = page address (A9 - A22)
//--			R3 = Address of buffer
//--			R4 = Number of bytes to be read
//-- 返回值: 无.
//--------------------------------------------------------------------
_SP_SamsungReadPageW: .proc
    PUSH BP,BP TO [SP];
	BP=SP+1;
	R1 = [BP+3];
	R2 = [BP+4];
    R3 = [BP+5];
    R4 = [BP+6];

    call F_SamsungReadPageW;

	POP BP,BP FROM [SP];
	retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SamsungReadWord
//-- 参数: R1 = column address (0 - 527)
//--            R2 = page address (A9 - A22)
//-- 返回值: R3 = Byte value.
//--------------------------------------------------------------------

_SP_SamsungReadWord:.proc
	push r5 to [sp]
	r5 = sp+1
	r1 = [r5+3]
	r2 = [r5+4]
	call _SamsungReadByte
	push r3 to [sp]
	r1+=1
	call _SamsungReadByte
	r3 = r3 lsl 4
	r3 = r3 lsl 4
	pop r1 from [sp]
	r1 = r1|r3
	pop r5 from [sp]
	retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SamsungReadWord_1   Read a word from flash anyaddr
//-- 参数: R1 = column address (0 - 527)
//--            R2 = page address (A9 - A24)
//--				R3 = Block address (A25)
//-- 返回值: R3 = Byte value.
//-- 2004.12.25   Edit by xinqiang   for change IO
//--------------------------------------------------------------------

_SP_SamsungReadWord_1:.proc
	push r5 to [sp]
	r5 = sp+1
	r1 = [r5+3]
	r2 = [r5+4]
	r3 = [r5+5]					//get the block number
	r4 = r3 & 0x0800
	r4 = r4 lsr 4
	r4 = r4 lsr 4
	r4 = r4 lsr 3
	r4 &= 0x0001
	[R_Addr25] = r4
	r3 = r3 lsl 4
	r3 = r3 lsl 1
	r2 |= r3
	call _SamsungReadByte		//Read the low byte
	push r3 to [sp]
	r1+=1
	call _SamsungReadByte		//Read the hight byte
	r3 = r3 lsl 4
	r3 = r3 lsl 4
	pop r1 from [sp]
	r1 = r1|r3
	pop r5 from [sp]
	retf
.endp
//--------------------------------------------------------------------
//-- Function: F_SamsungReadPageW
//-- 参数: R1 = column address (0 - 527)
//--            R2 = page address (A9 - A22)
//--			R3 = Address of buffer
//--			R4 = Number of bytes to be read
//-- 返回值: 无.
//2004.12.23  Edit by xinqiang for change the IO
//--------------------------------------------------------------------
F_SamsungReadPageW:
    push R3, R5 to [SP]
	M_SaveIoSetting_1;
	//......init port A0-A7 as output........
	M_InitIOAOut_1;
	//......send 命令 .....................
    call MM_SendReadCmd //R1,R2,R3,R4;
	//.....init port A0-A7 as input..........
    M_InitIOAIn_1;
	//......start of reading data............
	R1 = 20
?waitLp:
	R1 -= 1
	jnz ?waitLp
	R2 = R4
	R5 = SP + 1//2
	R3 = [R5+1]
	R4 = [R5+2]
	R1 = WE_BIT
	R1 |= R2
	R2 = R1|RE_BIT
?readLp:
	[P_IOB_Data] = R1
	R5 = [P_IOB_Data]			// Get低电平 er byte
	R5 &= 0xff00//0x00FF
	r5 = r5 lsr 4
	r5 = r5 lsr 4
	[P_IOB_Data] = r2//R1
	[P_IOB_Data] = R1
	push r1 to [sp]
	R1 = [P_IOB_Data]   		// Get高电平 er byte
	r1 &= 0xff00
	R5 |= R1;
	[R3++] = R5;
	[P_IOB_Data] = r2//R1
	pop r1 from [sp]
	R4 -= 2		
	jnz ?readLp
	M_RetrieveIoSetting_1;
	pop R3, R5 from [SP]
retf 
//--------------------------------------------------------------------
//-- 函数名: _SP_SamsungWriteByte
//-- 语法: SP_SamsungWriteByte(column address, page address,data to store)
//-- 参数: R1 = column address (0 - 527)
//--            R2 = page address (A9 - A22)
//--			R3 = data to store
//-- 返回值: R1=0: success, R1=1: failure 
//--		(only detect "1"s that are not successfully program to "0"s).
//--------------------------------------------------------------------
_SP_SamsungWriteByte: .proc
    PUSH BP,BP TO [SP];
	BP=SP+1
	R1 = [BP+3]
	R2 = [BP+4]
    R3 = [BP+5]
    r4 = CE_BIT
    [Port_IOB_Data] = r4
	call _SamsungWriteByte

    POP BP,BP FROM [SP];
	//pop R2, R5 from [SP]
	retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SP_SamsungWriteWord
//-- 语法: SP_SamsungWriteWord(column address, page address,data to store)
//-- 参数: R1 = column address (0 - 263)
//--            R2 = page address (A9 - A24)
//--			R3 = data to store
//-- 返回值: R1=0: success, R1=1: failure 
//--		(only detect "1"s that are not successfully program to "0"s).
//note: the Address 25 have define in function SP_InitWrite~~~~
//Date: 2004.12.24 Edit by xinqiang Zhang
//--------------------------------------------------------------------
_SP_SamsungWriteWord: .proc
    PUSH BP,BP TO [SP];
	BP=SP+1
	R1 = [BP+3]
	R2 = [BP+4]
    R3 = [BP+5]
	call _SamsungWriteByte
	R1 = [BP+3]
    R3 = [BP+5]
	call _SamsungWriteByte
	R1 = [BP+3]
	r1+=1
    R3 = [BP+5]
    r3 = r3 lsr 4
    r3 = r3 lsr 4
	call _SamsungWriteByte

    POP BP,BP FROM [SP];
	//pop R2, R5 from [SP]
	retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SamsungWriteByte
//-- 参数: R1 = column address (0 - 527)

⌨️ 快捷键说明

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