xiaoxiaocheng_plc/users/PLC_Com.c

996 lines
38 KiB
C
Raw Permalink Normal View History

2018-11-13 22:25:34 +08:00
/********************************************************/
// 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
/********************************************************
PLC<EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
ר<EFBFBD>ø<EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
M8126 ȫ<EFBFBD>ֱ<EFBFBD>־
M8127 ͨѶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>
M8128 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
M8129 ͨѶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
ר<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼĴ<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
D8000 = 200; ɨ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
D8001 = 0X5EF6; <EFBFBD>ͺŰ FX2N(C)
D8101 = 0X5EF6; <EFBFBD>ͺŰ FX2N(C)
D8002 = 8; <EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
D8102 = 8; <EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
D8003 = 0x0010; <EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
D8006 CPU<EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ѹ
D8010 = 10; ɨ<EFBFBD>ǰֵ
D8011 = 20; ɨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сʱ<EFBFBD><EFBFBD>(0.1MS)
D8012 = 140; ɨ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>(0.1MS)
D6030 D6031 D6032 D6033 <EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
D8080 D8081 <EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
D8120 = 0X4096 ͨѶ<EFBFBD><EFBFBD>ʽ
D8121 <EFBFBD><EFBFBD>վ<EFBFBD>ţ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>16<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
D8127 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD>׵<EFBFBD>ַ
D8128 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
D8129 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨѶ<EFBFBD><EFBFBD>ʱʱ<EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD>ֵ
D8000 <EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD>
D8019 <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
D8018 <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
D8017 <EFBFBD><EFBFBD>Ӧ<EFBFBD>·<EFBFBD>
D8016 <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
D8015 <EFBFBD><EFBFBD>ӦСʱ
D8014 <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
D8013 <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>
ͨѶ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>D8120<EFBFBD><EFBFBD>
----------------------------------------------------------------------
λ<EFBFBD><EFBFBD> | <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> | <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-----------+-------------+--------------------------------------------
b0 | <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD> | 0<EFBFBD><EFBFBD> 7λ 1<EFBFBD><EFBFBD> 8λ
-----------+-------------+--------------------------------------------
b2b1 | У<EFBFBD>ʽ | 00<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 01<EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD> 11<EFBFBD><EFBFBD>żУ<EFBFBD><EFBFBD>
-----------+-------------+--------------------------------------------
b3 | ֹͣλ | 0<EFBFBD><EFBFBD> 1λ 1<EFBFBD><EFBFBD> 2λ
-----------+-------------+--------------------------------------------
| | 0001<EFBFBD><EFBFBD>300 0111<EFBFBD><EFBFBD>4800
b7b6b5b4 | <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | 0100<EFBFBD><EFBFBD>600 1000<EFBFBD><EFBFBD>9600
| | 0101<EFBFBD><EFBFBD>1200 1001<EFBFBD><EFBFBD>19200
| | 0110<EFBFBD><EFBFBD>2400
-----------+-------------+--------------------------------------------
b8 | | 0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><EFBFBD>ͨѶר<EFBFBD><EFBFBD>
-----------+-------------+--------------------------------------------
b9 | | 0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ͬ<EFBFBD><EFBFBD>
-----------+-------------+--------------------------------------------
b12b11b10 | ͨѶ<EFBFBD>ӿ<EFBFBD> | 000<EFBFBD><EFBFBD>RS485<EFBFBD><EFBFBD>RS422<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
| | 010<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>RS232<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
-----------+-------------+--------------------------------------------
b13 | <EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD> | 0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-----------+-------------+-------------------------------------------
b14 | Э<EFBFBD><EFBFBD> | 0<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD><EFBFBD>ͨѶ 1<EFBFBD><EFBFBD>ר<EFBFBD><EFBFBD>ͨѶЭ<EFBFBD><EFBFBD>
-----------+-------------+--------------------------------------------
b15 | Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ | 0<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ1 1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ4
----------------------------------------------------------------------
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>D8120 = 0X4096 ͨѶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>19200
*********************************************************************************/
#include "stm32f10x.h"
#include "stm32f10x_flash.h"
#include <stdio.h>
#include "PLC_Dialogue.h"
#include "PLC_IO.h"
#include "PLC_CONF.H"
// #define flash_start_address 0x8006000
const u8 PLC_ROM[34000] __at (PLC_RAM_ADDR)={
//FLASH<53><48>ʼ<EFBFBD><CABC>ַΪPLC<4C><43>Ϣ**************************<2A><>ǰ<EFBFBD><C7B0>0X02<30><32>ʾPLCΪ16K<36>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>****************
0x10,0x00,0xD8,0xBA,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0xF4,0x09,0xFF,0x0B,0xF4,0x01,0xE7,0x03,0x64,0x0E,0xC7,0x0E,0xDC,0x0E,0xFF,0x0E,0x90,0x01,0xFE,0x03,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0X0F,0X00,//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,};
const u16 special_d[256]={
0X00C8,0X5EF6,0X0010,0X0010,0X0000,0X0025,0X001E,0X0000,0XFFFF,0X0000,
0X0000,0X0000,0X0000,0X00A5,0X00A5,0X00A5,0X00A5,0X00A5,0X0811,0X000F,
0X000A,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,
0X003D,0X001C,0X0000,0X0000,0X0014,0X00FF,0X03D7,0X0000,0X0000,0X0000,
0XFFFF,0XFFFF,0XFFFF,0XFFFF,0XFFFF,0XFFFF,0XFFFF,0XFFFF,0X0000,0XFFFF,
0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,
0X0000,0X0000,0X183B,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,
0X01F4,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,
0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,
0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,
0X0064,0X5EF6,0X0010,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,
0X0000,0X0000,0X0000,0X0000,0X0000,0X0000,0X0DDC,0X3DB6,0X0000,0X0000,
0X0000,0X0000,0X0000,0X0000,0X0002,0X0003,0X0000,0X0000};
const char Ascll[20]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0X41,0X42,0X43,0X44,0X45,0X46};
const char hex[]={
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,
0,10,11,12,13,14,15,0,0,0,0,0,0,};
u8 step_status[1000] __at (0x2000D200);
const u8 p_x[2] __at (0X8005000)={0x08,0x00}; // PLC_RAM_ADDR
u16 prog_write_buffer[2050];
static u8 Flag_Uart_Send=1; //<2F><><EFBFBD>ͱ<EFBFBD>־λ
u16 rx_count,tx_count; //<2F><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>
char tx_data[500]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD> 143
char rx_data[500]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD> 143
u16 prog_address,data_address; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
u16 PLC_16BIT[12100] __at (0x20001000); //PLC_RAM<41><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 PLC_8BIT[] __at (0x20000FFC); //PLC_RAM<41><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 Step_Address[2000]; //д<><D0B4>״̬Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD>ʹ<EFBFBD>ù<EFBFBD>2K<32>ֽ<EFBFBD>1600bit
u8 data_size,block_contol[2];
extern u8 edit_prog;
extern void RTC_Set(u16 syear,u8 smon,u8 sday,u8 hour,u8 min,u8 sec);
u8 Send_out;
u8 Write_Pro_flag = 0;
void data_init(void) //D8000~D8126<32><36>ʼ<EFBFBD><CABC>
{ //
u16 temp; //
u16 temp_address; //
prog_address=0x52; //
for(temp=0;temp<126;temp++) //
{ //
temp_address=0x0700; //ȡD8000<30><30>ʼ<EFBFBD><CABC>ַ0E00/2=0X700 ʹ<><CAB9>32λ<32><CEBB><EFBFBD><EFBFBD>
PLC_16BIT[temp_address+temp]=special_d[temp]; //<2F><><EFBFBD><EFBFBD>ϵͳFLASH<53><48><EFBFBD>ݵ<EFBFBD><DDB5>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
} //
PLC_16BIT[0X2000]=PLC_ROM[prog_address]; //ȡ<>ֽڸ<D6BD>λ
PLC_16BIT[0X2000]*=256; //
PLC_16BIT[0X2000]|=PLC_ROM[prog_address+1]; //ȡ<>ֽڵ<D6BD>λ
PLC_8BIT(0x01E0)=0x09; //<2F><>M8000 M8003<30><33>ON
block_contol[0]=200; //<2F><>ֹд<D6B9><D0B4><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ
block_contol[1]=200; //
} //
void write_block(u16 number) //д<><D0B4>FLASH
{
u16 temp,wait_write,appoint_address;
if(number<17) //д<><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); //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><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>
wait_write=prog_write_buffer[temp*2]+prog_write_buffer[temp*2+1]*0X100; //д<><D0B4>16bit<69><74>flash
FLASH_ProgramHalfWord(appoint_address,wait_write); //<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 backup_block(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<17)
{
for(temp=0;temp<2048;temp++)
{
appoint_address=number*0x800+temp; //<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]; //<2F><><EFBFBD><EFBFBD><EFBFBD>򱸷ݳ<F2B1B8B7><DDB3><EFBFBD>
}
}
}
void TX_Process(void) //<2F><><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(Flag_Uart_Send)
{
Send_out=Flag_Uart_Send = 0;
DMA1_Channel4->CNDTR = tx_count;//<2F><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
DMA1_Channel4->CCR |= 0x0001; //<2F><><EFBFBD><EFBFBD>DMA
}
}
//=======================================================================================================
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ErasurePLC
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PLC<4C><43><EFBFBD><EFBFBD>FLASH<53>ռ<EFBFBD>
// <20><EFBFBD><E4A1A1>: mode ģʽ
// <20><EFBFBD><E4A1A1>: void
// ȫ<>ֱ<EFBFBD><D6B1><EFBFBD>:
// <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>:
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: СС<D0A1><D0A1>
// <20>ա<EFBFBD><D5A1><EFBFBD>: 2014<31><34>5<EFBFBD><35>18<31><38>
// <20><> ע:
//-------------------------------------------------------------------------------------------------------
// <20>޸<EFBFBD><DEB8><EFBFBD>:
// <20>ա<EFBFBD><D5A1><EFBFBD>:
// <20><> ע:
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================
void ErasurePLC(u8 mode)
{
u16 temp=0,Erasure_PLC_16BIT;
/*******************************************PLC<4C><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD> ************************************************/
if(mode==1)
{
backup_block(0);
prog_write_buffer[92]=0x0f; //<2F><>ֵ
prog_write_buffer[93]=0x00; //<2F><>ֵ
for(temp=94;temp<2048;temp++) //<2F><>0x5E
{
prog_write_buffer[temp]=0xffff; //
}
FLASH_Unlock(); //flash<73>رձ<D8B1><D5B1><EFBFBD>
FLASH_ErasePage(PLC_RAM_ADDR+0x800); //
write_block(0); //<2F><><EFBFBD>ݵ<EFBFBD>һ<EFBFBD><D2BB>flash
for(temp=1;temp<10;temp++) //<2F><><EFBFBD><EFBFBD>10<31><30>
FLASH_ErasePage(PLC_RAM_ADDR+temp*0x800); //<2F><><EFBFBD><EFBFBD>flash
FLASH_Lock(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EBBFAA>flash<73><68><EFBFBD><EFBFBD>
}
/*******************************************PLC<4C><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>λ*********************************************/
if(mode==2)
{
for(Erasure_PLC_16BIT=0x2000;Erasure_PLC_16BIT<0x7E7E;Erasure_PLC_16BIT+=2) // <20><><EFBFBD><EFBFBD>D0000-D7999
PLC_8BIT(Erasure_PLC_16BIT)=0x00;
}
/*******************************************PLC<4C><43><EFBFBD><EFBFBD>λԪ<CEBB><D4AA> ***********************************************/
if(mode==3)
{
for(Erasure_PLC_16BIT=0x0000;Erasure_PLC_16BIT<0x00BE;Erasure_PLC_16BIT+=2) // <20><><EFBFBD><EFBFBD>M0000-M3071
PLC_8BIT(Erasure_PLC_16BIT)=0x00;
}
tx_data[1]=0x06,tx_count=1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><CFB1><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
}
/*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*******************************************************************************/
u8 check(char *MyD_str)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>
{
u16 temp;
u8 sum;
sum=0; //<2F><><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>
MyD_str+=3; //<2F><><EFBFBD><EFBFBD><EFBFBD>ʹӵ<CDB4><D3B5><EFBFBD>λ<EFBFBD><CEBB>ʼ
for(temp=3;temp<(rx_count-1);temp++)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
sum+=*MyD_str; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
MyD_str++; //ָ<><D6B8><EFBFBD><EFBFBD>һ
}
return sum; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
/*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>void switch_read_data(void)
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD>ת<EFBFBD><EFBFBD>ASCII<EFBFBD><EFBFBD>ΪHEX<EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><EFBFBD>ͼĴ<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
********************************************************************************/
void switch_read_data(void)
{
u16 temp;
for(temp=4;temp<(rx_count-2);temp++)
{
tx_data[temp/2]=hex[rx_data[temp]]*0x10;
tx_data[temp/2]+=hex[rx_data[temp+1]];
temp++;
}
}
void setup_HL(void) //<2F>ߵ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA> <20><>С<EFBFBD><D0A1>ת<EFBFBD><D7AA>
{
u8 temp;
temp=tx_data[3]; //<2F><>ַ<EFBFBD><D6B7>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>16λ<36><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
prog_address=temp*0x100+tx_data[2]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
}
void setup_LH(void) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַת<D6B7><D7AA>
{
u8 temp;
temp=tx_data[3]; //<2F><>ַ<EFBFBD><D6B7>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>16λ<36><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
data_address=temp*0x100+tx_data[4]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
}
typedef union
{
int data;
char data1[2];
} usart_data;
void read_plc_tyte(u8 addr) //<2F><>ȡPLC<4C>ͺ<EFBFBD> <20><><EFBFBD><EFBFBD>//ָ<>30<33><30>
{
u16 temp;
u8 temp_sum;
usart_data plc_type;
plc_type.data=special_d[addr]; //PLC<4C>ͺ<EFBFBD>
tx_data[1]=0x02; //<2F><><EFBFBD>Ŀ<EFBFBD>ʼ 02
temp_sum=0;
for(temp=0;temp<data_size;temp++)
{
tx_data[temp*2+2]=Ascll[plc_type.data1[temp]/0x10]; //ȡ<>ֽڸ<D6BD>λ
tx_data[temp*2+3]=Ascll[plc_type.data1[temp]%0x10]; //ȡ<>ֽڵ<D6BD>λ
temp_sum+=tx_data[temp*2+2]+tx_data[temp*2+3];
}
tx_data[temp*2+2]=0x03; //<2F><><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD> 03
temp_sum+=0x03;
tx_data[temp*2+3]=Ascll[temp_sum/0x10];
tx_data[temp*2+4]=Ascll[temp_sum%0x10];
tx_count=temp*2+4;
}
/*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣPPLC_Comm_Byte
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD>ֽڵ<EFBFBD>ַ<EFBFBD>ض<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Cmd<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʵ<EFBFBD>ַ(16BIT<EFBFBD><EFBFBD>ַ)
********************************************************************************/
u16 PLC_Comm_Byte(u16 comm_add)
{
if(comm_add>=0x4000&&comm_add<=0x7E7F){return comm_add-0x2000;}//D0000-D7999
else if(comm_add>=0x0280&&comm_add<=0x02FC){return comm_add-0x0280;}//S000-S999
else if(comm_add>=0x0240&&comm_add<=0x0256){return comm_add-0x01C0;}//X000-X277
else if(comm_add>=0x0180&&comm_add<=0x0196){return comm_add-0x00E0;}//Y000-Y267
else if(comm_add>=0x0200&&comm_add<=0x021F){return comm_add-0x0140;}//T00-T255 OVER<45><52><EFBFBD><EFBFBD>
else if(comm_add>=0x0500&&comm_add<=0x051F){return comm_add-0x0240;}//T00-T255 Enable <20><>Ȧ
else if(comm_add>=0x01E0&&comm_add<=0x01FF){return comm_add-0x0020;}//C00-C255 OVER<45><52><EFBFBD><EFBFBD>
else if( comm_add<=0x00BF){return comm_add+0x0100;}//M0000-M1535
else if(comm_add>=0x00C0&&comm_add<=0x017F){return comm_add+0x0440;}//M1536-M3071
else if(comm_add>=0x01C0&&comm_add<=0x01DF){return comm_add+0x0020;}//M8000-M8255
else{return comm_add;} //<2F><>Ч<EFBFBD><D0A7>ַ
}
/*******************************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>PLC_Com_BIT
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD>ͨ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>ַ<EFBFBD>ض<EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Cmd<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʵ<EFBFBD>ַ(BIT<EFBFBD><EFBFBD>ַ)
********************************************************************************/
u16 PLC_Com_BIT(u16 addr)
{
if((addr<=0x05FF)) return (addr+0x0800); //M0000-M1535
else if((addr>=0x0600)&&(addr<=0x0BFF)) return (addr+0x2200); //M1536-M3071
else if((addr>=0x0C00)&&(addr<=0x0CB7)) return (addr-0x0700); //Y00-Y267
else if((addr>=0x1200)&&(addr<=0x12BF)) return (addr-0x0E00); //X00-X267
else if((addr>=0x1400)&&(addr<=0x17E7)) return (addr-0X1400); //S00-S999
else if((addr>=0x2800)&&(addr<=0x28FF)) return (addr-0X1200); //T00-T255 Enable <20><>Ȧ
else if((addr>=0x1000)&&(addr<=0x10FF)) return (addr-0X0A00); //T00-T255 OVER <20><><EFBFBD><EFBFBD>
else if((addr>=0x0E00)&&(addr<=0x0EFF)) return (addr+0X0100); //M8000-M8255
else if((addr>=0x0F00)&&(addr<=0x0FFF)) return (addr-0X0100); //C00-C255 OVER<45><52><EFBFBD><EFBFBD>
else return addr;
}
//=======================================================================================================
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: void READ_data(void)
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> X,Y,M,S,T,C,D
// <20><EFBFBD><E4A1A1>: void
// <20><EFBFBD><E4A1A1>: void
// ȫ<>ֱ<EFBFBD><D6B1><EFBFBD>:
// <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>:
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: СС<D0A1><D0A1>
// <20>ա<EFBFBD><D5A1><EFBFBD>: 2014<31><34>6<EFBFBD><36>10<31><30>
// <20><> ע:
//-------------------------------------------------------------------------------------------------------
// <20>޸<EFBFBD><DEB8><EFBFBD>:
// <20>ա<EFBFBD><D5A1><EFBFBD>:
// <20><> ע:
//=======================================================================================================
void read_other_data(void) //ָ<>30<33><30>
{
u16 temp;
u8 temp_sum;
tx_data[1]=0x02; //<2F><><EFBFBD>Ŀ<EFBFBD>ʼ
temp_sum=0;
for(temp=0;temp<data_size;temp++)
{
tx_data[temp*2+2]=Ascll[PLC_8BIT(PLC_Comm_Byte(temp+prog_address))/0x10];//ȡ<>ֽڸ<D6BD>λ
tx_data[temp*2+3]=Ascll[PLC_8BIT(PLC_Comm_Byte(temp+prog_address))%0x10];//ȡ<>ֽڵ<D6BD>λ
temp_sum+=tx_data[temp*2+2]+tx_data[temp*2+3];
}
tx_data[temp*2+2]=0x03; //<2F><><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD> 03
temp_sum+=0x03;
tx_data[temp*2+3]=Ascll[temp_sum/0x10];
tx_data[temp*2+4]=Ascll[temp_sum%0x10];
tx_count=temp*2+4;
}
//=======================================================================================================
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: void READ_data(void)
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> д<><D0B4><EFBFBD><EFBFBD> X,Y,M,S,T,C,D
// <20><EFBFBD><E4A1A1>: void
// <20><EFBFBD><E4A1A1>: void
// ȫ<>ֱ<EFBFBD><D6B1><EFBFBD>:
// <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>:
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: СС<D0A1><D0A1>
// <20>ա<EFBFBD><D5A1><EFBFBD>: 2014<31><34>6<EFBFBD><36>10<31><30>
// <20><> ע:
//-------------------------------------------------------------------------------------------------------
// <20>޸<EFBFBD><DEB8><EFBFBD>:
// <20>ա<EFBFBD><D5A1><EFBFBD>:
// <20><> ע:
//=======================================================================================================
void PC_WRITE_byte(void) //д<><D0B4>
{
u16 temp;
prog_address=tx_data[2]*0x100+tx_data[3]+4;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
for(temp=0;temp<data_size;temp++)
{
PLC_8BIT(PLC_Comm_Byte(temp+prog_address))=tx_data[5+temp];
}
tx_data[1]=0x06,tx_count=1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
}
//=======================================================================================================
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: void FORCE_ON_data(void)
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> FORCE ON X,Y,M,S,T,C
// <20><EFBFBD><E4A1A1>: void
// <20><EFBFBD><E4A1A1>: void
// ȫ<>ֱ<EFBFBD><D6B1><EFBFBD>:
// <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>:
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: СС<D0A1><D0A1>
// <20>ա<EFBFBD><D5A1><EFBFBD>: 2014<31><34>6<EFBFBD><36>10<31><30>
// <20><> ע:
//-------------------------------------------------------------------------------------------------------
// <20>޸<EFBFBD><DEB8><EFBFBD>:
// <20>ա<EFBFBD><D5A1><EFBFBD>:
// <20><> ע:
//=======================================================================================================
void PC_FORCE_ON(void) //ǿ<><C7BF> 38 ON
{
PLC_BIT_ON(PLC_Com_BIT(tx_data[2]*0x100+tx_data[3]));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
tx_data[1]=0x06,tx_count=1;
}
//======================================================================================================
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: void FORCE_ON_data(void)
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> FORCE OFF X,Y,M,S,T,C
// <20><EFBFBD><E4A1A1>: void
// <20><EFBFBD><E4A1A1>: void
// ȫ<>ֱ<EFBFBD><D6B1><EFBFBD>:
// <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>:
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: СС<D0A1><D0A1>
// <20>ա<EFBFBD><D5A1><EFBFBD>: 2014<31><34>6<EFBFBD><36>10<31><30>
// <20><> ע:
//------------------------------------------------------------------------------------------------------
// <20>޸<EFBFBD><DEB8><EFBFBD>:
// <20>ա<EFBFBD><D5A1><EFBFBD>:
// <20><> ע:
//=======================================================================================================
void PC_FORCE_OFF(void) //ǿ<><C7BF> 37 OFF
{
PLC_BIT_OFF(PLC_Com_BIT(tx_data[2]*0x100+tx_data[3]));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
tx_data[1]=0x06,tx_count=1;
}
void PC_READ_byte(void) //<2F><><EFBFBD><EFBFBD>
{
prog_address=tx_data[2]*0x100+tx_data[3]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
switch(prog_address)
{
case 0x0ECA: read_plc_tyte(101); break; //<2F><>PLC TYPE
case 0x0E02: read_plc_tyte(1); break; //<2F><>PLC TYPE
default: read_other_data(); break;
}
}
void EPC_FORCE_ON(void) //ʹ<><CAB9><EFBFBD><EFBFBD>չ<EFBFBD><D5B9><EFBFBD><EFBFBD>"E"ǿ<><C7BF>ON
{
switch(prog_address)
{
case 0x0E23: break; // Զ<>̲<EFBFBD><CCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD>
case 0x0E24: PLC_8BIT(0X01E0)=0x09; Write_Pro_flag = 0; break; // Զ<>̲<EFBFBD><CCB2><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
case 0x0E25: PLC_8BIT(0X01E0)=0x0A; break; // Զ<>̲<EFBFBD><CCB2><EFBFBD><EFBFBD><EFBFBD>Ҫֹͣ
default: PLC_8BIT(0X01E0)=0x09; PLC_BIT_ON(PLC_Com_BIT(prog_address)); break; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
tx_data[1]=0x06,tx_count=1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
}
void EPC_FORCE_OFF(void) //ʹ<><CAB9><EFBFBD><EFBFBD>չ<EFBFBD><D5B9><EFBFBD><EFBFBD>"E"ǿ<><C7BF>OFF
{
PLC_BIT_OFF(PLC_Com_BIT(prog_address));
tx_data[1]=0x06,tx_count=1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
}
void PC_READ_Parameter(void) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> E00
{
u16 temp,temp_bit,temp_addr,mov_bit,temp1;
u8 temp_sum;
u8 send,monitor,monitor1,monitor2;
tx_data[1]=0x02; //<2F><><EFBFBD>Ŀ<EFBFBD>ʼ
temp_sum=0;
prog_address=PLC_Comm_Byte(tx_data[3]*0x100+tx_data[4]); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
if((prog_address==0x1790)||(prog_address==0x17D0)) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0X1790 <20><> 0X17D0<44><30>ַ
{
if(prog_address==0x1790)
{
monitor1=PLC_16BIT[0XA00]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0X1400/2=0XA00
for(temp1=monitor=0;monitor<monitor1;monitor++) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
temp_bit=PLC_Comm_Byte(PLC_16BIT[0XA02+monitor])/2;
PLC_16BIT[0xBC8+temp1]=PLC_16BIT[temp_bit];temp1++; //<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0X1790/2=0XBC8
if((temp_bit>=0x600)&&(temp_bit<=0x66E)) //<2F><>Ҫ<EFBFBD><D2AA>C200-C255<35>Ժ<EFBFBD><D4BA>ĵ<EFBFBD>ַ<EFBFBD><D6B7>32λ<32><CEBB>
{
PLC_16BIT[0xBC8+temp1]=PLC_16BIT[temp_bit+1]; //<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
temp1++;
}
}
monitor2=PLC_16BIT[0XA01]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
for(monitor1=0;monitor1<monitor2;monitor1++) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
{
temp_addr=PLC_Com_BIT(PLC_16BIT[0XA02+monitor+monitor1]);
temp_bit=PLC_16BIT[temp_addr/0x10];
mov_bit = temp_addr%0x10;
if((temp_bit&(1<<mov_bit))==(1<<mov_bit))
PLC_16BIT[0xBC8+temp1+monitor1/0x10]|=1<<(monitor1%0x10);//<2F><><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
else
PLC_16BIT[0xBC8+temp1+monitor1/0x10]&=~(1<<(monitor1%0x10));
}
}
}
for(temp=0;temp<data_size;temp++) //<2F><>RAM
{
send=PLC_8BIT(prog_address+temp);
tx_data[temp*2+2]=Ascll[send/0x10]; //ȡ<>ֽڸ<D6BD>λ
tx_data[temp*2+3]=Ascll[send%0x10]; //ȡ<>ֽڵ<D6BD>λ
temp_sum+=tx_data[temp*2+2]+tx_data[temp*2+3];
}
tx_data[temp*2+2]=0x03; //
temp_sum+=0x03;
tx_data[temp*2+3]=Ascll[temp_sum/0x10];
tx_data[temp*2+4]=Ascll[temp_sum%0x10];
tx_count=temp*2+4;
}
void PC_WRITE_Parameter(void) //д<><D0B4><EFBFBD><EFBFBD> E10
{
u16 temp;
prog_address=tx_data[3]*0x100+tx_data[4]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
for(temp=0;temp<data_size;temp++) //write RAM
{
PLC_8BIT(PLC_Comm_Byte(prog_address+temp))=tx_data[6+temp];
}
tx_data[1]=0x06,tx_count=1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
}
void PC_READ_PORG(void) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> E01
{
u16 temp;
u8 temp_sum;
tx_data[1]=0x02; //<2F><><EFBFBD>Ŀ<EFBFBD>ʼ
temp_sum=0;
data_address-=0x8000; //<2F><>FLASH <20><>ַ<EFBFBD><D6B7>0X8000<30><30><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>λ<EFBFBD><CEBB>
for(temp=0;temp<data_size;temp++)
{
tx_data[temp*2+2]=Ascll[PLC_ROM[data_address+temp]/0x10]; //ȡ<>ֽڸ<D6BD>λ
tx_data[temp*2+3]=Ascll[PLC_ROM[data_address+temp]%0x10]; //ȡ<>ֽڵ<D6BD>λ
temp_sum+=tx_data[temp*2+2]+tx_data[temp*2+3];
}
tx_data[temp*2+2]=0x03; //
temp_sum+=0x03;
tx_data[temp*2+3]=Ascll[temp_sum/0x10];
tx_data[temp*2+4]=Ascll[temp_sum%0x10];
tx_count=temp*2+4;
}
//void PC_WRITE_PORG(void) //д<><D0B4><EFBFBD><EFBFBD> E11
//{
// u16 temp;
// prog_address=tx_data[3]*0x100+tx_data[4]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
// edit_prog=0; //<2F>ѳ<EFBFBD><D1B3><EFBFBD><EFBFBD><EFBFBD><E0BCAD><EFBFBD><EFBFBD>,<2C><>Ϊд<CEAA><D0B4><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>P<EFBFBD><50>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E4BBAF>PLCӦ<43><D3A6><EFBFBD><EFBFBD>P<EFBFBD><50>ַ
// prog_address-=0x8000; //<2F><>ַ<EFBFBD><D6B7>0X8000<30><30><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>λ<EFBFBD><CEBB>
// for(temp=0;temp<data_size;temp++)
// {
// block_contol[0]=(prog_address+temp)/0x800; //ÿһ<C3BF><D2BB>ռ<EFBFBD>õĵ<C3B5>ַ 0X800<30><30>2K <20>ֽ<EFBFBD>
// if(block_contol[0]==block_contol[1]) //<2F>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>
// {
// prog_write_buffer[(prog_address+temp)-block_contol[0]*0x800]=tx_data[6+temp]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EBBBBA><EFBFBD><EFBFBD>
// }
// else //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><E9B4A6>
// {
// write_block(block_contol[1]); //<2F><>ǰһ<C7B0><D2BB>д<EFBFBD>뵽FLASH
// backup_block(block_contol[0]); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫд<D2AA><D0B4>FLASH<53><48>
// block_contol[1]=block_contol[0];
// prog_write_buffer[(prog_address+temp)-block_contol[0]*0x800]=tx_data[6+temp];
// }
// }
// tx_data[1]=0x06,tx_count=1;
//}
void PC_WRITE_PORG(void) //ADD СС<D0A1><D0A1> 20151118
{
u16 temp;
prog_address=(tx_data[3]*0x100+tx_data[4]);
PLC_8BIT(0X01E0)=0x0A;
Write_Pro_flag = 1; //<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD><D8B9><EFBFBD><EFBFBD>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ADD СС<D0A1><D0A1>
if(prog_address>0x7fff)
{
edit_prog=0;
prog_address-=0x8000;
for(temp=0;temp<data_size;temp++)
{
block_contol[0]=(prog_address+temp)/0x800;
if(block_contol[0]==block_contol[1])
{
prog_write_buffer[(prog_address+temp)-block_contol[0]*0x800]=tx_data[6+temp];
}
else
{
write_block(block_contol[1]);
backup_block(block_contol[0]);
block_contol[1]=block_contol[0];
prog_write_buffer[(prog_address+temp)-block_contol[0]*0x800]=tx_data[6+temp];
}
}
}
else
{
prog_address+=0x04;
for(temp=0;temp<data_size;temp++)
{
PLC_8BIT(PLC_Comm_Byte(temp+prog_address))=tx_data[6+temp];
}
}
tx_data[1]=0x06,tx_count=1;
// Write_Pro_flag = 0;
}
static u16 find_data(u16 addr,u16 find_data) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ
{
u8 find_ok,data_H,data_L;
find_ok=5;
data_H=find_data/0x100;
data_L=find_data%0x100;
addr-=0x8000;
do{
if((PLC_ROM[addr]==data_L)&&(PLC_ROM[addr+1]==data_H))
find_ok=0; //<2F>ҵ<EFBFBD><D2B5><EFBFBD>Ҫ<EFBFBD><D2AA>ָ<EFBFBD><D6B8>
else
addr+=2;
if(addr>(0xdedb-0x8000))
find_ok=1; //<2F><><EFBFBD><EFBFBD>Ч<EFBFBD>ķ<EFBFBD>Χ<EFBFBD><CEA7>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD>ENDָ<44><D6B8>
}while(find_ok>3);
addr+=0X8000;
return addr;
}
void find_data_address(void) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ
{
u8 temp_sum,data_H,data_L;
data_L=tx_data[5]; //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>ݵ<EFBFBD>λ
data_H=tx_data[6]; //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>ݸ<EFBFBD>λ
data_address=find_data(data_address,data_H*0X100+data_L); //<2F><>FLASH
tx_data[1]=0x02; //<2F><><EFBFBD>Ŀ<EFBFBD>ʼ
temp_sum=0;
tx_data[2]=0x31;
temp_sum+=tx_data[2];
data_H=data_address/0x100;
data_L=data_address%0x100;
tx_data[3]=Ascll[data_H/0X10];
tx_data[4]=Ascll[data_H%0X10];
tx_data[5]=Ascll[data_L/0X10];
tx_data[6]=Ascll[data_L%0X10];
tx_data[7]=0X03;
temp_sum+=tx_data[3];
temp_sum+=tx_data[4];
temp_sum+=tx_data[5];
temp_sum+=tx_data[6];
temp_sum+=tx_data[7];
tx_data[8]=Ascll[temp_sum/0x10];
tx_data[9]=Ascll[temp_sum%0x10];
tx_count=9;
}
void backup_mov_block(u16 number)
{
u16 temp,appoint_address;
if(number<10)
{
for(temp=0;temp<2048;temp++)
{
appoint_address=number*0x800+temp;
prog_write_buffer[temp]=p_x[appoint_address];
}
}
}
void mov_flash(u16 addr,u8 mov_addr)
{
u16 start_addr,end_addr,backup_addr,temp,temp1,temp2,mov_byte,addr_mov;
static u8 offset;
offset=mov_addr;
end_addr=find_data(addr+0x8000,0x000f)+mov_addr-0x8000;
start_addr=end_addr;
addr_mov=addr;
if(addr>0x5B)
{
addr_mov-=0X5C;
end_addr-=0x5C;
addr_mov/=2;
end_addr/=2;
addr_mov/=8;
end_addr/=8;
offset/=2;
mov_byte=offset/8;
offset%=8;
while(!(end_addr==addr_mov))
{
temp=step_status[end_addr]*0x100+step_status[end_addr-1];
temp<<=offset;
step_status[end_addr+mov_byte]=temp/0x100;
end_addr--;
}
temp=step_status[end_addr]*0x100+step_status[end_addr-1];
temp<<=offset;
step_status[end_addr+mov_byte]=temp/0x100;
}
end_addr=start_addr;
temp=start_addr;
do{
if((end_addr/0x800)==(addr/0x800))
start_addr=addr%0x800;
else
start_addr=0;
if((temp/0x800)==(end_addr/0x800))
temp1=end_addr%0x800+1;
else
temp1=2048;
backup_block(end_addr/0x800);
for(temp2=start_addr;temp2<temp1+1;temp2++)
{
backup_addr=(end_addr/0x800)*0x800+temp2-mov_addr;
prog_write_buffer[temp2]=p_x[backup_addr];
}
write_block(end_addr/0x800);
end_addr-=(temp1-start_addr);
}while(end_addr>addr+mov_addr);
}
void online_write_data(void)
{
u16 temp;
u8 temp1,temp2;
temp1=tx_data[5];
temp2=tx_data[6];
temp2-=temp1;
if(temp2>0)
{
mov_flash(data_address-0x8000,temp2);
}
edit_prog=0;
block_contol[0]=100;
block_contol[1]=100;
prog_address=(tx_data[3]*0x100+tx_data[4])-0x8000;
data_size=tx_data[6];
for(temp=0;temp<data_size;temp++)
{
block_contol[0]=(prog_address+temp)/0x800;
if(block_contol[0]==block_contol[1])
{
prog_write_buffer[(prog_address+temp)-block_contol[0]*0x800]=tx_data[7+temp];
}
else
{
write_block(block_contol[1]);
backup_block(block_contol[0]);
block_contol[1]=block_contol[0];
prog_write_buffer[(prog_address+temp)-block_contol[0]*0x800]=tx_data[7+temp];
}
}
write_block(block_contol[0]);
tx_data[1]=0x06,tx_count=1;
}
void all_flash_unlock(void) //FLASHȫ<48><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
block_contol[1]=200;
block_contol[0]=200;
tx_data[1]=0x06,tx_count=1;
}
void all_flash_lock(void) //FLASHȫ<48><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
write_block(block_contol[1]); //<2F><><EFBFBD><EFBFBD>֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>FLASH
block_contol[1]=200;
block_contol[0]=200;
FLASH_Lock();
tx_data[1]=0x06,tx_count=1;
}
void PC_OPTION_PROG(void) //<2F><>չ<EFBFBD><D5B9><EFBFBD><EFBFBD> "E" <20><><EFBFBD><EFBFBD>
{
u16 temp;
if((rx_count==11)&&((rx_data[4]==0x37)||(rx_data[4]==0x38)))//<2F>Ƿ<EFBFBD>Ϊǿ<CEAA>ƹ<EFBFBD><C6B9><EFBFBD>
{
prog_address=hex[rx_data[5]]*0x10+hex[rx_data[6]]+hex[rx_data[7]]*0x1000+hex[rx_data[8]]*0x100;
if(rx_data[4]==0x37)
{
EPC_FORCE_ON();
}
else
EPC_FORCE_OFF();
}
else
{
setup_LH(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
temp=tx_data[2];
switch(temp)
{
case 0x00: PC_READ_Parameter(); break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> E00
case 0x10: PC_WRITE_Parameter(); break; //д<><D0B4><EFBFBD><EFBFBD> E10
case 0x01: PC_READ_PORG(); break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> E01
case 0x11: PC_WRITE_PORG(); break; //д<><D0B4><EFBFBD><EFBFBD> E11
case 0x77: all_flash_unlock(); break; //ʹ<><CAB9><45><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>77
case 0x87: all_flash_lock(); break; //ʹ<><CAB9><45><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>87
case 0x41: find_data_address(); break; //<2F><><EFBFBD><EFBFBD>ENDָ<44><D6B8><EFBFBD><EFBFBD>ַ
case 0x61: all_flash_unlock(); break; //PLC<4C><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD> ӦΪ<D3A6>·<EFBFBD><C2B7>˶<EFBFBD><CBB6><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FLASHȫ<48><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case 0x60: ErasurePLC(1); break; //PLC<4C><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
case 0x63: ErasurePLC(2); break; //PLC<4C><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>λ
case 0x62: ErasurePLC(3); break; //PLC<4C><43><EFBFBD><EFBFBD>λԪ<CEBB><D4AA>
case 0xD1: online_write_data(); break;
default: tx_data[1]=0x15,tx_count=1;break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>
}
}
}
void find_end(void) //<2F><><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ENDָ<44>
{
if(rx_count==13)
tx_data[1]=0x06,tx_count=1;
else
tx_data[1]=0x06,tx_count=1;
}
void Process_switch(void)
{
u8 temp;
switch_read_data(); //<2F>ѵ<EFBFBD><D1B5><EFBFBD>λ<EFBFBD><CEBB>ʼ<EFBFBD><CABC>ASCII<49><49>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>HEX <09><><EFBFBD><EFBFBD>ַΪ<D6B7><CEAA><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD><EFBFBD><EFBFBD>
temp=rx_data[3];
switch(temp)
{
case 0x30: data_size=tx_data[4],PC_READ_byte(); break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>tx_data[4]<5D><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case 0x31: data_size=tx_data[4];PC_WRITE_byte(); break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>tx_data[4]<5D><> д<><D0B4><EFBFBD><EFBFBD>
case 0x34: find_end(); break; //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EEA3AC><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򷵻<EFBFBD>6
case 0x37: setup_HL(),PC_FORCE_ON(); break; //PLC <09><><EFBFBD><EFBFBD> Զ<><D4B6> <20><>0x37<33><37>
case 0x38: setup_HL(),PC_FORCE_OFF(); break; //PLC ֹͣ Զ<><D4B6> <20><>0x38<33><38>
case 0x42: all_flash_lock(); break; //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
case 0x45: data_size=tx_data[5],PC_OPTION_PROG();break; //E<><45><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
default: break;
}
if((tx_count==0)&&(rx_count==0)) //return error code for 0x15
tx_data[1]=0x15,tx_count=1;
rx_count=0;Send_out=1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
}
void usart(u16 DEFAULT_BAUD)
{
USART_InitTypeDef USART_InitStructure; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>üĴ<C3BC><C4B4><EFBFBD>
USART_InitStructure.USART_BaudRate = DEFAULT_BAUD; //<2F><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //8λ<38><CEBB><EFBFBD><EFBFBD>λ
USART_InitStructure.USART_StopBits = USART_StopBits_1; //һλֹͣλ
USART_InitStructure.USART_Parity = USART_Parity_No; //У<><D0A3>λ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(USART1,&USART_InitStructure); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
//---------------------<2D><><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>---------------------
void USART1_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure; //DMA<4D><41>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><E1B9B9>
GPIO_InitTypeDef GPIO_InitStructure; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>üĴ<C3BC><C4B4><EFBFBD>
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 , ENABLE); //<2F>򿪴<EFBFBD><F2BFAAB4>ڶ<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //<2F><><EFBFBD><EFBFBD>DMAʱ<41><CAB1>
DMA_DeInit(DMA1_Channel4); //DMA1ͨ<31><CDA8>4<EFBFBD><34><EFBFBD><EFBFBD>
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&USART1->DR);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)tx_data+1; //<2F>ڴ<EFBFBD><DAB4><EFBFBD>ַ
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //dma<6D><61><EFBFBD><EFBFBD><E4B7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DMA_InitStructure.DMA_BufferSize = 143; //<2F><><EFBFBD><EFBFBD>DMA<4D>ڴ<EFBFBD><DAB4><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//<2F><><EFBFBD><EFBFBD>DMA<4D><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //<2F><><EFBFBD><EFBFBD>DMA<4D><41><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>ģʽ
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֳ<EFBFBD>
DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_Byte;//<2F>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֳ<EFBFBD>
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; //<2F><><EFBFBD><EFBFBD>DMA<4D>Ĵ<EFBFBD><C4B4><EFBFBD>ģʽ
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //<2F><><EFBFBD><EFBFBD>DMA<4D><41><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD>
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //<2F><><EFBFBD><EFBFBD>DMA<4D><41>2<EFBFBD><32>memory<72>еı<D0B5><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DMA_Init(DMA1_Channel4,&DMA_InitStructure);
DMA_ITConfig(DMA1_Channel4,DMA_IT_TC,ENABLE);
usart(19200); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//TXE<58><45><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>,TC<54><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>,RXNE<4E><45><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>,PE<50><45>ż<EFBFBD><C5BC><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD>
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE);//<2F><><EFBFBD><EFBFBD>DMA<4D><41>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
USART_Cmd(USART1, ENABLE); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//*********************<2A><><EFBFBD><EFBFBD>1<EFBFBD>Ĺܽų<DCBD>ʼ<EFBFBD><CABC> ****************************************
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //<2F>ܽ<EFBFBD>9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //ѡ<><D1A1>GPIO<49><4F>Ӧ<EFBFBD>ٶ<EFBFBD>
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOA, &GPIO_InitStructure); //TX<54><58>ʼ<EFBFBD><CABC>
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //<2F>ܽ<EFBFBD>10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_Init(GPIOA, &GPIO_InitStructure); //RX<52><58>ʼ<EFBFBD><CABC>
}
void DMA1_Channel4_IRQHandler(void) //<2F><><EFBFBD><EFBFBD>1DMA<4D><41>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
{
DMA1->IFCR |= DMA1_FLAG_TC4; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
DMA1_Channel4->CCR &= 0xFFFE; //<2F>ر<EFBFBD>DMA
Flag_Uart_Send = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD>ٴη<D9B4><CEB7><EFBFBD>
}
void RX_Process(void) //<2F><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
static u8 sum,f=1;
rx_data[0]=0x7f&USART1->DR;
if(rx_data[0]==0X05) //<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD>
rx_count=0,tx_data[1]=0x06,tx_count=1,TX_Process(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD><D2B7><EFBFBD>0X06Ӧ<36><D3A6>
else if(rx_data[0]==0X02) //<2F><><EFBFBD>Ŀ<EFBFBD>ʼ
{rx_count=0x01;}
else if(rx_count==0)
{
if(f==1)
{
usart(19200);
rx_count=0,tx_data[1]=0x06,tx_count=1,TX_Process();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD><D2B7><EFBFBD>0X06Ӧ<36><D3A6>
f=0;
}
else if(f==0)
{
usart(9600);
rx_count=0,tx_data[1]=0x06,tx_count=1,TX_Process();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD><D2B7><EFBFBD>0X06Ӧ<36><D3A6>
f=1;
}
}
if(rx_count>0) //ȷ<>ϱ<EFBFBD><CFB1>Ŀ<EFBFBD>ʼ
{
rx_count++;
rx_data[rx_count]=rx_data[0];
if(rx_count>400) //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>143
tx_count=0,rx_count=0;
if((rx_count>3)&&(rx_data[rx_count-2]==0x03)) //<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD>
{
sum = check(rx_data);
if((rx_data[rx_count-1] == Ascll[sum/0x10])&&(rx_data[rx_count] == Ascll[sum%0x10]))// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD>״̬ <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
{
Process_switch();
}
else
tx_data[1]=0x15,tx_count=1,TX_Process(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>һش<D2BB><D8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECB3A3>ֵ0X15
}
}
}
void USART1_IRQHandler(void) //<2F>жϵ<D0B6><CFB5><EFBFBD>
{
if(USART_GetITStatus(USART1,USART_IT_RXNE)==SET) //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
RX_Process();
}
//<2F><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ȶ<EFBFBD>SR,<2C>ٶ<EFBFBD>DR<44>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϵ<D0B6><CFB5><EFBFBD><EFBFBD><EFBFBD>
if(USART_GetFlagStatus(USART1,USART_FLAG_ORE)==SET)
{
USART_ClearFlag(USART1,USART_FLAG_ORE); //<2F><>SR<53><52>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
USART_ReceiveData(USART1); //<2F><>DR
}
if(USART_GetITStatus(USART1, USART_IT_TXE)==SET)
{
USART_ClearITPendingBit(USART1,USART_IT_TXE);
USART_ITConfig(USART1,USART_IT_TXE,DISABLE);
}
if(USART_GetITStatus(USART1, USART_IT_TC)==SET) //<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
{
USART_ClearITPendingBit(USART1,USART_IT_TC);
}
}