淺談?dòng)脝纹瑱C(jī)模擬PLC(山寨三菱系列)
下面是我的模擬程序,因?yàn)橹粚?shí)現(xiàn)了幾條指令而且還并不完善所以編譯程序和PLC指令表程序混在一起的,但這只是個(gè)思路因?yàn)槲野l(fā)現(xiàn)有些指令按我的辦法基本不能實(shí)現(xiàn)但也算是個(gè)開始后面再慢慢改進(jìn)吧,如果你想做一個(gè)更牛的可以去參考http://www.51hei.com/mcu/1985.html 下面是模擬編譯的程序:本文引用地址:http://m.butianyuan.cn/article/201612/324257.htm
#include
//指令表模擬
#define AND &&
#define ANI && !
#define LD if(
#define LDI if( !
#define OUT )
//輸入輸出指令模擬
#define X000 P1_0
#define Y000 P2_0=1; else P2_0=0;
#define X001 P1_1
#define Y001 P2_1=1; else P2_1=0;
#define X002 P1_2
#define Y002 P2_2=1; else P2_2=0;
#define X003 P1_3
#define Y003 P2_3=1; else P2_3=0;
#define X004 P1_4
#define Y004 P2_4=1; else P2_4=0;
#define X005 P1_5
#define Y005 P2_5=1; else P2_5=0;
#define X006 P1_6
#define Y006 P2_6=1; else P2_6=0;
#define X007 P1_7
#define Y007 P2_7=1; else P2_7=0;
//輸入輸出口資源定義
int P1_0,P2_0,P1_1,P2_1,P1_2,P2_2,P1_3,P2_3,P1_4,P2_4,P1_5,P2_5,P1_6,P2_6,P1_7,P2_7;
//初始化函數(shù)
void chushihua()
{
P1_0=0;
P2_0=0;
P1_1=0;
P2_1=0;
P1_2=0;
P2_2=0;
P1_3=0;
P2_3=0;
P1_4=0;
P2_4=0;
P1_5=0;
P2_5=0;
P1_6=0;
P2_6=0;
P1_7=0;
P2_7=0;
}
//顯示輸入輸出狀態(tài)
void shurushuchu()
{
printf("輸入輸出口狀態(tài)表");
printf("X0->%d X1->%d X2->%d X3->%d X4->%d X5->%d X6->%d X7->%d",P1_0,P1_1,P1_2,P1_3,P1_4,P1_5,P1_6,P1_7);
printf("Y0->%d Y1->%d Y2->%d Y3->%d Y4->%d Y5->%d Y6->%d Y7->%d",P2_0,P2_1,P2_2,P2_3,P2_4,P2_5,P2_6,P2_7);
}
//采集輸入狀態(tài)
void shuru()
{
printf("請更新輸入點(diǎn)狀態(tài)");
printf("X0<-");
scanf("%d",&P1_0);
printf("X1<-");
scanf("%d",&P1_1);
printf("X2<-");
scanf("%d",&P1_2);
printf("X3<-");
scanf("%d",&P1_3);
printf("X4<-");
scanf("%d",&P1_4);
printf("X5<-");
scanf("%d",&P1_5);
printf("X6<-");
scanf("%d",&P1_6);
printf("X7<-");
scanf("%d",&P1_7);
}
int main()
{
int x=0;
chushihua();
while(1)
{
shuru();
//進(jìn)入PLC指令表程序部分編譯器主體完工的話就能把這部分直接拿出來通過編譯器編譯了
LD X000
AND X002
ANI X001
OUT Y000
LD X003
AND X004
ANI X006
AND X007
OUT Y001
shurushuchu();
}
return 0;
}
評論