130 lines
3.6 KiB
C
130 lines
3.6 KiB
C
|
/************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: PLC_Dialogue
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> PLC<EFBFBD>괦<EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <EFBFBD><EFBFBD><EFBFBD>˼<EFBFBD>
|
|||
|
<EFBFBD>ա<EFBFBD><EFBFBD><EFBFBD>: 2015<EFBFBD><EFBFBD>7<EFBFBD><EFBFBD>22<EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: 1.1
|
|||
|
************************************************************/
|
|||
|
#ifndef __PLC_Dialogue_H__
|
|||
|
#define __PLC_Dialogue_H__
|
|||
|
#include "stm32f10x.h"
|
|||
|
|
|||
|
#ifdef __cplusplus
|
|||
|
extern "C" {
|
|||
|
#endif
|
|||
|
extern const unsigned char PLC_BIT_OR[];
|
|||
|
extern const unsigned char PLC_BIT_AND[];
|
|||
|
extern u8 PLC_8BIT[4]; //PLC_RAM<41><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
extern u8 Step_Address[2000]; //ΪPLS OR PLF use
|
|||
|
#ifdef __cplusplus
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
#define PLC_RAM_ADDR 0x8006000 //<2F><>ʼ<EFBFBD><CABC>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ϊ0X800000<30><30>ʼ<EFBFBD><CABC> 0X1000 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>дPLC<4C><43><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ҫ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
#define RAM_ADDR 0x20001000 //PLC_RAM<41><4D>ʼ<EFBFBD><CABC>ַ
|
|||
|
#define RAM_T_ADDR 0x20002000 //PLC T <20><>ʼ<EFBFBD><CABC>ַ
|
|||
|
#define RAM_C_ADDR 0x20001A00 //PLC C <20><>ʼ<EFBFBD><CABC>ַ
|
|||
|
#define RAM_D_ADDR 0x20003000 //PLC D <20><>ʼ<EFBFBD><CABC>ַ
|
|||
|
#define RAM_D1000_ADDR 0x200037D0 //PLC D1000 <20><>ʼ<EFBFBD><CABC>ַ
|
|||
|
#define RAM_D8000_ADDR 0x20001E00 //PLC D8000 <20><>ʼ<EFBFBD><CABC>ַ
|
|||
|
#define PLC_START_Address ((u16*)(0x800605c))//PLC<4C><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
|
|||
|
#define ROTATE_LEFT(x, s, n) ((x) << (n)) | ((x) >> ((s) - (n))) //ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> xΪ<78><CEAA><EFBFBD><EFBFBD> sΪ<73><CEAA><EFBFBD><EFBFBD>λ<EFBFBD><CEBB> nΪ<6E>ƶ<EFBFBD>λ<EFBFBD><CEBB>
|
|||
|
#define ROTATE_RIGHT(x, s, n) ((x) >> (n)) | ((x) << ((s) - (n))) //ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> xΪ<78><CEAA><EFBFBD><EFBFBD> sΪ<73><CEAA><EFBFBD><EFBFBD>λ<EFBFBD><CEBB> nΪ<6E>ƶ<EFBFBD>λ<EFBFBD><CEBB>
|
|||
|
|
|||
|
#define swap_u16(x) ((x) >> (8)) | ((x) << (8)) //<2F><><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
#define swap_u32(x) ((x) >> (16))|((x) << (16)) //<2F><><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
#define PLC_D_C_T_addr(x) ((x) % (0x4000)) //V,Z<><5A>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
#define PLC_v_z_addr(x) ((x) / (0x4000)) //V,Z<><5A>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
#define PLC_RAM8(x) (*(u8*)(u32)(x)) //<2F>ֽڷ<D6BD>ʽ R/W RAM R ROM
|
|||
|
|
|||
|
#define PLC_RAM16(x) (*(s16*)(u32)(x)) //<2F><><EFBFBD>ַ<EFBFBD>ʽ R/W RAM R ROM
|
|||
|
|
|||
|
#define PLC_RAM32(x) (*(s32*)(u32)(x)) //<2F>ַ<EFBFBD>ʽ R/W RAM R ROM
|
|||
|
|
|||
|
#define PLC_RAM64(x) (*(int64_t*)(u32)(x)) //<2F>ַ<EFBFBD>ʽ R/W RAM R ROM
|
|||
|
|
|||
|
#define PLC_RAMfolta(x) (*(float*)(u32)(x)) //<2F>ַ<EFBFBD>ʽ R/W RAM R ROM
|
|||
|
|
|||
|
#define trade1 FLOAT.DATA //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
#define PLC_8BIT(x) PLC_RAM8(RAM_ADDR+x)
|
|||
|
|
|||
|
#define PLC_BIT_TEST(x) (PLC_RAM8(RAM_ADDR+((x)/8)) & PLC_BIT_OR[(x)%8])
|
|||
|
|
|||
|
#define PLC_BIT_ON(x) (PLC_RAM8(RAM_ADDR+((x)/8)) |=PLC_BIT_OR[(x)%8])
|
|||
|
#define PLC_BIT_OFF(x) (PLC_RAM8(RAM_ADDR+((x)/8)) &=PLC_BIT_AND[(x)%8])
|
|||
|
|
|||
|
#define PLC_PL_BIT_ON(x) (Step_Address[(x)/8] |=PLC_BIT_OR[(x)%8]) //д״ֵ̬Ϊ1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD>ʹ<EFBFBD><CAB9>
|
|||
|
#define PLC_PL_BIT_OFF(x) (Step_Address[(x)/8] &=PLC_BIT_AND[(x)%8])//д<><D0B4>״̬Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD>ʹ<EFBFBD>ù<EFBFBD>2K<32>ֽ<EFBFBD>1600bit
|
|||
|
|
|||
|
#define on 1
|
|||
|
#define off 0
|
|||
|
|
|||
|
typedef union
|
|||
|
{
|
|||
|
struct
|
|||
|
{
|
|||
|
u8 bit0 :1;
|
|||
|
u8 bit1 :1;
|
|||
|
u8 bit2 :1;
|
|||
|
u8 bit3 :1;
|
|||
|
u8 bit4 :1;
|
|||
|
u8 bit5 :1;
|
|||
|
u8 bit6 :1;
|
|||
|
u8 bit7 :1;
|
|||
|
u8 bit10 :1;
|
|||
|
u8 bit11 :1;
|
|||
|
u8 bit12 :1;
|
|||
|
u8 bit13 :1;
|
|||
|
u8 bit14 :1;
|
|||
|
u8 bit15 :1;
|
|||
|
u8 bit16 :1;
|
|||
|
u8 bit17 :1;
|
|||
|
}bits; //<2F><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Ѱַ
|
|||
|
u16 bytes; //<2F><><EFBFBD><EFBFBD><D4B0>ֽ<EFBFBD>Ѱַ
|
|||
|
}bit_byte; //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ܰ<EFBFBD>λ<EFBFBD><CEBB>ѰַҲ<D6B7>ɰ<EFBFBD><C9B0>ֽ<EFBFBD>Ѱַ<D1B0><D6B7><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/*
|
|||
|
*16λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
typedef union
|
|||
|
{
|
|||
|
u8 PLC_8BIT[24200];
|
|||
|
u16 PLC_16BIT[12100];
|
|||
|
} union_16BIT;
|
|||
|
|
|||
|
/*
|
|||
|
*<EFBFBD><EFBFBD><EFBFBD>㹲ͬ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
typedef union
|
|||
|
{
|
|||
|
float DATA;
|
|||
|
u16 DATA1[2];
|
|||
|
u32 bata;
|
|||
|
} float_union;
|
|||
|
/*
|
|||
|
*32λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
typedef union
|
|||
|
{
|
|||
|
s32 data;
|
|||
|
s16 data1[2];
|
|||
|
} s32_union;
|
|||
|
/*
|
|||
|
*64λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
typedef union
|
|||
|
{
|
|||
|
int64_t data;
|
|||
|
u16 data1[4];
|
|||
|
} u64_union;
|
|||
|
|
|||
|
#endif
|
|||
|
|
|||
|
#ifndef __at
|
|||
|
#define __at(_addr) __attribute__ ((at(_addr)))
|
|||
|
#endif
|
|||
|
|