121 lines
4.3 KiB
C++
121 lines
4.3 KiB
C++
|
/********************************************************/
|
|||
|
// CPU<50><55>Ҫ<EFBFBD><D2AA>STM32F103--RAM<41>ڴ治С<E6B2BB><D0A1>64K Flash<73>ڴ治С<E6B2BB><D0A1>128K
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>STM32F103RDT6<54><36>VET6<54><36><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>
|
|||
|
// <20>༭<EFBFBD><E0BCAD><EFBFBD>ڣ<EFBFBD>20150909
|
|||
|
// editor by СС<D0A1><D0A1>
|
|||
|
// <20><><EFBFBD>꣺shop182385147.taobao.com
|
|||
|
/********************************************************/
|
|||
|
|
|||
|
#include "stm32f10x.h"
|
|||
|
#include "stm32f10x_flash.h"
|
|||
|
#include <stdio.h>
|
|||
|
#include "PLC_Dialogue.h"
|
|||
|
#include "PLC_CONF.H"
|
|||
|
extern u16 prog_write_buffer[2050];
|
|||
|
extern u16 PLC_16BIT[12100];
|
|||
|
extern const u16 *PLC_Addr; //<2F><>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|||
|
extern const u8 PLC_ROM[]; //PLC<4C><43><EFBFBD><EFBFBD><F2B4A2B4><EFBFBD>
|
|||
|
/***********************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD>PLCͨ<EFBFBD>Ŵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
D8063,M8063=<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ͨ<EFBFBD>Ŵ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
0000=<EFBFBD><EFBFBD><EFBFBD>쳣;
|
|||
|
6301=<EFBFBD><EFBFBD>ż<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
6302=ͨ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
6303=ͨ<EFBFBD>ź<EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
6304=<EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
6305=ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
***********************************************/
|
|||
|
void PLC_COMM_ERROR(u16 err_id)
|
|||
|
{
|
|||
|
if(err_id!=0)PLC_BIT_ON(M8063);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
D8063=err_id;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void write_data(u16 number)
|
|||
|
{
|
|||
|
u16 temp,appoint_address;
|
|||
|
if(number<12) //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD>10<31><30>
|
|||
|
{
|
|||
|
FLASH_Unlock(); //flash<73>رձ<D8B1><D5B1><EFBFBD>
|
|||
|
FLASH_ErasePage(PLC_RAM_ADDR+number*0x800); //erase page һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC>2K
|
|||
|
for(temp=0;temp<1024;temp++) //<2F><><EFBFBD><EFBFBD>Ϊ16bit,ֻ<><D6BB>Ҫ1024<32>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
appoint_address=PLC_RAM_ADDR+number*0x800+temp*2; //<2F><>ʼ<EFBFBD><CABC>ַ<EFBFBD><D6B7><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD>ַ<EFBFBD>ټ<EFBFBD><D9BC>Ͽ<EFBFBD><CFBF><EFBFBD>С<EFBFBD><D0A1>ַ,<2C><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>λ<EFBFBD><CEBB>
|
|||
|
FLASH_ProgramHalfWord(appoint_address,prog_write_buffer[temp]); //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
FLASH_Lock(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>뿪<EFBFBD><EBBFAA>flash<73><68><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void Read_data(u16 number) //<2F><><EFBFBD><EFBFBD><EFBFBD>鱸<EFBFBD><E9B1B8>,Ŀ<><C4BF><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>֮ǰ<D6AE><C7B0>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
u16 temp,appoint_address;
|
|||
|
if(number<12)
|
|||
|
{
|
|||
|
for(temp=0;temp<1024;temp++)
|
|||
|
{
|
|||
|
appoint_address=number*0x800+temp*2; //<2F><>ʼ<EFBFBD><CABC>ַ<EFBFBD><D6B7><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD>ַ<EFBFBD>ټ<EFBFBD><D9BC>Ͽ<EFBFBD><CFBF><EFBFBD>С<EFBFBD><D0A1>ַ
|
|||
|
prog_write_buffer[temp]=PLC_ROM[appoint_address]+(PLC_ROM[appoint_address+1]*0x100); //<2F><><EFBFBD><EFBFBD><EFBFBD>ݳ<F2B1B8B7><DDB3><EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
/***********************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
***********************************************/
|
|||
|
void PLC_DATA_KEEP(void)
|
|||
|
{
|
|||
|
u16 temp=0,backup_addr;
|
|||
|
for(backup_addr=(0x1000+500);backup_addr<(0x1000+950);backup_addr++) // <20><><EFBFBD><EFBFBD> 400 D <20><>Ԫ<EFBFBD><D4AA> D500
|
|||
|
prog_write_buffer[temp]=PLC_16BIT[backup_addr],temp++;
|
|||
|
|
|||
|
for(backup_addr=(0x0500+100);backup_addr<(0x0500+150);backup_addr++) // <20><><EFBFBD><EFBFBD> 50 T <20><>Ԫ<EFBFBD><D4AA> T100
|
|||
|
prog_write_buffer[temp]=PLC_16BIT[backup_addr],temp++;
|
|||
|
|
|||
|
for(backup_addr=(0x0800+100);backup_addr<(0x0800+150);backup_addr++) // <20><><EFBFBD><EFBFBD> 50 D Unit from C100
|
|||
|
prog_write_buffer[temp]=PLC_16BIT[backup_addr],temp++;
|
|||
|
|
|||
|
for(backup_addr=(0x0020);backup_addr<(0x0020+32);backup_addr++) // <20><><EFBFBD><EFBFBD> 512-M1023
|
|||
|
prog_write_buffer[temp]=PLC_16BIT[backup_addr],temp++;
|
|||
|
|
|||
|
write_data(10);
|
|||
|
}
|
|||
|
|
|||
|
/***********************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>λ
|
|||
|
***********************************************/
|
|||
|
void Recover_data(void)
|
|||
|
{
|
|||
|
u16 temp=0,backup_addr;
|
|||
|
Read_data(10);
|
|||
|
|
|||
|
for(backup_addr=(0x1000+500);backup_addr<(0x1000+950);backup_addr++)
|
|||
|
PLC_16BIT[backup_addr]=prog_write_buffer[temp],temp++;
|
|||
|
|
|||
|
for(backup_addr=(0x0500+100);backup_addr<(0x0500+150);backup_addr++)
|
|||
|
PLC_16BIT[backup_addr]=prog_write_buffer[temp],temp++;
|
|||
|
|
|||
|
for(backup_addr=(0x0800+100);backup_addr<(0x0800+150);backup_addr++)
|
|||
|
PLC_16BIT[backup_addr]=prog_write_buffer[temp],temp++;
|
|||
|
|
|||
|
for(backup_addr=(0x0020);backup_addr<(0x0020+32);backup_addr++)
|
|||
|
PLC_16BIT[backup_addr]=prog_write_buffer[temp],temp++;
|
|||
|
}
|
|||
|
|
|||
|
void RST_T_D_C_M_data(void) //ADD СС<D0A1><D0A1> 20151214
|
|||
|
{
|
|||
|
u16 backup_addr;
|
|||
|
for(backup_addr=(0x1000+0);backup_addr<(0x1000+8000);backup_addr++) //D0000-D8000 0X1000--0X2F40
|
|||
|
PLC_16BIT[backup_addr]=0;
|
|||
|
for(backup_addr=(0x0500+0);backup_addr<(0x0500+256);backup_addr++) //C0-C256
|
|||
|
PLC_16BIT[backup_addr]=0;
|
|||
|
for(backup_addr=(0x0800+0);backup_addr<(0x0800+256);backup_addr++) //T0-T256
|
|||
|
PLC_16BIT[backup_addr]=0;
|
|||
|
for(backup_addr=(0x0000);backup_addr<(0x0020+96);backup_addr++) //M0-M3096
|
|||
|
PLC_16BIT[backup_addr]=0;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|