ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Вторник
26 ноября
64833 Топик полностью
addi (09.08.2006 11:42, просмотров: 1) ответил M@ik на Посмотреть-бы, что у вас там в asms.s...
Ответ: asms.s в сообщение ;--------------------------------------------------------------------- ; Other EQU settings ;--------------------------------------------------------------------- CMD_INTERNAL_VERIFY EQU (00000001B) ;Internal verify (compares MRG01 and MRG11) CMD_INTERNAL_VERIFY2 EQU (00000010B) ;Internal verify 2 (compares MRG01 and MRG12) CMD_BLOCK_ERASE EQU (00000011B) ;Block erase CMD_BLANK_CHECK EQU (00000100B) ;Blank check CMD_BYTE_WRITE EQU (00000101B) ;1-byte write NO_ERR EQU (00000000B) ;No errors ERR_FPRERR EQU (00000001B) ;PFCMD write error ERR_VCERR EQU (00000010B) ;Erase/write/internal verify error ERR_WEPRERR EQU (00000100B) ;Protect error FALSE EQU (0FFH) ;Abnormal TRUE EQU (00H) ;Normal DATATOP EQU (2) ;Data write start address EEPROM_BLOCK_NO EQU (tEEPROM_BLOCK_END - tEEPROM_BLOCK) ;Number of blocks used as ;EEPROM DATA_NO_MAX EQU (tDATA_LNG_END - tDATA_LNG) ;Number of data blocks to be ;written WRITE_RETRY EQU (10) ;Retry count for write ERASE_RETRY EQU (20) ;Retry count for erasure ;--------------------------------------------------------------------- ; Other RAM settings ;--------------------------------------------------------------------- EP_RAM2 DSEG saddr d2Address: DS 2 ;RAM for storing EEPROM read/write address dBlockTBLNo: DS 1 ;RAM for storing block being used during EEPROM ;read/write processing dLeng: DS 1 ;RAM for storing EEPROM read/write data length d2SrcAdr: DS 2 ;RAM for storing address during EEPROM data search d2EndAdr: DS 2 ;RAM for storing end address of block during EEPROM ;data search d2DataAdr: DS 2 ;RAM for securing latest data address during EEPROM ;data search d2SetAdr: DS 2 ;RAM for storing data transfer destination address ;during block transition d2GetAdr: DS 2 ;RAM for storing data transfer source address during ;block transition d2ReadGet: DS 2 ;RAM for storing data transfer source address d2ReadSet: DS 2 ;RAM for storing data transfer destination address dLength: DS 1 ;RAM for storing data length dNextBlockTBLNo: DS 1 ;RAM for storing transition destination block number ci: DS 1 ;General-purpose loop counter cj: DS 1 ;General-purpose loop counter d2MaskStatus: DS 2 ;RAM for storing mask data EP_PROG CSEG ;------------------------------------------------------------------- ; Function name: EEPROMReadV (user access function) ; Input: X = Read data number ; DE = Read data storage address ; Output: C = Normal completion (TRUE: 00H) or abnormal completion (FALSE: FFH) ; Summary: Data with the specified number is read from EEPROM to the storage address. ; 1. Searches for blocks being used as EEPROM. ; 2. Searches for latest data address among valid blocks. ; 3. Reads latest data from searched address. ;------------------------------------------------------------------- ghjdfgsasdfkog adgd fs'dflgks'df;lgsf;EEPROMReadV: PUSH HL PUSH DE PUSH AX MOVW AX,SP MOVW HL,AX CALL !EEPROMUseBlockSearchV ;Searches for blocks currently used as EEPROM MOV A,C MOV dBlockTBLNo,A CMP A,#FALSE BZ $EP_READ_FL ;Abnormal completion MOV E,A MOV A,[HL] MOV X,A CALL !EEPROMDataSearchV ;Acquires address of latest data of specified data ;number MOVW AX,BC CMPW AX,#0000H BZ $EP_READ_FL ;Abnormal completion INCW AX MOVW d2Address,AX MOV A,[HL] CALL !DataLeng ;Acquires data length from table MOV dLeng,A MOV ci,#0 EP_READ_1: MOV A,ci ;Loops from 0 to data length CMP A,dLeng BNC $EP_READ_TR MOVW AX,d2Address MOVW DE,AX INCW AX MOVW d2Address,AX MOV A,[DE] MOV C,A MOV A,[HL+2] XCH A,X MOV A,[HL+3] MOVW DE,AX INCW AX MOV [HL+3],A XCH A,X MOV [HL+2],A MOV A,C MOV [DE],A ;Stores data length amount of latest data INC ci ;Loop counter + 1 BR EP_READ_1 EP_READ_TR: MOV C,#TRUE ;Return value = Normal completion (TRUE) BR EP_READ_E EP_READ_FL: MOV C,#FALSE ;Return value = Abnormal completion (FALSE) EP_READ_E: POP AX POP DE POP HL RET ;------------------------------------------------------------------- ; Function name: EEPROMWriteV (user access function) ; Input: X = Write data number ; DE = Write data storage address ; Output: C = Normal completion (TRUE: 00H) or abnormal completion (FALSE: FFH) ; Summary: Writes data with specified number from the storage address to EEPROM. ; 1. Searches for blocks being used as EEPROM. ; 2. If there are no valid blocks, the first specified block is set as valid. ; 3. Searches for addresses to enable writing to valid block. ; 4. If the valid blocks are full and cannot be written to, the operation moves to the next block. ; 5. Creates write data. ; 6. Writes to valid blocks. ;------------------------------------------------------------------- EEPROMWriteV: PUSH HL PUSH DE PUSH AX MOVW AX,SP MOVW HL,AX CALL !SelfFlashModeOn ;Sets flash mode CALL !EEPROMUseBlockSearchV ;Searches for blocks being used as EEPROM MOV A,C MOV dBlockTBLNo,A ;Sets block number used CMP A,#FALSE ;Checks block number BNZ $EP_WRITE_3 ;Normal completion CALL !EEPROMBlockInitV ;If there are no currently used blocks, the smallest ;number block specified as EEPROM is set as the ;valid block. MOV A,C MOV dBlockTBLNo,A ;Sets block number used CMP A,#FALSE ;Checks block number BNZ $EP_WRITE_2 ;Normal completion BR EP_WRITE_FL ;Abnormal completion EP_WRITE_2: MOV A,dBlockTBLNo CALL !BlockAddressGet ADDW AX,#DATATOP MOVW d2Address,AX ;Calculates block write start address ;(Data start address + offset (valid/invalid flag)) BR EP_WRITE_4 EP_WRITE_3: MOV A,dBlockTBLNo MOV X,#00H XCH A,X CALL !EEPROMWriteTopSearchV MOVW AX,BC MOVW d2Address,AX ;Sets write address of table currently being used EP_WRITE_4: MOV A,[HL] CALL !DataLeng ;Acquires data length from table CALL !WriteDataLength ;Calculates actual storage data length from data ;length MOV dLeng,A ;Sets data length MOV A,dBlockTBLNo INC A CALL !BlockAddressGet ;Retrieves end address of block currently being used XCH A,X SUB A,d2Address XCH A,X SUBC A,d2Address+1 MOVW BC,AX ;Calculates data write address minus end address of ;block currently being used MOV A,dLeng MOV X,#0 XCH A,X CMP A,B BNZ $EP_WRITE_5 XCH A,X CMP A,C ;Compares writable number of bytes and write data ;length (data number, delimiter, etc.) BZ $EP_WRITE_7 EP_WRITE_5: BC $EP_WRITE_7 MOV A,dBlockTBLNo MOV X,#0 XCH A,X CALL !EEPROMUseBlockChangeV ;Changes block used when data cannot be written MOV A,C MOV dBlockTBLNo,A ;Determines block number to be used CMP A,#FALSE ;Checks block number BNZ $EP_WRITE_6 ;Normal completion BR EP_WRITE_FL ;Abnormal completion EP_WRITE_6: MOV A,dBlockTBLNo MOV X,#00H XCH A,X CALL !EEPROMWriteTopSearchV MOVW AX,BC MOVW d2Address,AX ;Set write address of table currently being used EP_WRITE_7: MOV A,[HL] MOV bDataBuf,A ;Sets data number for data written to start of data ;buffer MOV ci,#1 EP_WRITE_8: MOV A,[HL] CALL !DataLeng ;Acquires data length from table CMP A,ci ;Loops from 1 to data length BC $EP_WRITE_9 MOV A,[HL+2] XCH A,X MOV A,[HL+3] MOVW DE,AX ;Sets read address to RegDE INCW AX MOV [HL+3],A XCH A,X MOV [HL+2],A MOV A,[DE] MOV C,A ;Sets write address to RegC MOV A,ci MOV B,A ;Sets offset of write address to RegB MOVW AX,#bDataBuf XCH A,X ADD A,B XCH A,X ADDC A,#0 MOVW DE,AX ;Sets write address + offset to RegHL MOV A,C MOV [DE],A ;Creates write data to EEPROM MOV A,#0 INCW DE MOV [DE],A ;Sets 00H to data address + 1 (delimiter when last ;data address +1) INC ci ;Loop counter + 1 BR EP_WRITE_8 EP_WRITE_9: MOVW DE,#bDataBuf MOV A,dLeng MOV C,A MOVW AX,d2Address CALL !FlashEEPROMWrite ;Writes created write data to EEPROM BZ $EP_WRITE_TR EP_WRITE_FL: CALL !SelfFlashModeOff ;Releases flash mode MOV C,#FALSE ;Return value = Abnormal completion (FALSE) BR EP_WRITE_E EP_WRITE_TR: CALL !SelfFlashModeOff ;Releases flash mode MOV C,#TRUE ;Return value = Normal completion (TRUE) EP_WRITE_E: POP AX POP DE POP HL RET ;------------------------------------------------------------------- ; Function name: EEPROMUseBlockSearchV ; Input: None ; Output: C = Block table number (00H to FEh), abnormal completion (FALSE: FFH) ; Summary: Searches for currently used blocks in flash memory that are allocated to EEPROM. ;------------------------------------------------------------------- EEPROMUseBlockSearchV: PUSH HL MOV L,#0 ;Initializes loop counter L register EP_BSRC_T: MOV A,L CMP A,#EEPROM_BLOCK_NO ;Number of loops = Number of EEPROM setting blocks BNC $EP_BSRC_4 CALL !BlockAddressGet MOVW DE,AX MOV A,[DE] MOV bDataBuf,A INCW DE MOV A,[DE] MOV bDataBuf+1,A EP_BSRC_2: MOV A,bDataBuf CMP A,#00H BNZ $EP_BSRC_3 ;When valid flag = 00H, MOV A,bDataBuf+1 CMP A,#0FFH BNZ $EP_BSRC_3 ;and invalid flag = FFH, MOVW AX,HL ;this block is valid MOV A,#00H MOVW BC,AX ;Return value = Valid block number BR EP_BSRC_E EP_BSRC_3: INC L BR EP_BSRC_T EP_BSRC_4: MOV C,#FALSE ;Return value = Abnormal completion (no valid ;blocks) EP_BSRC_E: POP HL RET ;------------------------------------------------------------------- ; Function name: EEPROMBlockInitV ; Input: None ; Output: C = Normal completion (TRUE: 00H) or abnormal completion (FALSE: FFH) ; Summary: If none of the blocks to be used as EEPROM are valid blocks, ; the first specified block is set as currently used (valid). ;------------------------------------------------------------------- EEPROMBlockInitV: PUSH HL MOV A,!tEEPROM_BLOCK ;Sets smallest block number set for EEPROM MOV X,#0 CALL !SelfFlashBlockErase ;Erases specified block MOV A,C CMP A,#TRUE BNZ $EP_BINI_1 ;Abnormal completion MOV A,#00H MOV bDataBuf,A ;Sets block valid data MOVW DE,#bDataBuf MOV C,#1 MOV A,!tEEPROM_BLK_ADR MOV X,A MOV A,!tEEPROM_BLK_ADR+1 CALL !FlashEEPROMWrite ;Calls EEPROM write processing BZ $EP_BINI_2 ;Normal completion EP_BINI_1: ;Abnormal completion MOV C,#FALSE ;Return value = Abnormal completion BR EP_BINI_E EP_BINI_2: MOV C,#TRUE ;Return value = Normal completion EP_BINI_E: POP HL RET ;------------------------------------------------------------------- ; Function name: EEPROMUseBlockChangeV ; Input: X = Table number of currently used block ; (block number of block set for EEPROM use by user definition) ; Output: C = Block table number (00H to FEH), abnormal completion (FFH) ; Summary: If the currently used blocks are full of data, this function searches for the ; next block to be used and copies data to that block. ; 1. Sets block to be used next. ; 2. Erases block to be used next. ; 3. Transfers the latest data from a valid block to the next block. ; 4. Sets the next block to be used as valid ; 5. Sets currently valid blocks as invalid. ;------------------------------------------------------------------- EEPROMUseBlockChangeV: PUSH HL MOVW HL,AX MOV A,L ;Determines block to be used next INC A CMP A,#EEPROM_BLOCK_NO BC $EP_BCHG_2 MOV A,#0 EP_BCHG_2: MOV dNextBlockTBLNo,A MOV C,A MOVW AX,#tEEPROM_BLOCK XCH A,X ADD A,C XCH A,X ADDC A,#0 MOVW DE,AX MOV A,[DE] MOV X,#0 CALL !SelfFlashBlockErase ;Erases block to be used next MOV A,#FALSE CMP A,C BNZ $EP_BCHG_3 ;Normal completion BR EP_BCHG_FL ;Abnormal completion EP_BCHG_3: MOV A,dNextBlockTBLNo CALL !BlockAddressGet ADDW AX,#DATATOP MOVW d2SetAdr,AX ;Sets next block write start address MOV ci,#0 EP_BCHG_4: MOV A,ci CMP A,#DATA_NO_MAX ;Loops from 0 to DATA_NO_MAX BC $EP_BCHG_41 BR EP_BCHG_10 EP_BCHG_41: MOV A,L MOV E,A MOV A,ci MOV X,A CALL !EEPROMDataSearchV ;Searches latest data number address MOVW AX,BC MOVW d2GetAdr,AX CMPW AX,#0000H ;Judges whether address is other than 0000H (data ;exists) BNZ $EP_BCHG_42 BR EP_BCHG_9 EP_BCHG_42: MOVW AX,d2GetAdr MOVW d2ReadGet,AX ;Sets data acquisition address MOVW AX,#bDataBuf MOVW d2ReadSet,AX ;Sets data storage address MOV A,ci CALL !DataLeng ;Acquires data length from table CALL !WriteDataLength ;Calculates actual storage data length from data ;length MOV dLength,A ;Sets data length MOV A,#0 MOV cj,A EP_BCHG_5: MOV A,cj CMP A,dLength ;Loops from 0 to data length BNC $EP_BCHG_6 MOVW AX,d2ReadGet MOVW DE,AX INCW AX MOVW d2ReadGet,AX MOV A,[DE] MOV C,A MOVW AX,d2ReadSet MOVW DE,AX INCW AX MOVW d2ReadSet,AX MOV A,C MOV [DE],A ;Transfers data from data acquisition address to ;data storage address. INC cj ;Loop counter + 1 BR EP_BCHG_5 EP_BCHG_6: MOVW DE,#bDataBuf MOV A,dLength MOV C,A MOVW AX,d2SetAdr CALL !FlashEEPROMWrite ;Writes stored data to EEPROM BZ $EP_BCHG_8 ;Normal completion BR EP_BCHG_FL ;Abnormal completion EP_BCHG_8: MOV A,dLength XCH A,C MOVW AX,d2SetAdr XCH A,X ADD A,C XCH A,X ADDC A,#0 MOVW d2SetAdr,AX ;To search next data, search address + data length EP_BCHG_9: INC ci ;Loop counter + 1 BR EP_BCHG_4 EP_BCHG_10: MOV A,#00H MOV bDataBuf,A ;Prepares data for block valid/invalid setting MOV A,dNextBlockTBLNo CALL !BlockAddressGet MOVW DE,#bDataBuf MOV C,#1 CALL !FlashEEPROMWrite ;Sets block to be used next as valid BNZ $EP_BCHG_FL ;Abnormal completion EP_BCHG_12: MOV A,L CALL !BlockAddressGet INCW AX MOVW DE,#bDataBuf MOV C,#1 CALL !FlashEEPROMWrite ;Sets block being used as invalid BZ $EP_BCHG_TR EP_BCHG_FL: MOV C,#FALSE ;Return value = Abnormal completion BR EP_BCHG_E EP_BCHG_TR: MOV A,dNextBlockTBLNo MOV B,#00H XCH A,C ;Return value = Next block number EP_BCHG_E: POP HL RET ;------------------------------------------------------------------- ; Function name: EEPROMWriteTopSearchV ; Input: X = Search block table number ; (block number of block set for EEPROM use by user definition) ; Output: BC = Write address (0000H to FFFFH) ; Summary: Searches for specified block write address. ;------------------------------------------------------------------- EEPROMWriteTopSearchV: PUSH HL MOVW HL,AX MOV A,L CALL !BlockAddressGet ;From EEPROM block start end address table, ADDW AX,#DATATOP MOVW d2SrcAdr,AX ;sets block start address MOV A,L INC A CALL !BlockAddressGet ;From EEPROM block start end address table, MOVW d2EndAdr,AX ;sets block end address EP_WTSR_T: MOVW AX,d2SrcAdr MOVW DE,AX MOV A,[DE] MOV bDataBuf,A ;Reads EEPROM data from read address CMP A,#0FFH BZ $EP_WTSR_4 ;Is data number search end code (FFH)? CMP A,#DATA_NO_MAX BC $EP_WTSR_1 ;When outside range of data number MOVW AX,d2SrcAdr ADDW AX,#1 ;advances search pointer by 1 byte for next data ;search MOVW d2SrcAdr,AX BR EP_WTSR_2 EP_WTSR_1: MOVW AX,d2SrcAdr MOVW DE,AX MOV A,[DE] CALL !DataLeng ;Acquires data length from table CALL !WriteDataLength ;Calculates actual storage data length from data ;length MOV X,#00H ADD A,d2SrcAdr XCH A,X ADDC A,d2SrcAdr+1 MOVW d2SrcAdr,AX ;Advances search pointer by data length for ;searching next data EP_WTSR_2: MOVW AX,d2SrcAdr CMP A,d2EndAdr+1 BNZ $EP_WTSR_3 XCH A,X CMP A,d2EndAdr EP_WTSR_3: BC $EP_WTSR_T ;Judges whether search pointer is within search ;block range MOVW AX,d2EndAdr MOVW BC,AX ;Sets block end to search address if search pointer ;is outside search block range BR EP_WTSR_E EP_WTSR_4: MOVW AX,d2SrcAdr MOVW BC,AX ;Return value = Address of search pointer EP_WTSR_E: POP HL RET ;------------------------------------------------------------------- ; Function name: EEPROMDataSearchV ; Input: X = Read data number ; E = Currently used block table number ; (block number of block set for EEPROM use by user definition) ; Output: BC = Address of latest data (0001H to FFFFH), abnormal completion (0000H) ; Summary: Reads storage address of latest data at specified number. ;------------------------------------------------------------------- EEPROMDataSearchV: PUSH HL MOV A,X XCH A,X MOV A,E MOVW HL,AX CALL !BlockAddressGet ;From EEPROM block start end address table, ADDW AX,#DATATOP ;sets block start address MOVW d2SrcAdr,AX MOVW AX,#0000H MOVW d2DataAdr,AX ;Initializes search result storage address MOV A,H INC A CALL !BlockAddressGet ;From EEPROM block start end address table, MOVW d2EndAdr,AX ;sets block end address MOVW AX,HL MOV A,#00H ADDW AX,#tDATA_LNG MOVW DE,AX MOV A,[DE] ;Retrieves search data length of search data number CALL !WriteDataLength MOV dLength,A ;Calculates actual storage data length from data ;length EP_DASR_T: MOVW AX,d2SrcAdr MOVW DE,AX MOV A,[DE] MOV bDataBuf,A ;Retrieves search address data CMP A,L BNZ $EP_DASR_3 ;Compares with data number MOV A,dLength DEC A MOV X,#0 ADD A,d2SrcAdr XCH A,X ADDC A,d2SrcAdr+1 MOVW DE,AX MOV A,[DE] ;Retrieves delimiter CMP A,#00H BNZ $EP_DASR_4 ;If delimiter is 00H, search target data MOVW AX,d2SrcAdr MOVW d2DataAdr,AX ;Stores search address in search result storage ;address BR EP_DASR_4 EP_DASR_3: MOV A,bDataBuf CMP A,#0FFH ;Judges data end (FFH) BZ $EP_DASR_E EP_DASR_4: MOV A,bDataBuf CMP A,#DATA_NO_MAX ;When data number is outside range BC $EP_DASR_5 MOVW AX,d2SrcAdr INCW AX MOVW d2SrcAdr,AX ;advances search address for next data (+ 1 byte) BR EP_DASR_6 EP_DASR_5: MOV A,bDataBuf CALL !DataLeng ;Acquires data length from table CALL !WriteDataLength MOV X,#00H ADD A,d2SrcAdr XCH A,X ADDC A,d2SrcAdr+1 MOVW d2SrcAdr,AX ;Advances search address by data length for next ;data EP_DASR_6: CMP A,d2EndAdr+1 BNZ $EP_DASR_7 XCH A,X CMP A,d2EndAdr EP_DASR_7: BNC $EP_DASR_E ;Judges whether search pointer is within search ;block range BR EP_DASR_T EP_DASR_E: MOVW AX,d2DataAdr ;Return value = Search result of storage address ;(abnormal completion if 0000H) MOVW BC,AX POP HL RET ;------------------------------------------------------------------- ; Function name: SelfFlashBlockErase ; Input: A = Erase block number ; Output: C = Normal completion (TRUE: 00H) or abnormal completion (FALSE:F FH) ; Summary: Erases and performs blank check of the specified block. ; Remark: The following blank checks are performed twice. ; The purposes are different in each case. ; The first blank check determines whether empty space exists ; The second blank check determines whether empty space has been created by erasing blocks. ;------------------------------------------------------------------- SelfFlashBlockErase: PUSH HL XCH A,X PUSH AX MOVW AX,SP MOVW HL,AX MOV B,#ERASE_RETRY ;Sets retry count for erasure MOV A,[HL] ;Sets blank check block CALL !FlashBlockBlankCheck ;Blank check processing BZ $SF_BKER_TR ;If blank check error occurs, performs erase ;processing SF_BKER_RE: MOV A,[HL] ;Sets erase block CALL !FlashBlockErase ;Erase processing BNZ $SF_BKER_01 ;Abnormal completion MOV A,[HL] ;Sets blank check block CALL !FlashBlockBlankCheck ;Blank check processing BZ $SF_BKER_TR ;Blank check normally completed SF_BKER_01: DBNZ B,$SF_BKER_RE ;Checks retry count SF_BKER_FL: MOV A,#FALSE ;Return value = Abnormal completion BR SF_BKER_E SF_BKER_TR: MOV A,#TRUE ;Return value = Normal completion SF_BKER_E: MOV C,A POP AX POP HL RET ;------------------------------------------------------------------- ; Function name: SelfFlashModeOff ; Input: None ; Output: None ; Summary: Releases self programming mode. ;------------------------------------------------------------------- SelfFlashModeOff: MOV PFS,#NO_ERR MOV PFCMD,#0A5H ;PFCMD register control MOV FLPMC,#00H ;FLPMC register control (set value) MOV FLPMC,#0FFH ;FLPMC register control (inverted set value) MOV FLPMC,#00H ;Sets normal mode: FLPMC register control (set ;value) MOV A,PFS CMP A,#NO_ERR BNZ $SelfFlashModeOff ;Checks completion of write to special register EI MOVW AX,d2MaskStatus MOV MK1,A ;Delete this line when using 78K0S/KY1+ XCH A,X MOV MK0,A ;Restores interrupt mask flag RET ;------------------------------------------------------------------- ; Function name: SelfFlashModeOn ; Input: None ; Output: None ; Summary: Sets self programming mode. ;------------------------------------------------------------------- SelfFlashModeOn: MOV A,M