信捷plc编程用c语言(C语言编译过程初探)

信捷PLC编程软件XDPPro,里面有arm-none-eabi的gcc程序,测试所用型号的SOC为ST的Cortex-M7用C语言编程的自由度很高,如果有能力接管编译过程,各种高级数据结构更是锦上添花,下面我们就来说一说关于信捷plc编程用c语言?我们一起去了解并探讨一下这个问题吧!

信捷plc编程用c语言(C语言编译过程初探)

信捷plc编程用c语言

信捷PLC编程软件XDPPro,里面有arm-none-eabi的gcc程序,测试所用型号的SOC为ST的Cortex-M7。用C语言编程的自由度很高,如果有能力接管编译过程,各种高级数据结构更是锦上添花。

初步测试了GCC的调用过程,从抓取到的一些信息看,用户手册中未详述的魔术操作,在源码中反而直白明了。

如果利用C语言开发出实用的数据结构和算法,这种小型PLC的应用场景还是很多的,毕竟有1MB的程序空间,要填满真不容易。附上gcc调用参数和文件核心内容:源码 -> *.c -> *.i

//XDPPro v3.7.4b, PLC XL5E-16 //调用记录arm-none-eabi-*.exe 2021-11-20 23:32:57.655 C:\XDPPro\TOOL\XD\bin\arm-none-eabi-gcc.exe -save-temps //保留临时文件,在*-gcc.exe同层文件夹中:FUNC1.i FUNC1.s ..\..\..\tmp\PrjFuncB\FUNC1.c -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -nostartfiles -o ..\..\..\tmp\PrjFuncB\FUNC1.o -I ..\inc -c -fsigned-char -g -ffunction-sections -mlittle-endian 2021-11-20 23:33:03.871 C:\XDPPro\TOOL\XD\bin\arm-none-eabi-ld.exe -T ..\..\..\tmp\PrjFuncB\stm32_flash.ld -Map=..\..\..\tmp\PrjFuncB\xd.map -s -o ..\..\..\tmp\PrjFuncB\xd.out ..\..\..\tmp\PrjFuncB\Ladder1.o ..\..\..\tmp\PrjFuncB\FUNC1.o ..\..\..\tmp\PrjFuncB\sysRegAddr.o ..\..\..\tmp\PrjFuncB\sysFuncAddr.o -L ..\lib\M7 -lm -lgcc -lc 2021-11-20 23:33:04.257 C:\XDPPro\TOOL\XD\bin\arm-none-eabi-objdump.exe -s -D -marm ..\..\..\tmp\PrjFuncB\xd.out 2021-11-20 23:33:07.555 C:\XDPPro\TOOL\XD\bin\arm-none-eabi-ld.exe -T ..\..\..\tmp\PrjFuncB\stm32_flash.ld -Map=..\..\..\tmp\PrjFuncB\xd.map -s -o ..\..\..\tmp\PrjFuncB\xd.out ..\..\..\tmp\PrjFuncB\TGLadder1.o -L ..\lib\M7 -lm -lgcc -lc 2021-11-20 23:33:07.930 C:\XDPPro\TOOL\XD\bin\arm-none-eabi-objdump.exe -s -D -marm ..\..\..\tmp\PrjFuncB\xd.out //end_//调用记录 //file:源文件_FUNC1 /************************************************************************* FunctionBlockName: FUNC1 Version: 1.0.0 Author: thj UpdateTime: 2021-11-14 16:39:43 Comment: abcd 12345678 **************************************************************************/ #define thj_FUNC1 void FUNC1(WORD W, BIT B) { #define SysRegAddr_HD_D_HM_M unsigned long* p0 = (unsigned long*)&D[0]; (*p0) ; #define pD4_Float (( float * ) &D[4]) * pD4_Float = 1.2345; //* ( ( float * ) &D[4] ) = 1.2345; strcpy((char*)&D[20], "a一二b1234"); //GB18030 *((wchar_t*)&D[30]) = L'\x1234'; *((double*)&D[40]) = sqrt(2); *((double*)&D[50]) = 1122334455.0; } //end_源文件 //file:FUNC1.c #define ARM_M7 #include "funcb.h" #define thj_FUNC1 void FUNC1(WORD W, BIT B) { asm("PUSH {R0}"); asm("MRS R0,CONTROL"); asm("ORR R0,R0,#0x1"); asm("MSR CONTROL,R0"); asm("POP {R0}"); short NeedCompileSysRegAddr; extern short __HD; short* HD = (short*)&__HD; char* B_HD = (char*)&__HD; extern short __D; short* D = (short*)&__D; char* B_D = (char*)&__D; extern char __HM; INT32U HM = (INT32U)&__HM; extern char __M; INT32U M = (INT32U)&__M; unsigned long* p0 = (unsigned long*)&D[0]; (*p0) ; #define pD4_Float (( float * ) &D[4]) * pD4_Float = 1.234; strcpy((char*)&D[20], "a一二b1234"); *((wchar_t*)&D[30]) = L'\x1234'; *((double*)&D[40]) = sqrt(2); *((double*)&D[50]) = 1122334455.0; asm("svc 0x01"); } //end_FUNC1.c //file:FUNC1.i void FUNC1_i(INT16S* W, INT32U B) { asm("PUSH {R0}"); asm("MRS R0,CONTROL"); asm("ORR R0,R0,#0x1"); asm("MSR CONTROL,R0"); asm("POP {R0}"); #define SysRegAddr_HD_D_HM_M short NeedCompileSysRegAddr; extern short __HD; short* HD = (short*)&__HD; char* B_HD = (char*)&__HD; extern short __D; short* D = (short*)&__D; char* B_D = (char*)&__D; extern char __HM; INT32U HM = (INT32U)&__HM; extern char __M; INT32U M = (INT32U)&__M; //end_define unsigned long* p0 = (unsigned long*)&D[0]; (*p0) ; *((float*)&D[4]) = 1.234; strcpy((char*)&D[20], "a一二b1234"); *((wchar_t*)&D[30]) = L'\x1234'; *((double*)&D[40]) = sqrt(2); *((double*)&D[50]) = 1122334455.0; asm("svc 0x01"); } //end_FUNC1.i

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页