XDSingleYYaJi.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. #include "global.h"
  2. #if XI_DONG_MACHINE
  3. /**************************************
  4. ** 函数名称:void SYYAJi(void)
  5. ** 函数功能:方块插稍机动作函数
  6. ** 输入输出说明:
  7. 输入:
  8. X0 启动开关
  9. X1 停止开关(做完当条停机)
  10. X2 紧急停机开关
  11. X3 左计数接近开关
  12. X4 右计数接近开关
  13. X5 注油机液位开关
  14. X6 注油机液压开关
  15. X7 铜线故障
  16. X10 成型故障
  17. X11 卡带故障(布带1)
  18. X12 没带故障(布带2)
  19. X13 送带故障(布带3)
  20. X14 合链上限、下限位开关(合链1)
  21. X15 缺牙开关(合链2)
  22. X16 缺牙开关(合链3)
  23. X17 左送料开关上限(关)
  24. X20 左送料下限开关(开)
  25. X21 右送料上限开关(关)
  26. X22 右送料下限开关(开)
  27. X23 并链机上限开关(关)
  28. X24 并链机下限开关(开)
  29. X25 接头输入
  30. X26
  31. X27
  32. 输出:
  33. Y0 蜂鸣器
  34. Y1 左直流电磁铁(进)
  35. Y2 左直流电磁铁(出)
  36. Y3 右直流电磁铁(进)
  37. Y4 右直流电磁铁(出)
  38. Y5 主电机
  39. Y6 注油机
  40. Y7 左、右送带电机
  41. Y10 压链电机
  42. Y11 合链电机
  43. Y12 合链电磁铁
  44. Y13 左送料电机
  45. Y14 右送料电机
  46. Y15 并链电机
  47. Y16
  48. Y017
  49. ***************************************/
  50. void SYY_Right_Action(void);
  51. void SYY_ZhuYou(void); //注油
  52. void SYY_Start(void);
  53. void SYY_Error_Action(void);
  54. void SYY_SongLiao(void); //送料动作(送丝)
  55. void SYY_Lelf_Action(void); //左边排牙动作
  56. void SYY_Right_Action(void); //右边排牙动作
  57. void SYY_StartZYFirst(void);
  58. void SYY_Stop_Action(void);
  59. // 左右启动计数选择,复位时6空6牙
  60. short SYY_cDBuff,SYY_StartZYFlag = 0,SYY_cStartPYFlag_Left,SYY_cStartPYFlag_Right,SYY_cClr_Flag,
  61. SYY_cHeLian,SYY_cZhuYou,SYY_cWriflash,SYY_cTatal_OK,SYY_cTestTime;
  62. unsigned long SYY_cTotalTength,SYY_cCountTime = 0,SYY_cJieKou,SYY_cJieDaiTotal,SYY_cJieDaiClrTotal,SYY_cJieDai_Flag,SYY_cJieDaiWeiZi,cDelayTime17;
  63. unsigned long SYY_cTotal;
  64. unsigned char SYY_cStart_Right_EN = 0,SYY_bRunning,SYY_bStop;
  65. void SYY_SetAlarmCode(unsigned alarm_code)
  66. {
  67. SetAlarmCode(SYY_ALARM_ADDR,alarm_code);
  68. SYY_bStop = 1;
  69. }
  70. void SYYa_InitAction(void)
  71. {
  72. XGearRatio = 1;
  73. YGearRatio = 1;
  74. }
  75. void SYYa_Action(void)
  76. {
  77. if(SYY_StartZYFlag == 0)
  78. {
  79. SYY_cTotalTength = ((unsigned long)user_datas[98] << 16) + user_datas[97]; //累计
  80. //停机1小时以上
  81. SYY_StartZYFlag = 1;
  82. SYY_StartZYFirst();
  83. M15 = 1;
  84. SYY_cClr_Flag = user_datas[105];
  85. SYY_cJieDai_Flag = user_datas[103];
  86. SYY_cJieDaiTotal = user_datas[102];
  87. SYY_cJieDaiClrTotal = user_datas[104];
  88. }
  89. user_datas[121] = SYY_cJieDaiTotal;
  90. user_datas[122] = SYY_cJieDaiClrTotal;
  91. user_datas[123] = SYY_cJieDai_Flag;
  92. user_datas[124] = SYY_cJieDaiWeiZi;
  93. user_datas[125] = user_datas[68];
  94. user_datas[126] = user_datas[69];
  95. user_datas[127] = user_datas[65];
  96. user_datas[128] = user_datas[66];
  97. //接头检测
  98. if(X25_UP) //空位
  99. {
  100. SYY_cJieDaiTotal = user_datas[6] + 6;
  101. SYY_cJieDaiClrTotal = 0;
  102. SYY_cJieDai_Flag = 1;
  103. SETY015();
  104. }
  105. else if(X25_DW)
  106. {
  107. CLRY015();
  108. SYY_cJieDaiClrTotal += 6;
  109. SYY_cJieDai_Flag = 2;
  110. if(SYY_cJieDaiTotal == 0)
  111. {
  112. SYY_cJieDaiTotal = user_datas[6] + 6;
  113. }
  114. else
  115. {
  116. }
  117. }
  118. SYY_ZhuYou(); //注油
  119. SYY_Start();
  120. SYY_Error_Action();
  121. SYY_SongLiao(); //送料动作(送丝)
  122. SYY_Lelf_Action(); //左边排牙动作
  123. SYY_Right_Action(); //右边排牙动作
  124. //旋转电磁铁动作
  125. if((Y001 || Y002) && (dwTickCount >= cDelayTime6)) //左边
  126. {
  127. CLRY001();
  128. CLRY002();
  129. }
  130. if((Y003 || Y004) && (dwTickCount >= cDelayTime7)) //右边
  131. {
  132. CLRY003();
  133. CLRY004();
  134. }
  135. //合链机启动
  136. if(M4)
  137. {
  138. if(X024)
  139. {
  140. SETY010();
  141. SETY011();
  142. }
  143. else if(X023 != 0)
  144. {
  145. CLRY010();
  146. CLRY011();
  147. }
  148. }
  149. else
  150. {
  151. CLRY010();
  152. CLRY011();
  153. }
  154. //做完一条输出
  155. if(Y016 && (dwTickCount >= cDelayTime17))
  156. {
  157. CLRY016();
  158. }
  159. //排牙电机
  160. if(M2)
  161. {
  162. M2 = 0;
  163. if(Y005)
  164. {
  165. if(M7 == 0)M6 = 0; //M6 排牙控制
  166. }
  167. else if(M3 && (M0100 == 0))
  168. M6 = 1; //M6 排牙控制
  169. }
  170. if(M6)
  171. {
  172. if(Y005 == 0)
  173. {
  174. cDelayTime1 = dwTickCount + (unsigned long)100 * 10; //启动后延时判断出错
  175. cDelayTime2 = dwTickCount; //累计时间启动
  176. //每次启动电机时启动注油时间
  177. SETY006();
  178. cDelayTime8 = dwTickCount + (unsigned long)user_datas[2] * 1000; //注油时间 秒
  179. cDelayTime3 = dwTickCount + (unsigned long)6000; //延时检测油压
  180. }
  181. SETY005(); //排牙主电机
  182. SETY007(); //左右送布带电机
  183. }
  184. else
  185. {
  186. if(Y005)
  187. {
  188. cDelayTime1 = dwTickCount + (unsigned long)45 * 10; //关闭后延时判断出错
  189. }
  190. CLRY005(); //排牙电机
  191. CLRY007(); //左右送布带电机
  192. }
  193. //产量清零
  194. if(M9)
  195. {
  196. M9 = 0;
  197. ClrcToTal(97);
  198. SYY_cTotalTength = ((unsigned long)user_datas[98] << 16) + user_datas[97]; //累计
  199. M15 = 1; //M15
  200. user_datas[86] = 0; //小时清零
  201. user_datas[87] = 0; //分钟清零
  202. user_datas[88] = 0; //累计时间
  203. }
  204. }
  205. void SYY_cTotal_Time(void)
  206. {
  207. unsigned long i,ch,k;
  208. SYY_cTotal = (unsigned long)(user_datas[77] << 16) + (unsigned long)user_datas[76];
  209. //一条的长度 mm
  210. k = (user_datas[67]+ user_datas[64]) * user_datas[0] *157/user_datas[1]/500;
  211. user_datas[102] = k%0x10000;
  212. user_datas[103] = k/0x10000;
  213. i = k * SYY_cTotal; //累积长度MM
  214. user_datas[104] = i%0x10000;
  215. user_datas[105] = i/0x10000;
  216. if(user_datas[68] == 0)
  217. {
  218. ch = (user_datas[65]); //加已打齿数
  219. }
  220. else
  221. {
  222. ch = user_datas[64] + user_datas[68]; //空位打完
  223. }
  224. ch = ch * user_datas[0] *157/(user_datas[1]*500); //当条剩于长度
  225. user_datas[106] = ch%0x10000;
  226. user_datas[107] = ch/0x10000;
  227. if(ch <= k)
  228. i += (k - ch);
  229. i /= 100;
  230. user_datas[63] = i/0x10000; //已累计
  231. user_datas[62] = i%0x10000;
  232. i =((unsigned long)user_datas[85] << 16) + user_datas[84];
  233. if(SYY_cTotal >= i)
  234. i = 0;
  235. else
  236. {
  237. i = k * (i - SYY_cTotal-1);
  238. i += ch;
  239. i = i/100;
  240. }
  241. user_datas[61] = i/0x10000; //已累计
  242. user_datas[60] = i%0x10000;
  243. //累计时间
  244. if(Y005) //
  245. {
  246. user_datas[89] = SYY_cTestTime;
  247. SYY_cCountTime += SYY_cTestTime; //累积时间
  248. user_datas[88] += SYY_cTestTime; //当前生产总量累积时间
  249. if(SYY_cCountTime >= 1000) //大于1秒
  250. {
  251. user_datas[96] += SYY_cCountTime/1000; //1秒
  252. SYY_cCountTime %= 1000;
  253. if(user_datas[96] >= 3600) //大于1小时
  254. {
  255. i = user_datas[96]/3600; //
  256. user_datas[96] %= 3600;
  257. i += ((unsigned long)user_datas[93] << 16) + user_datas[92];//所有总生产时间
  258. user_datas[93] = (unsigned short)(i>>16);
  259. user_datas[92] = (unsigned short)(i);
  260. }
  261. }
  262. //累计已用时间
  263. if(user_datas[88] >= 60000) //1分钟
  264. {
  265. user_datas[87]++;
  266. user_datas[86] += user_datas[87]/60; //1小时
  267. user_datas[87] = user_datas[87]%60; //1小时
  268. user_datas[88] = user_datas[88]-60000;
  269. }
  270. //计算剩于时间
  271. ch = SYY_cTestTime*(user_datas[67]+ user_datas[64]); //单条所用的时间
  272. i = ((unsigned long)user_datas[85] << 16) + user_datas[84];
  273. if(SYY_cTotal >= i)
  274. i = 0;
  275. else
  276. {
  277. i -= SYY_cTotal;
  278. k = (ch/1000) * i; //大于1秒
  279. i = (ch%1000) * i; //所得MS
  280. k += i/1000; //总秒数
  281. user_datas[94] = k/3600; //所剩小时
  282. user_datas[95] = (k%3600)/60; //所剩小时
  283. }
  284. }
  285. }
  286. //重设数据
  287. void SYY_ReSetData(unsigned short cData,unsigned short cMode)
  288. {
  289. if((user_datas[65] != user_datas[66]) || (user_datas[68] != user_datas[69]))
  290. SYY_cStart_Right_EN = 1;
  291. else
  292. SYY_cStart_Right_EN = 0;
  293. if(cData == 0)
  294. {
  295. user_datas[65] = user_datas[64];
  296. user_datas[66] = user_datas[64];
  297. }
  298. else
  299. {
  300. user_datas[65] = 0;
  301. user_datas[66] = 0;
  302. }
  303. //左边
  304. user_datas[68] = cData;
  305. SYY_cStartPYFlag_Left = cMode;
  306. //右边
  307. user_datas[69] = cData;
  308. SYY_cStartPYFlag_Right = cMode;
  309. //接口直接跳过
  310. SYY_cJieDai_Flag = 0;
  311. SYY_cJieDaiTotal = 0;
  312. SYY_cJieDaiClrTotal = 0;
  313. SYY_cClr_Flag = 0;
  314. user_datas[102] = 0;
  315. user_datas[103] = 0;
  316. user_datas[104] = 0;
  317. user_datas[105] = 0;
  318. }
  319. void SYY_Start(void)
  320. {
  321. if(M0100 == 0)//首次加油已经完成
  322. {
  323. if((M0 || X00_UP) && (SYY_bRunning == 0) && M3 && (X001 == 0) && (middle_coils[11].value == 0)
  324. && (middle_coils[10].value == 0) && (SYY_cTotal < ((unsigned long)user_datas[84] + user_datas[85]*0x10000)))
  325. {
  326. M7 = 1; //M7 工作显示
  327. M4 = 1; //M4 合链控制
  328. M5 = 1; //M5 送丝控制
  329. M6 = 1; //M6 排牙控制
  330. user_datas[40] = 3;
  331. SYY_bRunning = 1;
  332. if(X023 == 0)
  333. {
  334. SETY010();
  335. SETY011();
  336. }
  337. }
  338. M0 = 0;
  339. }
  340. else
  341. {
  342. M0 = 0; //M0 倒时显示
  343. }
  344. if(M1 || X001 || ((middle_coils[11].value != 0) && (middle_coils[10].value != 0)))
  345. {
  346. // 普通停止是打完当条再停止
  347. if(M1 || (X001))
  348. {
  349. if(M6)
  350. SYY_bStop = 1;
  351. }
  352. else //其它故障都要立即停止
  353. {
  354. if(SYY_bRunning)SETY000();
  355. SYY_Stop_Action();
  356. SYY_bStop = 0;
  357. }
  358. M0 = 0; //M0 系统复位
  359. }
  360. if(M14) //系统复位 重新 6空位,6牙
  361. {
  362. M14 = 0;
  363. if(SYY_bRunning == 0)
  364. { if((user_datas[68] || user_datas[69]))
  365. {
  366. SYY_ReSetData(user_datas[68] + 2,1);//(6,1); //6空位,6牙
  367. }
  368. else if(user_datas[67])
  369. SYY_ReSetData(user_datas[67],1);//(6,1); //6空位,6牙
  370. else
  371. SYY_ReSetData(1,0);//(6,1); //6空位,6牙
  372. }
  373. }
  374. //故障清除
  375. if(M13)
  376. {
  377. if(M0088) //叠牙时直接打空位
  378. {
  379. SYY_ReSetData(user_datas[67],0); //正常空位,正常牙数
  380. }
  381. middle_coils[10].value = 0;
  382. middle_coils[11].value = 0;
  383. user_datas[100] = 0;
  384. CLRY000();
  385. }
  386. }
  387. // 停止工作
  388. void SYY_Stop_Action(void)
  389. {
  390. M7 = 0; //M7 工作显示
  391. if((X002 == 0) && (M0100 == 0))M3 = 0;//M3 注油控制
  392. if(SYY_bRunning)M4 = 0;; //M4 合链控制
  393. M5 = 0; //M5 送丝控制
  394. M6 = 0; //M6 排牙控制
  395. user_datas[40] = 2;
  396. SYY_bRunning = 0;
  397. }
  398. //错误停机
  399. void SYY_Error_Action(void)
  400. {
  401. unsigned short i;
  402. if(X002 == 0) //紧急停止
  403. {
  404. M0091 = 1; //M91 紧急停止警告
  405. user_datas[100] = 91;
  406. }
  407. else if(X02_UP)
  408. {
  409. M0091 = 0; //M91 紧急停止警告
  410. user_datas[100] = 0;
  411. }
  412. if(dwTickCount >= cDelayTime1)
  413. {
  414. if(X005) //液位警告
  415. {
  416. if(dwTickCount >= cDelayTime12)
  417. {
  418. M0089 = 1; //M89 液位警告
  419. user_datas[100] = 89;
  420. }
  421. }
  422. else
  423. {
  424. cDelayTime12 = dwTickCount + (unsigned long)8 * 10;
  425. }
  426. if(X007) //铜线故障
  427. {
  428. if(dwTickCount >= cDelayTime11)
  429. {
  430. M0087 = 1; //M87 铜线故障警告
  431. user_datas[100] = 87;
  432. }
  433. }
  434. else
  435. {
  436. cDelayTime11 = dwTickCount + (unsigned long)30 * 10;
  437. }
  438. if(X010 && Y005) //叠牙
  439. {
  440. M0086 = 1; //M0086 叠牙警告
  441. user_datas[100] = 86;
  442. }
  443. if(X011 && Y005) //卡带故障(布带1)
  444. {
  445. if(dwTickCount >= cDelayTime13)
  446. {
  447. M0080 = 1; //M0080 卡带故障(布带1)
  448. user_datas[100] = 80;
  449. }
  450. }
  451. else
  452. {
  453. cDelayTime13 = dwTickCount + (unsigned long)8 * 10;
  454. }
  455. if(X012) //没带故障(布带2)
  456. {
  457. if(dwTickCount >= cDelayTime9)
  458. {
  459. M0081 = 1; //M81 没带故障(布带2)
  460. user_datas[100] = 81;
  461. }
  462. }
  463. else
  464. {
  465. cDelayTime9 = dwTickCount + (unsigned long)5 * 10;
  466. }
  467. if(X013) //送带故障(布带3)
  468. {
  469. if(dwTickCount >= cDelayTime10)
  470. {
  471. M0082 = 1; //M82 送带故障(布带3)
  472. user_datas[100] = 82;
  473. }
  474. }
  475. else
  476. {
  477. cDelayTime10 = dwTickCount + (unsigned long)5 * 10;
  478. }
  479. if(X014) //合链上限、下限位开关(合链1)
  480. {
  481. if(dwTickCount >= cDelayTime14)
  482. {
  483. M0083 = 1; //M83 合链上限、下限位开关(合链1)
  484. user_datas[100] = 83;
  485. }
  486. }
  487. else
  488. {
  489. cDelayTime14 = dwTickCount + (unsigned long)3 * 10;
  490. }
  491. //油压不到警告
  492. if(Y006 && (dwTickCount >= cDelayTime3))
  493. {
  494. if(X006)
  495. {
  496. M0090 = 1; //M90 油压不到警告
  497. user_datas[100] = 90;
  498. }
  499. }
  500. //数牙出错
  501. if(user_datas[67]) //有空位时(条计数时才有效)
  502. {
  503. if(user_datas[65] || user_datas[66])
  504. {
  505. if(user_datas[65] >= user_datas[66])
  506. {
  507. i = user_datas[65] - user_datas[66];
  508. }
  509. else
  510. i = user_datas[66] - user_datas[65];
  511. // 正常打牙状态
  512. if((SYY_cClr_Flag == 0) && (i > 2) && (((i < (user_datas[64]-1)) && (SYY_cStartPYFlag_Right == 0))
  513. // 复位打牙状态
  514. ||(SYY_cStartPYFlag_Right && (i < 5))))
  515. {
  516. M0088 = 1; //M0088 数牙出错
  517. user_datas[100] = 88;
  518. }
  519. }
  520. else if((user_datas[68] || user_datas[69]))
  521. {
  522. if(user_datas[68] >= user_datas[69])
  523. {
  524. i = user_datas[68] - user_datas[69];
  525. }
  526. else
  527. i = user_datas[69] - user_datas[68];
  528. if((SYY_cClr_Flag == 0) && (i > 2) && (i != user_datas[67]))
  529. {
  530. M0088 = 1; //M0088 数牙出错
  531. user_datas[100] = 88;
  532. }
  533. }
  534. }
  535. }
  536. else
  537. {
  538. cDelayTime14 = dwTickCount + (unsigned long)3 * 10;
  539. cDelayTime10 = dwTickCount + (unsigned long)5 * 10;
  540. cDelayTime9 = dwTickCount + (unsigned long)5 * 10;
  541. cDelayTime13 = dwTickCount + (unsigned long)8 * 10;
  542. cDelayTime12 = dwTickCount + (unsigned long)8 * 10;
  543. cDelayTime11 = dwTickCount + (unsigned long)30 * 10;
  544. }
  545. //两边合链出错
  546. if((SYY_cHeLian == 0) && (X15_UP) || (X16_UP) && M4)
  547. {
  548. SYY_cHeLian = 1;
  549. cDelayTime5 = dwTickCount + (unsigned long)user_datas[5] * 10;
  550. }
  551. if((M4 == 0) || (X015 && X016) || ((X015 == 0)&& (X016 == 0)))
  552. {
  553. if((M4 == 0) || ((X015 == 0)&& (X016 == 0)))
  554. {
  555. SYY_cHeLian = 0;
  556. }
  557. else
  558. {
  559. if(X015 && X016)
  560. {
  561. if(X15_UP || X16_UP)
  562. {
  563. cDelayTime4 = dwTickCount + (unsigned long)40;
  564. if(SYY_cHeLian == 1)
  565. SYY_cHeLian = 2;
  566. }
  567. if((SYY_cHeLian == 2) && (dwTickCount >= cDelayTime4))
  568. {
  569. SYY_cHeLian = 3;
  570. SETY012();
  571. cDelayTime4 = dwTickCount + (unsigned long)120;
  572. }
  573. }
  574. else if(Y012 == 0)
  575. cDelayTime4 = dwTickCount + (unsigned long)40;
  576. }
  577. if(Y012 && (dwTickCount >= cDelayTime4))
  578. {
  579. CLRY012();
  580. }
  581. }
  582. else if((SYY_cHeLian == 1) && (dwTickCount >= cDelayTime5))
  583. {
  584. if(X015 == 0)
  585. {
  586. M0084 = 1; //M84 (合链2出错)
  587. user_datas[100] = 84;
  588. }
  589. else
  590. {
  591. M0085 = 1; //M85 (合链2出错)
  592. user_datas[100] = 85;
  593. }
  594. }
  595. }
  596. void SYY_StartZYFirst(void)
  597. {
  598. SYY_cDBuff = user_datas[4];
  599. M0100 = 1; //M0100 倒时显示
  600. cDelayTime8 = dwTickCount + (unsigned long)1000;
  601. SETY006();
  602. user_datas[40] = 1;
  603. cDelayTime3 = dwTickCount + (unsigned long)15000;
  604. M3 = 1; //M3 注油控制
  605. }
  606. void SYY_ZhuYou(void)
  607. {
  608. if(Y006)
  609. {
  610. if((dwTickCount >= cDelayTime8) || (M3 == 0))
  611. {
  612. if(M0100)
  613. {
  614. cDelayTime8 = dwTickCount + (unsigned long)1000;
  615. if(user_datas[4])
  616. {
  617. user_datas[4]--;
  618. }
  619. if((user_datas[4] == 0) || (M3 == 0)) //初次注油完成
  620. {
  621. M0100 = 0; //M0100
  622. CLRY006(); //注油机关
  623. user_datas[4] = SYY_cDBuff;
  624. cDelayTime8 = dwTickCount + (unsigned long)user_datas[3] * 60 * 1000;
  625. user_datas[40] = 2; //注油完成
  626. }
  627. }
  628. else
  629. {
  630. CLRY006(); //注油机关
  631. if(M3)
  632. cDelayTime8 = dwTickCount + (unsigned long)user_datas[3] * 60 * 1000; //间隔注油时间 分钟
  633. else
  634. cDelayTime8 = dwTickCount;
  635. }
  636. M8 = 0; //M8 清通知位
  637. }
  638. }
  639. else if(M3 && ((dwTickCount >= cDelayTime8) || M8) && X002)
  640. {
  641. //大于1小时,重新先注油
  642. if(((dwTickCount - cDelayTime8) > (3600 * 1000)) && (dwTickCount >= cDelayTime8))
  643. {
  644. SYY_StartZYFirst();
  645. }
  646. else
  647. {
  648. SETY006();
  649. cDelayTime8 = dwTickCount + (unsigned long)user_datas[2] * 1000; //注油时间 秒
  650. cDelayTime3 = dwTickCount + (unsigned long)5000; //延时检测油压
  651. }
  652. M8 = 0; //M8 清通知位
  653. }
  654. }
  655. void SYY_SongLiao(void)
  656. {
  657. static unsigned long cSSYASongLiao_In_Time_L = 0,cSSYASongLiao_In_Time_R = 0;
  658. //送丝启动
  659. if(M5)
  660. {
  661. //左送料(送丝)
  662. if(X020)
  663. {
  664. if(dwTickCount >= cSSYASongLiao_In_Time_L)
  665. SETY013();
  666. }
  667. else if(X017)
  668. {
  669. if(dwTickCount >= cSSYASongLiao_In_Time_L)
  670. CLRY013();
  671. }
  672. else
  673. {
  674. cSSYASongLiao_In_Time_L = dwTickCount + (unsigned long)100; //防干扰时间
  675. }
  676. //右送料(送丝)
  677. if(X022)
  678. {
  679. if(dwTickCount >= cSSYASongLiao_In_Time_R )
  680. SETY014();
  681. }
  682. else if(X021)
  683. {
  684. if(dwTickCount >= cSSYASongLiao_In_Time_R )
  685. CLRY014();
  686. }
  687. else
  688. {
  689. cSSYASongLiao_In_Time_R = dwTickCount + (unsigned long)100; //防干扰时间
  690. }
  691. }
  692. else
  693. {
  694. CLRY013();
  695. CLRY014();
  696. cSSYASongLiao_In_Time_L = dwTickCount + (unsigned long)100; //防干扰时间
  697. cSSYASongLiao_In_Time_R = dwTickCount + (unsigned long)100; //防干扰时间
  698. }
  699. }
  700. //左边排牙动作
  701. //D64 牙数设定
  702. //D65 左牙记录
  703. //D66 右空位记录
  704. //D67 空位设定
  705. //D68 左空位记录
  706. //D69 右空位记录
  707. //当在按下复位时就先打6空位,再打6牙
  708. void SYY_Lelf_Action(void)
  709. {
  710. unsigned long i;
  711. if(X03_UP)
  712. {
  713. SYY_cStart_Right_EN = 0;
  714. if(SYY_cJieDai_Flag == 1)
  715. {
  716. if(SYY_cJieDaiTotal)
  717. SYY_cJieDaiClrTotal++;
  718. else
  719. SYY_cJieDaiClrTotal = 0;
  720. }
  721. if(SYY_cJieDaiTotal && SYY_cJieDai_Flag)
  722. {
  723. SYY_cJieDaiTotal--;
  724. if(SYY_cJieDaiTotal == 0) //直接按空位方式走
  725. {
  726. SYY_cStartPYFlag_Left = 3;
  727. SYY_cStartPYFlag_Right = 3;
  728. user_datas[68] = SYY_cJieDaiClrTotal + user_datas[67];
  729. if(user_datas[67] == 0)
  730. {
  731. user_datas[68] += 10;
  732. }
  733. user_datas[69] = user_datas[68];
  734. if(SYY_cJieDai_Flag == 2)
  735. SYY_cJieDai_Flag = 0;
  736. CLRY002();
  737. SETY001();
  738. cDelayTime6 = dwTickCount + (unsigned long)SYY_DianCiTieOutTIME;
  739. //变为空位,不用铜丝
  740. CLRY004();
  741. SETY003();
  742. cDelayTime7 = dwTickCount + (unsigned long)SYY_DianCiTieOutTIME;
  743. }
  744. }
  745. if(user_datas[68]) //空位状态
  746. {
  747. if(SYY_cStartPYFlag_Left == 1)
  748. {
  749. SYY_cStartPYFlag_Left = 2;
  750. //变为空位,不用铜丝
  751. CLRY002();
  752. SETY001();
  753. cDelayTime6 = dwTickCount + (unsigned long)SYY_DianCiTieOutTIME;
  754. }
  755. user_datas[68]--;
  756. if(user_datas[68] == 0)
  757. {
  758. switch(SYY_cStartPYFlag_Left)
  759. {
  760. case 1:
  761. case 2:
  762. user_datas[65] = 6 ;//左边牙数
  763. break;
  764. default:
  765. user_datas[65] = user_datas[64] ;//左边牙数
  766. break;
  767. }
  768. //只有大于一条拉链时才打牙状态
  769. if((SYY_cJieDaiTotal >= (user_datas[65]+user_datas[67])) || (SYY_cJieDai_Flag == 0))
  770. {
  771. //变为打牙,
  772. CLRY001();
  773. SETY002();
  774. cDelayTime6 = dwTickCount + (unsigned long)SYY_DianCiTieOutTIME;
  775. SYY_cClr_Flag = 0;
  776. }
  777. else
  778. {
  779. if(SYY_cJieDai_Flag != 0)
  780. user_datas[68] = user_datas[6] + 6;//SYY_cJieDaiTotal + 5 + SYY_cJieDaiClrTotal;
  781. user_datas[65] = 0;
  782. SYY_cClr_Flag = 1;
  783. }
  784. }
  785. }
  786. else if(user_datas[65]) //打齿状态
  787. {
  788. user_datas[65]--;
  789. //如果不是码装方式(空位不为0)
  790. if(((SYY_cJieDaiTotal + 5) < (user_datas[65] + user_datas[67]/2)) && (user_datas[67] != 0) && (SYY_cJieDai_Flag))
  791. {
  792. CLRY002();
  793. SETY001();
  794. cDelayTime6 = dwTickCount + (unsigned long)SYY_DianCiTieOutTIME;
  795. user_datas[68] = SYY_cJieDaiTotal + 5;
  796. SYY_cClr_Flag = 1;
  797. }
  798. else if(user_datas[65] == 0)
  799. {
  800. //变为空位,
  801. if(user_datas[67] != 0)
  802. {
  803. CLRY002();
  804. SETY001();
  805. cDelayTime6 = dwTickCount + (unsigned long)SYY_DianCiTieOutTIME;
  806. }
  807. else //空位为0时
  808. {
  809. user_datas[65] = user_datas[64] ;//左边牙数
  810. }
  811. //产量计数
  812. //当两边的齿都打完时,产量加1
  813. if(SYY_cTatal_OK)
  814. {
  815. SYY_cTatal_OK = 0;
  816. if(SYY_cStartPYFlag_Left == 0)
  817. {
  818. SYY_cTotal++;
  819. SETY016();
  820. cDelayTime17 = dwTickCount + (unsigned long)100;
  821. }
  822. //按停止 或产量到
  823. if(SYY_bStop || (SYY_cTotal >= ((unsigned long)user_datas[84] + user_datas[85]*0x10000)))
  824. {
  825. SYY_Stop_Action();
  826. if(SYY_bStop == 0)
  827. user_datas[40] = 4;
  828. SYY_bStop = 0;
  829. }
  830. }
  831. else
  832. SYY_cTatal_OK = 1;
  833. SYY_cStartPYFlag_Left = 0;
  834. }
  835. }
  836. M15 = 1; //M15 清通知位
  837. //如叠牙或数牙导常的情况下,不能送牙
  838. if(M0086 || M0088 || M0080)
  839. {
  840. CLRY002();
  841. SETY001();
  842. cDelayTime6 = dwTickCount + (unsigned long)SYY_DianCiTieOutTIME;
  843. }
  844. //所有累计总长度
  845. i = SYY_cTotalTength + ((unsigned long)user_datas[63] << 16) + user_datas[62]; //累计
  846. user_datas[98] = i >> 16;
  847. user_datas[97] = (unsigned short)i; //清零时保存
  848. SYY_cTestTime = dwTickCount - cDelayTime2; //计算时间 (
  849. cDelayTime2 = dwTickCount;
  850. }
  851. else if(M15) //下一程序周期计算长度的时间
  852. {
  853. M15 = 0;
  854. SYY_cTotal_Time();
  855. }
  856. }
  857. void SYY_Right_Action(void)
  858. {
  859. if(X04_UP && (SYY_cStart_Right_EN == 0))
  860. {
  861. if(user_datas[69]) //空位状态
  862. {
  863. if(SYY_cStartPYFlag_Right == 1)
  864. {
  865. SYY_cStartPYFlag_Right = 2;
  866. //变为空位,不用铜丝
  867. CLRY004();
  868. SETY003();
  869. cDelayTime7 = dwTickCount + (unsigned long)SYY_DianCiTieOutTIME;
  870. }
  871. user_datas[69]--;
  872. if(user_datas[69] == 0)
  873. {
  874. switch(SYY_cStartPYFlag_Right)
  875. {
  876. case 1:
  877. case 2:
  878. user_datas[66] = 6 ;//左边牙数
  879. break;
  880. default:
  881. user_datas[66] = user_datas[64] ;//左边牙数
  882. break;
  883. }
  884. if(SYY_cClr_Flag) //还是变空位
  885. {
  886. user_datas[69] = user_datas[68];
  887. user_datas[66] = 0;
  888. SYY_cClr_Flag = 0;
  889. }
  890. else
  891. {
  892. //变为打牙,
  893. CLRY003();
  894. SETY004();
  895. cDelayTime7 = dwTickCount + (unsigned long)SYY_DianCiTieOutTIME;
  896. }
  897. }
  898. }
  899. else if(user_datas[66]) //打齿状态
  900. {
  901. user_datas[66]--;
  902. if(SYY_cClr_Flag)
  903. {
  904. user_datas[69] = user_datas[68];
  905. CLRY004();
  906. SETY003();
  907. cDelayTime7 = dwTickCount + (unsigned long)SYY_DianCiTieOutTIME;
  908. }
  909. else if(user_datas[66] == 0)
  910. {
  911. //变为空位,
  912. if(user_datas[67] != 0)
  913. {
  914. CLRY004();
  915. SETY003();
  916. cDelayTime7 = dwTickCount + (unsigned long)SYY_DianCiTieOutTIME;
  917. }
  918. else //空位为0时
  919. {
  920. user_datas[66] = user_datas[64] ;//左边牙数
  921. }
  922. //产量计数
  923. //当两边的齿都打完时,产量加1
  924. if(SYY_cTatal_OK)
  925. {
  926. SYY_cTatal_OK = 0;
  927. if(SYY_cStartPYFlag_Right == 0)
  928. {
  929. SYY_cTotal++;
  930. SETY016();
  931. cDelayTime17 = dwTickCount + (unsigned long)100;
  932. }
  933. SYY_cWriflash = 1;
  934. //按停止 或产量到
  935. if(SYY_bStop || (SYY_cTotal >= ((unsigned long)user_datas[84] + user_datas[85]*0x10000)))
  936. {
  937. SYY_Stop_Action();
  938. if(SYY_bStop == 0)
  939. {
  940. user_datas[40] = 4;
  941. }
  942. SYY_bStop = 0;
  943. }
  944. }
  945. else
  946. SYY_cTatal_OK = 1;
  947. SYY_cStartPYFlag_Right = 0;
  948. }
  949. }
  950. //如叠牙的情况下,不能送牙
  951. if(M0086 || M0088 || M0080)
  952. {
  953. CLRY004();
  954. SETY003();
  955. cDelayTime7 = dwTickCount + (unsigned long)SYY_DianCiTieOutTIME;
  956. }
  957. }
  958. }
  959. #endif