📄 flashwritepage.s51
字号:
/******************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** ++ *** *
* *** + + *** CHIPCON *
* *** + *
* *** + + *** *
* *** ++ *** *
* *** *** *
* ************ *
* ********** *
* *
*******************************************************************************
Filename: flashWritePage.s51
Target: cc1110
Author: EFU
Revised: 2/3-2006
Revision: 1.0
******************************************************************************/
;;-----------------------------------------------------------------------------
;; See hal.h for a description of this function.
;;-----------------------------------------------------------------------------
#include "ioCC1110.h"
MODULE flashWritePage.s51
RSEG RCODE
PUBLIC halFlashWritePage
FUNCTION halFlashWritePage, 0203H
DS 1
halFlashWritePage:
; R2 (LSB) and R3 (MSB) contains the start address of the data to be copied to flash (BYTE xdata * buf )
; R4 (LSB) and R5 (MSB) contains the start address of the buffer from which the program can be run in RAM
; R1 contains the flash page the data is to be written to
; Make sure that interrupts are off
MOV R0, #01;
JBC EA, intsOffHere;
MOV R0, #00;
intsOffHere:
; Storing the initial data pointer select.
PUSH DPH;
PUSH DPL;
PUSH DPH1;
PUSH DPL1;
PUSH DPS;
; Set DPTR0 = address in XDATA RAM to which the flash write procedure which is to be copied.
MOV A, R5;
MOV DPH, A;
MOV A, R4;
MOV DPL, A;
; Saving the start address of the actual flash write procedure in XDATA RAM.
PUSH DPL;
PUSH DPH;
; Set DPTR1 = start address of the procedure template in CODE
; This procedure is to be copied to XDATA.
MOV DPH1, #HIGH(copy2FlashProcStart);
MOV DPL1, #LOW(copy2FlashProcStart);
; Use R1 to count loops...
MOV R4, #copy2FlashProcEnd - copy2FlashProcStart;
; Copy @DPTR1->@DPTR0
copyLoop: MOV DPS, #1;
MOVX A, @DPTR;
INC DPTR;
MOV DPS, #0;
MOVX @DPTR, A;
INC DPTR;
DJNZ R4, copyLoop;
; xdata pointer to start of data is in R2 and R3
; Set up data pointer 1
MOV DPL1, R2
MOV DPH1, R3
; Setting the flash page to write to
; Bits 6:1 of FADDRH indicates which page to write to.
MOV A,R1
RL A
MOV FADDRH, A
MOV FADDRL, #00H
; Setting the flash write timing according to the clock division factor in CLKCON.
MOV A,CLKCON
ANL A,#07H
MOV R4,A
INC R4
MOV A,#044H
rotate: CLR C
RRC A
DJNZ R4,rotate
MOV FWT,A
; Data pointer 0 indicates where the start of the copied routine in XDATA is located.
; Pointer to start of data to copy is in data pointer 1.
MOV DPS, #0;
POP DPH;
POP DPL;
MOV R3,#02H
MOV R4,#00H
MOV R5,#02H
; Make the indirect function call
LCALL indirCall;
; Using the original data pointer
POP DPS;
POP DPL1;
POP DPH1;
POP DPL;
POP DPH;
MOV A, R0;
JZ intsWereOff;
SETB EA;
intsWereOff:
RET;
; Calling the flash write in XDATA RAM. (Pointed to by DPTR0)
indirCall: CLR A;
JMP @A+DPTR;
; Starting to write to flash
copy2FlashProcStart:
; Using data pointer 1 which indicates start of data to be copied to flash
; Erasing the page
MOV FCTL, #01H
waitEraseLoop: MOV A, FCTL
ANL A,#80H
JNZ waitEraseLoop
MOV DPS, #1;
; Turning on flash write.
MOV FCTL,#02H
; Writing data
;R3 = 2
; R4 = 0
; ; R5 = 4
writeBlock: ;
MOVX A, @DPTR
INC DPTR
MOV FWDATA, A
DJNZ R5,writeBlock
MOV R5,#02H
waitLoop: MOV A, FCTL
ANL A,#40H
JNZ waitLoop
DJNZ R4,writeBlock
DJNZ R3,writeBlock
done: RET;
copy2FlashProcEnd:
END;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -