📄 samsungflashv11.asm
字号:
push R2,R5 to [SP]
// ..... Buffer check
R2=[R_ReadIndex]
cmp R2,C_MaxPageBuffer
jb ?L_ExtractBuffer // Data in buffer , go read it
// ..... Get Status
///////////////////////////////////////////
//debug
?L_WaitForReadFlash:
call _SamsungGetStatus;
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;
?L_LowerPage:
R3 = T_PageBuffer;
R4= C_MaxPageBufferBytes;
call F_SamsungReadPageW;
// Update Data
R1=0
[R_ReadIndex]=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;
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.
//--------------------------------------------------------------------
_SamsungReadByte: //.proc
push R1, R2 to [SP]
push R4, R5 to [SP]
M_SaveIoSetting;
//......init port A0-A7 as output........
M_InitIOAOut;
//......send 命令 .....................
M_SendReadCmd R1,R2,R3,R4;
//.....init port A0-A7 as input..........
M_InitIOAIn;
//......start of reading data............
R1 = 20
?waitLp:
R1 -= 1
jnz ?waitLp
R4 |= WE_BIT //RE低电平
[Port_IOB_Data] = R4
R3 = [Port_IOA_Data]
R3 &= 0x00FF
M_RetrieveIoSetting;
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
//--------------------------------------------------------------------
//-- Function: F_SamsungReadPageW
//-- 参数: R1 = column address (0 - 527)
//-- R2 = page address (A9 - A22)
//-- R3 = Address of buffer
//-- R4 = Number of bytes to be read
//-- 返回值: 无.
//--------------------------------------------------------------------
F_SamsungReadPageW:
push R3, R5 to [SP]
M_SaveIoSetting;
//......init port A0-A7 as output........
M_InitIOAOut;
//......send 命令 .....................
M_SendReadCmd R1,R2,R3,R4;
//.....init port A0-A7 as input..........
M_InitIOAIn;
//......start of reading data............
R1 = 20
?waitLp:
R1 -= 1
jnz ?waitLp
R2 = R4
R5 = SP + 2
R3 = [R5+1]
R4 = [R5+2]
?readLp:
R1 = WE_BIT //RE低电平
R1 |= R2
[P_IOB_Data] = R1
R5 = [P_IOA_Data] // Get低电平 er byte
R5 &= 0x00FF
R1 = (WE_BIT|RE_BIT)
R1 |= R2
[P_IOB_Data] = R1
R1 = WE_BIT //RE低电平
R1 |= R2
[P_IOB_Data] = R1
R1 = [P_IOA_Data] // Get高电平 er byte
R1 = R1 lsl 4;
R1 = R1 lsl 4;
R5 |= R1;
[R3++] = R5;
R1 = (WE_BIT|RE_BIT)
R1 |= R2
[P_IOB_Data] = R1
R4 -= 2
jnz ?readLp
M_RetrieveIoSetting;
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]
call _SamsungWriteByte
POP BP,BP FROM [SP];
//pop R2, R5 from [SP]
retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SamsungWriteByte
//-- 参数: 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).
//--------------------------------------------------------------------
_SamsungWriteByte: //.proc
push R2, R5 to [SP]
M_SaveIoSetting;
//......init port A0-A7 as output.......
M_InitIOAOut;
//......send 命令 .........
M_SendWriteCmd R1,R2,R3,R4;
//......write data sequence..............
R1 = R3 //portA
R2 = R4 //portB
R5 = SP + 2
R3 = [R5+2]
R5 = RE_BIT
R5 |= R2
[Port_IOB_Data] = R5 //WE低电平 , RE高电平 , ALE低电平
R3 &= 0x00FF
R3 |= R1
[Port_IOA_Data] = R3
R5 = (RE_BIT|WE_BIT)
R5 |= R2
[Port_IOB_Data] = R5
//.......start program process...............
M_StartProgram R1,R2;
//.......read status.........................
R4 = (CLE_BIT|RE_BIT)
R4 |= R2
[Port_IOB_Data] = R4
R4 = 0x0070 //get status
R4 |= R1
[Port_IOA_Data] = R4 //WE低电平 , RE高电平 , CLE高电平
R4 = (CLE_BIT|RE_BIT|WE_BIT)
R4 |= R2
[Port_IOB_Data] = R4
//........init port A0-A7 as input............
M_InitIOAIn;
//............................................
R4 = WE_BIT
R4 |= R2
R5 = (WE_BIT|RE_BIT)
R5 |= R2
?busyLp:
[Port_IOB_Data] = R4
R1 = [Port_IOA_Data]
[Port_IOB_Data] = R5
R2 = R1 & 0x0040
jz ?busyLp
R1 &= 0x0001
M_RetrieveIoSetting;
pop R2, R5 from [SP]
retf
//.endp
//--------------------------------------------------------------------
//-- 函数名: _SP_SamsungWritePageW
//-- 语法: SamsungWritePageW(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 stored
//-- 返回值: 无
//--------------------------------------------------------------------
_SP_SamsungWritePageW: .proc
PUSH BP,BP TO [SP];
BP=SP+1
R1 = [BP+3]
R2 = [BP+4]
R3 = [BP+5]
R4 = [BP+6]
call F_SamsungWritePageW
POP BP,BP FROM [SP];
retf
.endp
//--------------------------------------------------------------------
//-- Function: F_SamsungWritePageW
//-- 参数: R1 = column address (0 - 527)
//-- R2 = page address (A9 - A22)
//-- R3 = address of buffer
//-- R4 = Number of bytes to be stored (must be even)
//-- 返回值: 无
//--------------------------------------------------------------------
F_SamsungWritePageW:
push R3, R5 to [SP]
M_SaveIoSetting;
//......init port A0-A7 as output.......
M_InitIOAOut;
//......send 命令 .........
M_SendWriteCmd R1,R2,R3,R4;
//......write data sequence..............
R1 = R3 //portA
R2 = R4 //portB
R5 = SP + 2
R3 = [R5+1]
R4 = [R5+2]
?writeLp:
R5 = RE_BIT
R5 |= R2
[P_IOB_Data] = R5 //WE低电平 , RE高电平 , ALE低电平
R5 = [R3] //extract低电平 er byte
R5 &= 0x00FF;
R5 |= R1
[P_IOA_Data] = R5
R5 = (RE_BIT|WE_BIT)
R5 |= R2
[P_IOB_Data] = R5
R5 = RE_BIT
R5 |= R2
[P_IOB_Data] = R5 //WE低电平 , RE高电平 , ALE低电平
R5 = [R3++] //extract高电平 er byte
R5 = R5 lsr 4
R5 = R5 lsr 4
R5 |= R1
[P_IOA_Data] = R5
R5 = (RE_BIT|WE_BIT)
R5 |= R2
[P_IOB_Data] = R5
R4 -= 2
jnz ?writeLp
nop
//.......start program process...............
M_StartProgram R1,R2;
// Not checking status here
M_RetrieveIoSetting;
pop R3, R5 from [SP]
retf
//--------------------------------------------------------------------
//-- 函数名: _SP_SamsungEraseBlock
//-- 语法: SP_SamsungEraseBlock(Block address)
//-- 参数:
//-- R1 = Block address (0 - 1023).
//-- Each block contains 16 pages = 8KBytes + 256 Bytes of spare space
//-- 返回值:
//-- R1 = 0 if success, R1 = 1 if failure
//--------------------------------------------------------------------
_SP_SamsungEraseBlock: .proc
PUSH BP,BP TO [SP];
BP = SP + 1;
R1 = [BP+3];
call _SamsungEraseBlock
POP BP,BP FROM [SP];
retf
.endp
//--------------------------------------------------------------------
//-- 函数名: _SamsungEraseBlock
//-- 参数:
//-- R1 = Block address (0 - 4095).
//-- Each block contains 32 pages = 16KBytes + 512 Bytes of spare space
//-- 返回值:
//-- R1 = 0 if success, R1 = 1 if failure
//--------------------------------------------------------------------
_SamsungEraseBlock: //.proc
push R2, R5 to [SP]
M_SaveIoSetting;
//......init port A0-A7 as output.......
M_InitIOAOut;
//......send 命令 ....................
R5 = SP
R3 = [R5+1]
R4 = [R5+2]
R5 = (CLE_BIT|RE_BIT)
R5 |= R4
[Port_IOB_Data] = R5
R5 = 0x0060 //auto block erase setup
R5 |= R3
[Port_IOA_Data] = R5
R5 = (CLE_BIT|RE_BIT|WE_BIT)
R5 |= R4
[Port_IOB_Data] = R5 //WE高电平
R5 = (WE_BIT|ALE_BIT|RE_BIT) //CLE低电平 , WE高电平 , ALE高电平 , RE高电平
R5 |= R4
[Port_IOB_Data] = R5
//.....写地址.....................
R4 |= (ALE_BIT|RE_BIT)
[Port_IOB_Data] = R4 //WE低电平
R1 = R1 LSL 4
R2 = R1 & 0x00FF
R2 |= R3
[Port_IOA_Data] = R2 //Address9 - 16
[Port_IOB_Data] = R5 //WE, ALE, RE高电平
[Port_IOB_Data] = R4 //WE低电平
R1 = R1 LSR 4
R1 = R1 LSR 4
R1 |= R3
[Port_IOA_Data] = R1 //Address17 - 24
[Port_IOB_Data] = R5 //WE, ALE高电平
[Port_IOB_Data] = R4 //WE低电平
push r1 to [sp]
r1 = 0
[Port_IOA_Data] = r1 //Address25
pop r1 from [sp]
[Port_IOB_Data] = R5 //WE, ALE高电平
R5 = SP
R4 = [R5+2]
R5 = RE_BIT
R5 |= R4
[Port_IOB_Data] = R5 //WE低电平 , RE高电平 , ALE低电平
//.......开始erase.................
R1 = R3
R2 = R4
R5 = (CLE_BIT|RE_BIT)
R5 |= R2
[Port_IOB_Data] = R5 //WE低电平 , RE高电平 , CLE高电平
R5 = 0x00D0 //清除命令
R5 |= R1
[Port_IOA_Data] = R5
R5 = (CLE_BIT|RE_BIT|WE_BIT)
R5 |= R2
[Port_IOB_Data] = R5
//.......读status.........................
R4 = (CLE_BIT|RE_BIT)
R4 |= R2
[Port_IOB_Data] = R4
R4 = 0x0070 //获得status
R4 |= R1
[Port_IOA_Data] = R4 //WE低电平 , RE高电平 , CLE高电平
R4 = (CLE_BIT|RE_BIT|WE_BIT)
R4 |= R2
[Port_IOB_Data] = R4
//........把A0-A7初始化为输入............
M_InitIOAIn;
//............................................
R4 = WE_BIT
R4 |= R2
R5 = (WE_BIT|RE_BIT)
R5 |= R2
?busyLp:
[Port_IOB_Data] = R4
R1 = [Port_IOA_Data]
[Port_IOB_Data] = R5
R2 = R1 & 0x0040
jz ?busyLp
R1 &= 0x0001
//
//
// 在这里处理erase错误
//
//
M_RetrieveIoSetting;
pop R2, R5 from [SP]
retf
//.endp
//--------------------------------------------------------------------
//-- 函数名: _SP_SamsungMassErase
//-- 语法: SamsungMassEraseBlock()
//-- 参数:
//-- R1 = Block address (0 - 4095).
//-- Each block contains 16 pages = 8KBytes + 256 Bytes of spare space
//-- 返回值:
//-- R1 = 0 if success, R1 >= 1 the # of block erase failures
//--------------------------------------------------------------------
_SP_SamsungMassErase: .proc
push R2,R3 to [SP];
R2 = C_BlockBin; // 全部Erase
R3 = 0; // #代表失败
?L_EraseLoop:
R1 = R2;
call _SamsungEraseBlock
R3+=R1; // #代表失败
?L_BlockEraseSuccess:
R2+=1;
cmp R2, C_MaxBlock;
jb ?L_EraseLoop;
R1 = R3;
pop R2,R3 from [SP];
retf
.endp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -