C++具备类的创建思想很实用于实际场景多相似性的框架搭建;同种类型或相似类型的C++的优势明显因此进行相互嵌套使用
需要在C中使用C++类的话,你可以通过C++的“extern "C"”语法来实现。这允许你在C++代码中使用C的链接方式,而在C代码中使用C++的特性。
standard.cpp
#include "FB_Standard_TON.h"
#include "math.h"Class_FB_Standard_TON::Class_FB_Standard_TON()//¹¹Ô캯Êý--¿ÉÒÔ½øÐÐÓвÎÊýµÄÖØÔØ--->ÎÞ·µ»ØÀàÐÍ
{;
}
Class_FB_Standard_TON::~Class_FB_Standard_TON()//Îö¹¹º¯Êý
{;
}/***************·½·¨****************/
void Class_FB_Standard_TON::TON(u32 system_time_num,u16 PT_time,bool* IN,bool* out_Q)//¹¹Ô캯Êý--¿ÉÒÔ½øÐÐÓвÎÊýµÄÖØÔØ--->ÎÞ·µ»ØÀàÐÍ
{if((IN_old == false)&&(*IN == true)) {ton_step =100;star_time = system_time_num;}if(*IN == false) {ton_step =1000;*out_Q=0;}switch(ton_step){case 100:if ((system_time_num-star_time)>=PT_time)//²»ÓùØÐÄÒç³ö*out_Q = 1;break;default:*out_Q = 0;break;}IN_old = *IN;
}
standard.h
#ifndef __FB_STANDARD_TON__
#define __FB_STANDARD_TON__#include "applicfg.h"
#include "ObjDict.h"
#include <math.h>
#include "sys.h"extern "C" void FB_Standard_TON_LIB(u32 system_time_num,u16 PT_time,bool* IN,bool* out_Q);//CÓëC++µÄÖм䴫µÝº¯Êý--->Ò²³ÆΪ¼æÈݺ¯Êýclass Class_FB_Standard_TON{public:int ton_step;bool IN_old;u32 star_time;Class_FB_Standard_TON(void);//¹¹Ô캯Êý~Class_FB_Standard_TON(void);//Îö¹¹º¯Êývoid TON(u32 system_time_num,u16 PT_time,bool* IN,bool* out_Q);
};Class_FB_Standard_TON FB_Standard_TON;//ʵÀý»¯Ààvoid FB_Standard_TON_LIB(u32 system_time_num,u16 PT_time,bool* IN,bool* out_Q)//º¯ÊýÉùÃ÷
{FB_Standard_TON.TON(system_time_num,PT_time,IN,out_Q);//ÀàµÄ·½·¨µ÷ÓÃ
}#endif
C语言函数的调用
main.c
extern void FB_Standard_TON_LIB(u32 system_time_num,u16 PT_time,bool* IN,bool* out_Q);void test_ton()
{bool in,Q;FB_Standard_TON_LIB(SysTick->VAL,1000,&in,&Q);
}