发布于 2010-05-19 21:38:05
10楼
在这里我做个顺水人情了。
下面是我不记得在哪里得到的库的程序。我尽我的能力翻译了一点中文,自己基本上可以看明白。
导入即可。
SUBROUTINE_BLOCK 存EEPROM:SBR1
TITLE=##########################################################
// LICENSE:
// This program is distributed as freeware.
//
// Siemens makes no warranty, expressed or implied, with regard to this software. All implied warranties, including the warranties of merchantability and fitness for a particular use, are hereby excluded.
//
// Under no circumstances shall Siemens, or the authors of this product, be liable for any incidental or consequential damages, nor for any damages.
// ##########################################################
//
// This program is protected against unintentional delete.
// If you wish to modify the routine
// PASSWORD = EDIT
//
// ##########################################################
// ATTENTION: The values on the EEPROM could be stored about 100.000 times.
// After that the CPU will be DAMAGE.
// Be careful and store the data only when is necessary NOT continuously
// Example: If you store the data every hour they would live 11-12 years.
// ##########################################################
//
// This Routine store values of V-执行偏移 to the internal EEPROM.
//
// The Program start when Start=high.
// The Busy-Bit will indicate that the storage is in process.
// When the routine is finish the Busy=Low and Done=High.
// ( Do NOT reset the Done-Bit manually, this will be done automatically when the Start=Low )
//
// The program need three temporary variables: 执行偏移 as INT; Busy,Done as BOOL
//
// Example:
// store VB50,VB51,VB52,VB53,VB54 to EEPROM
// -------
//
// ----SM0.0----
//
//
// ---- M0.0 -----
//
// &VB50
// +5
// MW10
// Q1.0
// Q1.1 !! do not reset manually(手工地) the DONE-parameter, it will be automatically reset when START= Low !!
// ------
//
//
VAR_INPUT
开始:BOOL; // 开始例行程序
地址:DWORD;
长度:INT; // quantity of bytes to store
END_VAR
VAR_IN_OUT
执行偏移:INT; // temp. Memory for SMW32
忙:BOOL; // routine in process
完成:BOOL; // all bytes are stored
END_VAR
VAR
V首偏移:INT;
V末:INT;
V首址:DWORD;
END_VAR
BEGIN
Network 1 // When Start is not active then reset done (prepare for next pass)
LDN L0.0
R L9.1, 1
CRET
Network 2 // When Bytes are stored don`t process(进行) the subroutine anymore 保存完成后,开始标志要断开已使完成标志复位.
LD L9.1
CRET
Network 3 // If multiply instances of these library are used or another EEPROM storage is in process then exit subroutine 有其他程序正在使用保存过程就退出子程序.
LD SM31.7
CRET
Network 4 // Separate(分散) the V_Address and calculate(计划) the End-Address and set EEPROM storage(储存器) in Bytes
LD SM0.0
LPS
MOVD LD1, LD14
AENO
MOVW LW16, LW10
AENO
MOVW LW10, LW12
AENO
+I LW5, LW12
AENO
DECW LW12
LPP
MOVB 1, SMB31
Network 5 // In first scan transfer the V_Address to 执行偏移 and prepare(准备) the SMW32 to store the first value in EEPROM
LDN L9.0
MOVW LW10, LW7
AENO
MOVW LW7, SMW32
AENO
S L9.0, 1
S SM31.7, 1
CRET
Network 6 // Store in every CPU cycle one Byte more until all been stored (increment the SMW32-执行偏移 and Transfer to them)
LDW< SMW32, LW12
INCW LW7
AENO
MOVW LW7, SMW32
AENO
S SM31.7, 1
CRET // Wait for CPU to finish the store operation
Network 7 // If all Bytes are stored reset Busy and set the Finish-Bit
LDW>= LW7, LW12
R L9.0, 1
S L9.1, 1
END_SUBROUTINE_BLOCK