YXYYaJi.c 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601
  1. #include "global.h"
  2. #if XI_DONG_MACHINE
  3. void YYa_AlarmProtect(void);
  4. void YYa_ManualAction(void);
  5. void YYa_AutoAction(void);
  6. void YYa_StepCheckStart(void);
  7. void YYa_ExtiActionX31(void);
  8. void YYa_SongLiao(void);
  9. void YY_JieTouControl(void);
  10. void YY_ZhuYou(void);
  11. void YY_Stop_Action(void);
  12. void YY_StartZYFirst(void);
  13. float YY_CalToothLength(unsigned short roll_diameter,unsigned short tooth_num);
  14. //输入齿数计算长度返回的是单位厘米
  15. unsigned long YY_ToothNumCalLengthCM(float single_length,unsigned short tooth_num,unsigned long zipper_num);
  16. //输入齿数计算长度返回的是单位英寸
  17. unsigned long YY_ToothNumCalLengthInch(float single_length,unsigned short tooth_num,unsigned long zipper_num);
  18. //输入长度厘米算齿数
  19. unsigned long YY_ToothLengthCMCalNum(float single_length,unsigned short tooth_length,unsigned long zipper_num);
  20. //输入长度厘米算英寸
  21. unsigned long YY_ToothLengthCMCalInch(float single_length,unsigned short tooth_length,unsigned long zipper_num);
  22. //输入厘米长度计算总长度单位米
  23. unsigned long YY_LengthCalLengthM(unsigned short set_length,unsigned short kongwei_length,unsigned long zipper_num);
  24. //输入英寸长度计算总长度
  25. unsigned long YY_InchLengthCalLength(unsigned short set_length,unsigned short kongwei_length,unsigned long zipper_num);
  26. //输入齿数计算长度返回的是单位米
  27. unsigned long YY_ToothNumCalLength(float single_length,unsigned short tooth_num,unsigned long zipper_num);
  28. //输入齿数计算长度返回的是单位米带浮点型
  29. float YY_ToothNumCalLengthFloat(float single_length,unsigned short tooth_num,unsigned long zipper_num);
  30. //输入长度英寸算齿数
  31. unsigned long YY_ToothLengthInchCalNum(float single_length,unsigned short tooth_length,unsigned long zipper_num);
  32. //输入长度英寸算厘米
  33. unsigned long YY_ToothLengthInchCalCM(float single_length,unsigned short tooth_length,unsigned long zipper_num);
  34. void YY_SetLeftPyData(unsigned short cLeftData,unsigned short cLeftKongWei);
  35. void YY_SetRightPyData(unsigned short cRightData,unsigned short cRightKongWei);
  36. void SetLeftSpaceDisplay(unsigned char mode,unsigned short source_data);
  37. void SetRightSpaceDisplay(unsigned char mode,unsigned short source_data);
  38. void YY_SetLeftDCTSpace(void);
  39. void YY_SetRightDCTSpace(void);
  40. void YY_SetLeftDCTTooth(void);
  41. void YY_SetRightDCTTooth(void);
  42. unsigned long YY_GetLeftToothNum(void);
  43. unsigned long YY_GetRightToothNum(void);
  44. unsigned long YY_GetLeftToothNumDisplay(void);
  45. unsigned long YY_GetRightToothNumDisplay(void);
  46. unsigned long YY_GetLeftSpace(void);
  47. unsigned long YY_GetRightSpace(void);
  48. unsigned long YY_GetLeftSpaceDisplay(void);
  49. unsigned long YY_GetRightSpaceDisplay(void);
  50. void YY_SetLeftDisplay(unsigned short source_data);
  51. void YY_SetRightDisplay(unsigned short source_data);
  52. void YY_SetLeftSpaceDisplay(unsigned short source_data);
  53. void YY_SetRightSpaceDisplay(unsigned short source_data);
  54. void YY_AddTotal(void);
  55. unsigned long YY_GetTotal(void);
  56. unsigned long YY_GetSetTotal(void);
  57. void YY_LeftToothDisplayAdd(void);
  58. void YY_RightToothDisplayAdd(void);
  59. void YY_LeftSpaceDisplayAdd(void);
  60. void YY_RightSpaceDisplayAdd(void);
  61. void YY_LeftOverSet(void);
  62. void YY_RightOverSet(void);
  63. float YY_SingleToothLength;
  64. unsigned long YY_cTotal,YY_ProOnceTime,YY_cJieDaiClrTotal,YY_cJieDaiState,YY_cJieDaiTotal;
  65. unsigned char YY_RightCountEnable,YY_cOverTotalLeftFlg = 0,YY_cOverTotalRightFlg = 0,YY_LeftOk,YY_RightOk,YY_ChangeNextGroupFlg,YY_cTatal_OK,YY_CalUseLifeFlg,
  66. YY_SaveParamFlg,YY_UseLifeNowGroup,YY_LastGroup,YY_cHeLian,YY_bOldMode,YY_OldGroup;
  67. unsigned short YY_NowLeftPyNum,YY_NowRightPyNum,YY_NowLeftPyKongWei,YY_NowRightPyKongWei,YY_ZYBuff,YY_cStartWorkTime;
  68. unsigned short YY_cStartPYFlag_Left,YY_cStartPYFlag_Right;
  69. YY_SingleParam_str *YY_SingleParam;
  70. YY_GroupParam_str *YY_GroupParam;
  71. YY_SystemParam_str *YY_SystemParam;
  72. YY_ComponentParam_str *YY_ComponentParam;
  73. void YYa_SetAlarmCode(unsigned short alarm_code)
  74. {
  75. YY_SystemParam->AlarmCode |= alarm_code;
  76. YY_bAlarmStop = 1;
  77. }
  78. void YYa_SetLifeAlarmCode(unsigned short alarm_code)
  79. {
  80. YY_ComponentParam->LifeAlarm |= 0x0001 << alarm_code;
  81. }
  82. void YYa_InitAction(void)
  83. {
  84. static unsigned long start_delay;
  85. YY_SingleParam = (YY_SingleParam_str *)&user_datas[YY_SINGLE_ADDR];
  86. YY_GroupParam = (YY_GroupParam_str *)&user_datas[YY_GROUP_ADDR];
  87. YY_SystemParam = (YY_SystemParam_str *)&user_datas[YY_SYSTEM_ADDR];
  88. YY_ComponentParam = (YY_ComponentParam_str *)&user_datas[YY_LIFE_ADDR];
  89. if(YY_SystemParam->NowGroup > 4)YY_SystemParam->NowGroup = 0;
  90. YY_SingleToothLength = YY_CalToothLength(YY_SystemParam->ToothLength,YY_SystemParam->ToothNum);
  91. YY_bMode = YY_SINGLE_MODE;
  92. YY_bDCTEnable = 1;
  93. YY_cTotal = YY_GetTotal();
  94. YY_StartZYFirst();
  95. YY_bCalculateTotal = 1; //bCalculate
  96. YY_SystemParam->AlarmCode = 0;
  97. start_delay = dwTickCount + 1000;
  98. while(dwTickCount <= start_delay)
  99. {
  100. io_app_read_input();
  101. }
  102. }
  103. void YYa_Action(void)
  104. {
  105. YYa_ManualAction();
  106. YYa_AutoAction();
  107. YY_ZhuYou();
  108. YYa_SongLiao();
  109. YYa_StepCheckStart(); // 调用脚踏开关检测程序
  110. YYa_AlarmProtect();
  111. }
  112. void YY_ClearJTData(void)
  113. {
  114. YY_cJieDaiState = 0;
  115. YY_cJieDaiTotal = 0;
  116. YY_cJieDaiClrTotal = 0;
  117. }
  118. //重设数据
  119. void YY_ReSetData(void)
  120. {
  121. unsigned char i;
  122. switch(YY_bMode)
  123. {
  124. case YY_SINGLE_MODE:
  125. {
  126. if((YY_SingleParam->DisplyLeftToothNum != YY_SingleParam->DisplyRightToothNum) || (YY_SingleParam->DisplyLeftToothNumSpace != YY_SingleParam->DisplyRightToothNumSpace))
  127. YY_RightCountEnable = 1;
  128. else
  129. YY_RightCountEnable = 0;
  130. YY_SingleParam->DisplyLeftToothNum = 0;
  131. YY_SingleParam->DisplyLeftToothLengthCM = 0;
  132. YY_SingleParam->DisplyLeftToothLengthINCH = 0;
  133. YY_SingleParam->DisplyLeftToothNumSpace = 0;
  134. YY_SingleParam->DisplyLeftToothLengthCMSpace = 0;
  135. YY_SingleParam->DisplyLeftToothLengthINCHSpace = 0;
  136. YY_SingleParam->DisplyRightToothNum = 0;
  137. YY_SingleParam->DisplyRightToothLengthCM = 0;
  138. YY_SingleParam->DisplyRightToothLengthINCH = 0;
  139. YY_SingleParam->DisplyRightToothNumSpace = 0;
  140. YY_SingleParam->DisplyRightToothLengthCMSpace = 0;
  141. YY_SingleParam->DisplyRightToothLengthINCHSpace = 0;
  142. YY_ClearJTData();
  143. }break;
  144. case YY_GROUP_MODE:
  145. {
  146. if((YY_GroupParam->DisplyLeftToothNum[YY_SystemParam->NowGroup] != YY_GroupParam->DisplyRightToothNum[YY_SystemParam->NowGroup]) || (YY_GroupParam->DisplyLeftToothNumSpace[YY_SystemParam->NowGroup] != YY_GroupParam->DisplyRightToothNumSpace[YY_SystemParam->NowGroup]))
  147. {
  148. YY_RightCountEnable = 1;
  149. }
  150. else
  151. {
  152. YY_RightCountEnable = 0;
  153. }
  154. for(i = 0;i < 5;i++)
  155. {
  156. YY_GroupParam->DisplyLeftToothNum[i] = 0;
  157. YY_GroupParam->DisplyLeftToothLengthCM[i] = 0;
  158. YY_GroupParam->DisplyLeftToothLengthINCH[i] = 0;
  159. YY_GroupParam->DisplyLeftToothNumSpace[i]= 0;
  160. YY_GroupParam->DisplyLeftToothLengthCMSpace[i]= 0;
  161. YY_GroupParam->DisplyLeftToothLengthINCHSpace[i]= 0;
  162. YY_GroupParam->DisplyRightToothNum[i]= 0;
  163. YY_GroupParam->DisplyRightToothLengthCM[i]= 0;
  164. YY_GroupParam->DisplyRightToothLengthINCH[i]= 0;
  165. YY_GroupParam->DisplyRightToothLengthCM[i]= 0;
  166. YY_GroupParam->DisplyRightToothLengthCMSpace[i]= 0;
  167. YY_GroupParam->DisplyRightToothLengthINCHSpace[i]= 0;
  168. YY_ClearJTData();
  169. }
  170. }break;
  171. }
  172. }
  173. unsigned long YY_CalOverLength(void)
  174. {
  175. unsigned char i;
  176. switch(YY_bMode)
  177. {
  178. case YY_SINGLE_MODE:
  179. {
  180. YY_SingleParam->OverLength = (YY_SingleParam->LeftToothLengthCM + YY_SingleParam->LeftToothLengthCMSpace) * YY_SingleParam->OverTotal / 1000;
  181. }break;
  182. case YY_GROUP_MODE:
  183. {
  184. YY_GroupParam->AllOverLength = 0;
  185. for(i=0;i<5;i++)
  186. {
  187. YY_GroupParam->AllOverLength += (YY_GroupParam->LeftToothLengthCM[i] + YY_GroupParam->LeftToothLengthCMSpace[i]) * YY_GroupParam->OverSetTotal[i] / 1000;
  188. }
  189. }break;
  190. default:return 0;
  191. }
  192. return 0;
  193. }
  194. void YY_CalProcessTime(unsigned long add_time)
  195. {
  196. unsigned long time_buff,hour_buff,minute_buff;
  197. unsigned char i;
  198. switch(YY_bMode)
  199. {
  200. case YY_SINGLE_MODE:
  201. {
  202. if(YY_MAIN_MOTOR)
  203. {
  204. time_buff = YY_SingleParam->OverTotal * (YY_SingleParam->LeftToothNum + YY_SingleParam->LeftToothNumSpace) * add_time;
  205. time_buff = time_buff / 1000;
  206. hour_buff = time_buff / 3600;
  207. YY_SingleParam->SetTimeHour = hour_buff;
  208. time_buff -= hour_buff * 3600;
  209. minute_buff = time_buff / 60;
  210. YY_SingleParam->SetTimeMinute = minute_buff;
  211. }
  212. }break;
  213. case YY_GROUP_MODE:
  214. {
  215. if(YY_MAIN_MOTOR)
  216. {
  217. time_buff = 0;
  218. for(i=0;i<5;i++)
  219. {
  220. time_buff += YY_GroupParam->OverSetTotal[i] * (YY_GroupParam->LeftToothNum[i] + YY_GroupParam->LeftToothNumSpace[i]) * add_time;
  221. }
  222. time_buff = time_buff / 1000;
  223. hour_buff = time_buff / 3600;
  224. YY_GroupParam->SetTimeHour = hour_buff;
  225. time_buff -= hour_buff * 3600;
  226. minute_buff = time_buff / 60;
  227. YY_GroupParam->SetTimeMinute = minute_buff;
  228. }
  229. }break;
  230. }
  231. }
  232. void YY_CalRemainTime(unsigned long one_time)
  233. {
  234. unsigned long time_buff,hour_buff,minute_buff;
  235. unsigned char i;
  236. switch(YY_bMode)
  237. {
  238. case YY_SINGLE_MODE:
  239. {
  240. time_buff = one_time * (YY_SingleParam->SetTotal - YY_SingleParam->OverTotal) * (YY_SingleParam->LeftToothNum + YY_SingleParam->LeftToothNumSpace);
  241. time_buff = time_buff / 1000;
  242. hour_buff = time_buff / 3600;
  243. YY_SingleParam->RemainTimeHour = hour_buff;
  244. time_buff -= hour_buff * 3600;
  245. minute_buff = time_buff / 60;
  246. YY_SingleParam->RemainTimeMinute = minute_buff;
  247. }break;
  248. case YY_GROUP_MODE:
  249. {
  250. time_buff = 0;
  251. for(i=0;i<5;i++)
  252. {
  253. time_buff += (YY_GroupParam->SetTotal[i] - YY_GroupParam->OverSetTotal[i]) * (YY_GroupParam->LeftToothNum[i] + YY_GroupParam->LeftToothNumSpace[i]) * one_time;
  254. }
  255. time_buff = time_buff / 1000;
  256. hour_buff = time_buff / 3600;
  257. YY_GroupParam->RemainTimeHour = hour_buff;
  258. time_buff -= hour_buff * 3600;
  259. minute_buff = time_buff / 60;
  260. YY_GroupParam->RemainTimeMinute = minute_buff;
  261. }break;
  262. }
  263. }
  264. void YY_cTotal_Time(void)
  265. {
  266. YY_CalOverLength();
  267. YY_CalProcessTime(YY_ProOnceTime);
  268. YY_CalRemainTime(YY_ProOnceTime);
  269. }
  270. //参数运算控制
  271. void YY_CalculataParam(void)
  272. {
  273. unsigned char i;
  274. unsigned long total_buff;
  275. if(YY_bMode != YY_bOldMode)
  276. {
  277. YY_cTotal = YY_GetTotal();
  278. }
  279. YY_bOldMode = YY_bMode;
  280. if(YY_SystemParam->NowGroup != YY_OldGroup)
  281. {
  282. YY_SystemParam->NextGroupBuff = YY_SystemParam->NowGroup + 1;
  283. }
  284. YY_OldGroup = YY_SystemParam->NowGroup;
  285. //输入右边的齿数
  286. if(YY_bCalInputRightToothNum)
  287. {
  288. YY_bCalInputRightToothNum = 0;
  289. YY_SingleParam->RightToothNumSpace = (YY_SingleParam->LeftToothNumSpace + YY_SingleParam->LeftToothNum) - YY_SingleParam->RightToothNum;
  290. YY_bCalInputToothNum = 1;
  291. }
  292. if(YY_bCalInputRightKongWei)
  293. {
  294. YY_bCalInputRightKongWei = 0;
  295. YY_SingleParam->RightToothNum = (YY_SingleParam->LeftToothNumSpace + YY_SingleParam->LeftToothNum) - YY_SingleParam->RightToothNumSpace;
  296. YY_bCalInputToothNum = 1;
  297. }
  298. //输入右边的长度
  299. if(YY_bCalInputRightToothNumLength)
  300. {
  301. YY_bCalInputRightToothNumLength = 0;
  302. YY_SingleParam->RightToothLengthCMSpace = (YY_SingleParam->LeftToothLengthCMSpace + YY_SingleParam->LeftToothLengthCM) - YY_SingleParam->RightToothLengthCM;
  303. YY_bCalInputLength = 1;
  304. }
  305. if(YY_bCalInputRightKongWeiLength)
  306. {
  307. YY_bCalInputRightKongWeiLength = 0;
  308. YY_SingleParam->RightToothLengthCM = (YY_SingleParam->LeftToothLengthCMSpace + YY_SingleParam->LeftToothLengthCM) - YY_SingleParam->RightToothLengthCMSpace;
  309. YY_bCalInputLength = 1;
  310. }
  311. //输入右边的英寸长度
  312. if(YY_bCalInputRightToothNumLengthInch)
  313. {
  314. YY_bCalInputRightToothNumLengthInch = 0;
  315. YY_SingleParam->RightToothLengthINCHSpace = (YY_SingleParam->LeftToothLengthINCHSpace + YY_SingleParam->LeftToothLengthINCH) - YY_SingleParam->RightToothLengthINCH;
  316. YY_bCalInputLengthInch = 1;
  317. }
  318. if(YY_bCalInputRightKongWeiLengthInch)
  319. {
  320. YY_bCalInputRightKongWeiLengthInch = 0;
  321. YY_SingleParam->RightToothLengthINCH = (YY_SingleParam->LeftToothLengthINCHSpace + YY_SingleParam->LeftToothLengthINCH) - YY_SingleParam->RightToothLengthINCHSpace;
  322. YY_bCalInputLengthInch = 1;
  323. }
  324. if(YY_bCalInputToothNum)
  325. {
  326. YY_bCalInputToothNum = 0;
  327. YY_SingleParam->LeftToothLengthCM = YY_ToothNumCalLengthCM(YY_SingleToothLength,YY_SingleParam->LeftToothNum,1);
  328. YY_SingleParam->LeftToothLengthINCH = YY_ToothNumCalLengthInch(YY_SingleToothLength,YY_SingleParam->LeftToothNum,1);
  329. YY_SingleParam->RightToothLengthCM = YY_ToothNumCalLengthCM(YY_SingleToothLength,YY_SingleParam->RightToothNum,1);
  330. YY_SingleParam->RightToothLengthINCH = YY_ToothNumCalLengthInch(YY_SingleToothLength,YY_SingleParam->RightToothNum,1);
  331. YY_SingleParam->LeftToothLengthCMSpace = YY_ToothNumCalLengthCM(YY_SingleToothLength,YY_SingleParam->LeftToothNumSpace,1);
  332. YY_SingleParam->LeftToothLengthINCHSpace = YY_ToothNumCalLengthInch(YY_SingleToothLength,YY_SingleParam->LeftToothNumSpace,1);
  333. YY_SingleParam->RightToothLengthCMSpace = YY_ToothNumCalLengthCM(YY_SingleToothLength,YY_SingleParam->RightToothNumSpace,1);
  334. YY_SingleParam->RightToothLengthINCHSpace = YY_ToothNumCalLengthInch(YY_SingleToothLength,YY_SingleParam->RightToothNumSpace,1);
  335. YY_GroupParam->AllSetLength = 0;
  336. for(i = 0;i < 5;i++)
  337. {
  338. YY_GroupParam->AllSetLength += YY_ToothNumCalLength(YY_SingleToothLength,(YY_GroupParam->LeftToothNum[i] + YY_GroupParam->LeftToothNumSpace[i]),YY_GroupParam->SetTotal[i]);
  339. }
  340. YY_SingleParam->SetLength = YY_ToothNumCalLength(YY_SingleToothLength,(YY_SingleParam->LeftToothNum + YY_SingleParam->LeftToothNumSpace),YY_SingleParam->SetTotal);
  341. YY_GroupParam->AllSetTotal = 0;
  342. for(i = 0;i < 5;i++)
  343. {
  344. YY_GroupParam->AllSetTotal += YY_GroupParam->SetTotal[i];
  345. }
  346. for(i = 0;i < 5;i++)
  347. {
  348. YY_GroupParam->LeftToothLengthCM[i] = YY_ToothNumCalLengthCM(YY_SingleToothLength,YY_GroupParam->LeftToothNum[i],1);
  349. }
  350. for(i = 0;i < 5;i++)
  351. {
  352. YY_GroupParam->LeftToothLengthCMSpace[i] = YY_ToothNumCalLengthCM(YY_SingleToothLength,YY_GroupParam->LeftToothNumSpace[i],1);
  353. }
  354. for(i = 0;i < 5;i++)
  355. {
  356. YY_GroupParam->LeftToothLengthINCH[i] = YY_ToothNumCalLengthInch(YY_SingleToothLength,YY_GroupParam->LeftToothNum[i],1);
  357. }
  358. for(i = 0;i < 5;i++)
  359. {
  360. YY_GroupParam->LeftToothLengthINCHSpace[i] = YY_ToothNumCalLengthInch(YY_SingleToothLength,YY_GroupParam->LeftToothNumSpace[i],1);
  361. }
  362. }
  363. if(YY_bCalInputLength)
  364. {
  365. YY_bCalInputLength = 0;
  366. YY_SingleParam->LeftToothLengthINCH = YY_ToothLengthCMCalInch(YY_SingleToothLength,YY_SingleParam->LeftToothLengthCM,1);
  367. YY_SingleParam->LeftToothNum = YY_ToothLengthCMCalNum(YY_SingleToothLength,YY_SingleParam->LeftToothLengthCM,1);
  368. YY_SingleParam->RightToothLengthINCH = YY_ToothLengthCMCalInch(YY_SingleToothLength,YY_SingleParam->RightToothLengthCM,1);
  369. YY_SingleParam->RightToothNum = YY_ToothLengthCMCalNum(YY_SingleToothLength,YY_SingleParam->RightToothLengthCM,1);
  370. YY_SingleParam->LeftToothLengthINCHSpace = YY_ToothLengthCMCalInch(YY_SingleToothLength,YY_SingleParam->LeftToothLengthCMSpace,1);
  371. YY_SingleParam->LeftToothNumSpace = YY_ToothLengthCMCalNum(YY_SingleToothLength,YY_SingleParam->LeftToothLengthCMSpace,1);
  372. YY_SingleParam->RightToothLengthINCHSpace = YY_ToothLengthCMCalInch(YY_SingleToothLength,YY_SingleParam->RightToothLengthCMSpace,1);
  373. YY_SingleParam->RightToothNumSpace = YY_ToothLengthCMCalNum(YY_SingleToothLength,YY_SingleParam->RightToothLengthCMSpace,1);
  374. YY_GroupParam->AllSetLength = 0;
  375. for(i = 0;i < 5;i++)
  376. {
  377. YY_GroupParam->AllSetLength += YY_LengthCalLengthM(YY_GroupParam->LeftToothLengthCM[i],YY_GroupParam->LeftToothLengthCMSpace[i],YY_GroupParam->SetTotal[i]);
  378. }
  379. YY_SingleParam->SetLength = YY_ToothNumCalLength(YY_SingleToothLength,(YY_SingleParam->LeftToothNum + YY_SingleParam->LeftToothNumSpace),YY_SingleParam->SetTotal);
  380. YY_GroupParam->AllSetTotal = 0;
  381. for(i = 0;i < 5;i++)
  382. {
  383. YY_GroupParam->AllSetTotal += YY_GroupParam->SetTotal[i];
  384. }
  385. for(i = 0;i < 5;i++)
  386. {
  387. YY_GroupParam->LeftToothNum[i] = YY_ToothLengthCMCalNum(YY_SingleToothLength,YY_GroupParam->LeftToothLengthCM[i],1);
  388. }
  389. for(i = 0;i < 5;i++)
  390. {
  391. YY_GroupParam->LeftToothNumSpace[i] = YY_ToothLengthCMCalNum(YY_SingleToothLength,YY_GroupParam->LeftToothLengthCMSpace[i],1);
  392. }
  393. for(i = 0;i < 5;i++)
  394. {
  395. YY_GroupParam->LeftToothLengthINCH[i] = YY_ToothLengthCMCalInch(YY_SingleToothLength,YY_GroupParam->LeftToothLengthCMSpace[i],1);
  396. }
  397. for(i = 0;i < 5;i++)
  398. {
  399. YY_GroupParam->LeftToothLengthINCHSpace[i] = YY_ToothLengthCMCalInch(YY_SingleToothLength,YY_GroupParam->LeftToothLengthCMSpace[i],1);
  400. }
  401. YY_bCalInputToothNum = 1;
  402. }
  403. if(YY_bCalInputLengthInch)
  404. {
  405. YY_bCalInputLengthInch = 0;
  406. YY_SingleParam->LeftToothLengthCM = YY_ToothLengthInchCalCM(YY_SingleToothLength,YY_SingleParam->LeftToothLengthINCH,1);
  407. YY_SingleParam->LeftToothNum = YY_ToothLengthInchCalNum(YY_SingleToothLength,YY_SingleParam->LeftToothLengthINCH,1);
  408. YY_SingleParam->RightToothLengthCM = YY_ToothLengthInchCalCM(YY_SingleToothLength,YY_SingleParam->RightToothLengthINCH,1);
  409. YY_SingleParam->RightToothNum = YY_ToothLengthInchCalNum(YY_SingleToothLength,YY_SingleParam->RightToothLengthINCH,1);
  410. YY_SingleParam->LeftToothLengthCMSpace = YY_ToothLengthInchCalCM(YY_SingleToothLength,YY_SingleParam->LeftToothLengthINCHSpace,1);
  411. YY_SingleParam->LeftToothNumSpace = YY_ToothLengthInchCalNum(YY_SingleToothLength,YY_SingleParam->LeftToothLengthINCHSpace,1);
  412. YY_SingleParam->RightToothLengthCMSpace = YY_ToothLengthInchCalCM(YY_SingleToothLength,YY_SingleParam->RightToothLengthINCHSpace,1);
  413. YY_SingleParam->RightToothNumSpace = YY_ToothLengthInchCalNum(YY_SingleToothLength,YY_SingleParam->RightToothLengthINCHSpace,1);
  414. YY_GroupParam->AllSetLength = 0;
  415. for(i = 0;i < 5;i++)
  416. {
  417. YY_GroupParam->AllSetLength += YY_InchLengthCalLength(YY_GroupParam->LeftToothLengthINCH[i],YY_GroupParam->LeftToothLengthINCHSpace[i],YY_GroupParam->SetTotal[i]);
  418. }
  419. YY_SingleParam->SetLength = YY_ToothNumCalLength(YY_SingleToothLength,(YY_SingleParam->LeftToothNum + YY_SingleParam->LeftToothNumSpace),YY_SingleParam->SetTotal);
  420. YY_GroupParam->AllSetTotal = 0;
  421. for(i = 0;i < 5;i++)
  422. {
  423. YY_GroupParam->AllSetTotal += YY_GroupParam->SetTotal[i];
  424. }
  425. for(i = 0;i < 5;i++)
  426. {
  427. YY_GroupParam->LeftToothNum[i] = YY_ToothLengthInchCalNum(YY_SingleToothLength,YY_GroupParam->LeftToothLengthINCH[i],1);
  428. }
  429. for(i = 0;i < 5;i++)
  430. {
  431. YY_GroupParam->LeftToothNumSpace[i] = YY_ToothLengthInchCalNum(YY_SingleToothLength,YY_GroupParam->LeftToothLengthINCHSpace[i],1);
  432. }
  433. for(i = 0;i < 5;i++)
  434. {
  435. YY_GroupParam->LeftToothLengthCM[i] = YY_ToothLengthInchCalCM(YY_SingleToothLength,YY_GroupParam->LeftToothLengthINCH[i],1);
  436. }
  437. for(i = 0;i < 5;i++)
  438. {
  439. YY_GroupParam->LeftToothLengthCMSpace[i] = YY_ToothLengthInchCalCM(YY_SingleToothLength,YY_GroupParam->LeftToothLengthINCHSpace[i],1);
  440. }
  441. YY_bCalInputToothNum = 1;
  442. }
  443. if(YY_bCalculateTotal) //下一程序周期计算长度的时间
  444. {
  445. YY_bCalculateTotal = 0; // 清通知位
  446. total_buff = 0;
  447. for(i = 0;i < 5;i++)
  448. {
  449. total_buff += YY_GroupParam->SetTotal[i];
  450. }
  451. if(YY_GroupParam->AllSetTotal > total_buff)YY_GroupParam->AllSetTotal = total_buff;
  452. YY_cTotal_Time();
  453. }
  454. if(YY_bCalAllLength)
  455. {
  456. YY_bCalAllLength = 0;
  457. YY_GroupParam->AllSetLength = 0;
  458. for(i = 0;i < 5;i++)
  459. {
  460. YY_GroupParam->AllSetLength += YY_ToothNumCalLength(YY_SingleToothLength,(YY_GroupParam->LeftToothNum[i] + YY_GroupParam->LeftToothNumSpace[i]),YY_GroupParam->SetTotal[i]);
  461. }
  462. YY_SingleParam->SetLength = YY_ToothNumCalLength(YY_SingleToothLength,(YY_SingleParam->LeftToothNum + YY_SingleParam->LeftToothNumSpace),YY_SingleParam->SetTotal);
  463. }
  464. if(YY_bClear1)
  465. {
  466. YY_bClear1 = 0;
  467. YY_GroupParam->OverSetTotal[0] = 0;
  468. YY_GroupParam->DisplyLeftToothLengthCM[0] = 0;
  469. YY_GroupParam->DisplyLeftToothLengthCMSpace[0] = 0;
  470. YY_GroupParam->DisplyLeftToothLengthINCHSpace[0] = 0;
  471. YY_GroupParam->DisplyLeftToothLengthINCH[0] = 0;
  472. YY_GroupParam->DisplyRightToothNum[0] = 0;
  473. YY_GroupParam->DisplyRightToothNumSpace[0] = 0;
  474. }
  475. if(YY_bClear2)
  476. {
  477. YY_bClear2 = 0;
  478. YY_GroupParam->OverSetTotal[1] = 0;
  479. YY_GroupParam->DisplyLeftToothLengthCM[1] = 0;
  480. YY_GroupParam->DisplyLeftToothLengthCMSpace[1] = 0;
  481. YY_GroupParam->DisplyLeftToothLengthINCHSpace[1] = 0;
  482. YY_GroupParam->DisplyLeftToothLengthINCH[1] = 0;
  483. YY_GroupParam->DisplyRightToothNum[1] = 0;
  484. YY_GroupParam->DisplyRightToothNumSpace[1] = 0;
  485. }
  486. if(YY_bClear3)
  487. {
  488. YY_bClear3 = 0;
  489. YY_GroupParam->OverSetTotal[2] = 0;
  490. YY_GroupParam->DisplyLeftToothLengthCM[2] = 0;
  491. YY_GroupParam->DisplyLeftToothLengthCMSpace[2] = 0;
  492. YY_GroupParam->DisplyLeftToothLengthINCHSpace[2] = 0;
  493. YY_GroupParam->DisplyLeftToothLengthINCH[2] = 0;
  494. YY_GroupParam->DisplyRightToothNum[2] = 0;
  495. YY_GroupParam->DisplyRightToothNumSpace[2] = 0;
  496. }
  497. if(YY_bClear4)
  498. {
  499. YY_bClear4 = 0;
  500. YY_GroupParam->OverSetTotal[3] = 0;
  501. YY_GroupParam->DisplyLeftToothLengthCM[3] = 0;
  502. YY_GroupParam->DisplyLeftToothLengthCMSpace[3] = 0;
  503. YY_GroupParam->DisplyLeftToothLengthINCHSpace[3] = 0;
  504. YY_GroupParam->DisplyLeftToothLengthINCH[3] = 0;
  505. YY_GroupParam->DisplyRightToothNum[3] = 0;
  506. YY_GroupParam->DisplyRightToothNumSpace[3] = 0;
  507. }
  508. if(YY_bClear5)
  509. {
  510. YY_bClear5 = 0;
  511. YY_GroupParam->OverSetTotal[4] = 0;
  512. YY_GroupParam->DisplyLeftToothLengthCM[4] = 0;
  513. YY_GroupParam->DisplyLeftToothLengthCMSpace[4] = 0;
  514. YY_GroupParam->DisplyLeftToothLengthINCHSpace[4] = 0;
  515. YY_GroupParam->DisplyLeftToothLengthINCH[4] = 0;
  516. YY_GroupParam->DisplyRightToothNum[4] = 0;
  517. YY_GroupParam->DisplyRightToothNumSpace[4] = 0;
  518. }
  519. }
  520. void YY_StartZYFirst(void)
  521. {
  522. YY_ZYBuff = YY_SystemParam->StartOilTime;
  523. YY_bFirstZY = 1; //M100 倒时显示
  524. YY_bZhuYou = 1;
  525. YY_ZYDelay = dwTickCount + 1000;
  526. YY_OIL_MOTOR = 1;
  527. YY_DISPLAY_STATE = 1;
  528. YY_OilCheckDelay = dwTickCount + 2500;
  529. }
  530. void YY_ZhuYou(void)
  531. {
  532. if(YY_OIL_MOTOR)
  533. {
  534. if((dwTickCount >= YY_ZYDelay) || (YY_bZhuYou == 0))
  535. {
  536. if(YY_bFirstZY)
  537. {
  538. YY_ZYDelay = dwTickCount + 1000;
  539. if(YY_SystemParam->StartOilTime)
  540. {
  541. YY_SystemParam->StartOilTime--;
  542. }
  543. if((YY_SystemParam->StartOilTime == 0) || (YY_bZhuYou == 0)) //初次注油完成
  544. {
  545. YY_bFirstZY = 0; //M100
  546. YY_OIL_MOTOR = 0; //注油机关
  547. YY_SystemParam->StartOilTime = YY_ZYBuff;
  548. YY_ZYDelay = dwTickCount + YY_SystemParam->IntOilTime * 60 * 1000;
  549. YY_DISPLAY_STATE = 2; //注油完成
  550. }
  551. }
  552. else
  553. {
  554. YY_OIL_MOTOR = 0; //注油机关
  555. if(YY_bZhuYou)
  556. YY_ZYDelay = dwTickCount + YY_SystemParam->IntOilTime * 60 * 1000; //间隔注油时间 分钟
  557. else
  558. YY_ZYDelay = dwTickCount;
  559. }
  560. YY_bZYNow = 0; //M8 清通知位
  561. }
  562. }
  563. else if(YY_bZhuYou && ((dwTickCount >= YY_ZYDelay) || YY_bZYNow) && YY_EGMSTOP_IN)
  564. {
  565. //大于1小时,重新先注油
  566. if(((dwTickCount - YY_ZYDelay) > (3600 * 1000)) && (dwTickCount >= YY_ZYDelay))
  567. {
  568. YY_StartZYFirst();
  569. }
  570. else
  571. {
  572. YY_OIL_MOTOR = 1;
  573. YY_ZYDelay = dwTickCount + YY_SystemParam->OilTime * 1000; //注油时间 秒
  574. YY_OilCheckDelay = dwTickCount + (unsigned long)2500; //延时检测油压
  575. }
  576. YY_bZYNow = 0; //M8 清通知位
  577. }
  578. }
  579. //手动动作
  580. void YYa_ManualAction(void)
  581. {
  582. //合链机启动
  583. if(YY_bHL)
  584. {
  585. if(YY_HL_DW_IN)
  586. {
  587. YY_HL_MOTOR = 1;
  588. }
  589. else if(YY_HL_UP_IN)
  590. {
  591. YY_HL_MOTOR = 0;
  592. }
  593. }
  594. else
  595. {
  596. YY_HL_MOTOR = 0;
  597. }
  598. if(YY_bPYMotor)
  599. {
  600. YY_bPYMotor = 0;
  601. if(YY_MAIN_MOTOR)
  602. {
  603. if(!YY_bRunning)YY_bPYControl = 0;
  604. }
  605. else if(YY_bZhuYou && !YY_bOnceStartPower) YY_bPYControl = 1;
  606. }
  607. if(YY_bPYControl)
  608. {
  609. if(YY_MAIN_MOTOR == 0)
  610. {
  611. YY_CheckDelay = dwTickCount + 1000;
  612. YY_OIL_MOTOR = 1;
  613. YY_ZhuYouDelay = dwTickCount + 1000*YY_SystemParam->OilTime;
  614. YY_CheckDelay = dwTickCount + 2500;
  615. }
  616. YY_MAIN_MOTOR = 1;
  617. }
  618. else
  619. {
  620. if(YY_MAIN_MOTOR)
  621. {
  622. YY_CheckDelay = dwTickCount + 1000;
  623. }
  624. YY_MAIN_MOTOR = 0;
  625. }
  626. if(YY_bClearTotal)
  627. {
  628. YY_bClearTotal = 0;
  629. switch(YY_bMode)
  630. {
  631. case YY_SINGLE_MODE:
  632. {
  633. YY_SystemParam->AllProductTime += YY_SingleParam->SetTimeHour;
  634. YY_SystemParam->AllProductTime += YY_SingleParam->SetTimeMinute/60;
  635. YY_SingleParam->OverTotal = 0;
  636. YY_SingleParam->OverLength = 0;
  637. YY_SingleParam->SetTimeHour = 0;
  638. YY_SingleParam->SetTimeMinute = 0;
  639. }break;
  640. case YY_GROUP_MODE:
  641. {
  642. YY_SystemParam->AllProductTime += YY_GroupParam->SetTimeHour;
  643. YY_SystemParam->AllProductTime += YY_GroupParam->SetTimeMinute/60;
  644. YY_GroupParam->AllOverTotal = 0;
  645. YY_GroupParam->AllOverLength = 0;
  646. YY_GroupParam->SetTimeHour = 0;
  647. YY_GroupParam->SetTimeMinute = 0;
  648. }break;
  649. }
  650. YY_cTotal = 0;
  651. }
  652. if(YY_bClearPro)
  653. {
  654. YY_bClearPro = 0;
  655. YY_SystemParam->AllProductTime = 0;
  656. YY_SystemParam->AllProductLength = 0;
  657. }
  658. if(!YY_bRunning)
  659. {
  660. if((YY_bChangeNextGroup) && (YY_GroupParam->DisplyLeftToothNum[YY_SystemParam->NowGroup] == 0) && (YY_GroupParam->DisplyLeftToothNumSpace[YY_SystemParam->NowGroup] == 0))
  661. {
  662. YY_bChangeNextGroup = 0;
  663. YY_SystemParam->NowGroup = YY_SystemParam->NextGroupBuff - 1;
  664. }
  665. if(YY_bReset)
  666. {
  667. YY_bReset = 0;
  668. switch(YY_bMode)
  669. {
  670. case YY_SINGLE_MODE:
  671. {
  672. YY_ReSetData();
  673. }break;
  674. case YY_GROUP_MODE:
  675. {
  676. YY_ReSetData();
  677. }break;
  678. }
  679. }
  680. }
  681. //故障清除
  682. if(YY_bClearAlarm)
  683. {
  684. if(YY_SystemParam->AlarmCode& YY_TOOTH_NUM_ALARM) //叠牙时直接打空位
  685. {
  686. YY_ReSetData(); //6空位,6牙
  687. }
  688. YY_ALARM_LED = 0;
  689. YY_SystemParam->AlarmCode = 0;
  690. YY_bClearAlarm = 0;
  691. }
  692. if(YY_bSetDCTEnable)
  693. {
  694. YY_bSetDCTEnable = 0;
  695. if(YY_bDCTEnable)
  696. {
  697. YY_SingleParam->DisplyLeftToothNum = 0;
  698. YY_SingleParam->DisplyLeftToothLengthCM = 0;
  699. YY_SingleParam->DisplyLeftToothLengthINCH = 0;
  700. YY_SingleParam->DisplyLeftToothNumSpace = 0;
  701. YY_SingleParam->DisplyLeftToothLengthCMSpace = 0;
  702. YY_SingleParam->DisplyLeftToothLengthINCHSpace = 0;
  703. YY_SingleParam->DisplyRightToothNum = 0;
  704. YY_SingleParam->DisplyRightToothLengthCM = 0;
  705. YY_SingleParam->DisplyRightToothLengthINCH = 0;
  706. YY_SingleParam->DisplyRightToothNumSpace = 0;
  707. YY_SingleParam->DisplyRightToothLengthCMSpace = 0;
  708. YY_SingleParam->DisplyRightToothLengthINCHSpace = 0;
  709. YY_cStartPYFlag_Left = 1;
  710. YY_cStartPYFlag_Right = 1;
  711. }
  712. else
  713. {
  714. YY_cStartPYFlag_Left = 0;
  715. YY_cStartPYFlag_Right = 0;
  716. YY_SingleParam->DisplyLeftToothNum = 0;
  717. YY_SingleParam->DisplyLeftToothLengthCM = 0;
  718. YY_SingleParam->DisplyLeftToothLengthINCH = 0;
  719. YY_SingleParam->DisplyLeftToothNumSpace = 0;
  720. YY_SingleParam->DisplyLeftToothLengthCMSpace = 0;
  721. YY_SingleParam->DisplyLeftToothLengthINCHSpace = 0;
  722. YY_SingleParam->DisplyRightToothNum = 0;
  723. YY_SingleParam->DisplyRightToothLengthCM = 0;
  724. YY_SingleParam->DisplyRightToothLengthINCH = 0;
  725. YY_SingleParam->DisplyRightToothNumSpace = 0;
  726. YY_SingleParam->DisplyRightToothLengthCMSpace = 0;
  727. YY_SingleParam->DisplyRightToothLengthINCHSpace = 0;
  728. YY_SetLeftDCTSpace();
  729. YY_SetRightDCTSpace();
  730. }
  731. }
  732. YY_CalculataParam();
  733. }
  734. //拉链接头控制处理
  735. void YY_JieTouControl(void)
  736. {
  737. //接头检测
  738. if(YY_JT_IN_UP) //空位
  739. {
  740. YY_cJieDaiTotal = YY_SystemParam->JieTouMJToothNum;
  741. YY_cJieDaiClrTotal = 0;
  742. YY_cJieDaiState = 1;
  743. }
  744. else if(YY_JT_IN_DW)
  745. {
  746. YY_cJieDaiState = 2;
  747. if(YY_cJieDaiTotal == 0)
  748. {
  749. YY_cJieDaiTotal = YY_SystemParam->JieTouMJToothNum;
  750. }
  751. else
  752. {
  753. }
  754. }
  755. }
  756. void YY_CountYaError(void)
  757. {
  758. unsigned short i;
  759. switch(YY_bMode)
  760. {
  761. case YY_SINGLE_MODE:
  762. {
  763. //数牙出错
  764. /* if(UserParam->LeftOverToothNum || UserParam->RightOverToothNum)
  765. {
  766. if(UserParam->LeftOverToothNum >= UserParam->RightOverToothNum)
  767. {
  768. i = UserParam->LeftOverToothNum - UserParam->RightOverToothNum;
  769. }
  770. else
  771. i = UserParam->RightOverToothNum - UserParam->LeftOverToothNum;
  772. // 正常打牙状态
  773. if((i > 2) && (((i < (UserParam->LeftSetNum-1)) && (cStartPYFlag_Right == 0))
  774. // 复位打牙状态
  775. ||(cStartPYFlag_Right && (i < 5))))
  776. {
  777. M88 = 1; //M88 数牙出错
  778. ALARM_CODE = 88;
  779. if(Y017 == 0)Y16 = 1;
  780. }
  781. }
  782. else if((UserParam->LeftOverKongWei || UserParam->RightOverKongWei) && UserParam->LeftSetKongWei)
  783. {
  784. if(UserParam->LeftOverKongWei >= UserParam->RightOverKongWei)
  785. {
  786. i = UserParam->LeftOverKongWei - UserParam->RightOverKongWei;
  787. }
  788. else
  789. i = UserParam->RightOverKongWei - UserParam->LeftOverKongWei;
  790. if((i > 2) && (i != UserParam->LeftSetKongWei))
  791. {
  792. M88 = 1; //M88 数牙出错
  793. ALARM_CODE = 88;
  794. if(Y16 == 0)Y017 = 1;
  795. }
  796. } */
  797. }break;
  798. case YY_GROUP_MODE:
  799. {
  800. //数牙出错
  801. if(YY_GroupParam->DisplyLeftToothNum[YY_SystemParam->NowGroup] || YY_GroupParam->DisplyRightToothNum[YY_SystemParam->NowGroup])
  802. {
  803. if(YY_GroupParam->DisplyLeftToothNum[YY_SystemParam->NowGroup] >= YY_GroupParam->DisplyRightToothNum[YY_SystemParam->NowGroup])
  804. {
  805. i = YY_GroupParam->DisplyLeftToothNum[YY_SystemParam->NowGroup] - YY_GroupParam->DisplyRightToothNum[YY_SystemParam->NowGroup];
  806. }
  807. else
  808. i = YY_GroupParam->DisplyRightToothNum[YY_SystemParam->NowGroup] - YY_GroupParam->DisplyLeftToothNum[YY_SystemParam->NowGroup];
  809. // 正常打牙状态
  810. if((i > 2) && (((i < (YY_GroupParam->LeftToothNum[YY_SystemParam->NowGroup]-1)) && (YY_cStartPYFlag_Right == 0))
  811. // 复位打牙状态
  812. ||(YY_cStartPYFlag_Right && (i < 5))))
  813. {
  814. YYa_SetAlarmCode(YY_TOOTH_NUM_ALARM);
  815. if(Y017 == 0)Y16 = 1;
  816. }
  817. }
  818. else if((YY_GroupParam->DisplyLeftToothNumSpace[YY_SystemParam->NowGroup] || YY_GroupParam->DisplyRightToothNumSpace[YY_SystemParam->NowGroup]) && YY_GroupParam->LeftToothNumSpace[YY_SystemParam->NowGroup])
  819. {
  820. if(YY_GroupParam->DisplyLeftToothNumSpace[YY_SystemParam->NowGroup] >= YY_GroupParam->DisplyRightToothNumSpace[YY_SystemParam->NowGroup])
  821. {
  822. i = YY_GroupParam->DisplyLeftToothNumSpace[YY_SystemParam->NowGroup] - YY_GroupParam->DisplyRightToothNumSpace[YY_SystemParam->NowGroup];
  823. }
  824. else
  825. i = YY_GroupParam->DisplyRightToothNumSpace[YY_SystemParam->NowGroup] - YY_GroupParam->DisplyLeftToothNumSpace[YY_SystemParam->NowGroup];
  826. if((i > 2) && (i != YY_GroupParam->LeftToothNumSpace[YY_SystemParam->NowGroup]))
  827. {
  828. YYa_SetAlarmCode(YY_TOOTH_NUM_ALARM);
  829. if(Y16 == 0)Y017 = 1;
  830. }
  831. }
  832. }break;
  833. }
  834. }
  835. void YY_RefreshLengthInch(void)
  836. {
  837. unsigned char i;
  838. switch(YY_bMode)
  839. {
  840. case YY_SINGLE_MODE:
  841. {
  842. YY_SingleParam->DisplyLeftToothLengthCM = YY_ToothNumCalLengthCM(YY_SingleToothLength,YY_SingleParam->DisplyLeftToothNum,1);
  843. YY_SingleParam->DisplyLeftToothLengthCMSpace = YY_ToothNumCalLengthCM(YY_SingleToothLength,YY_SingleParam->DisplyLeftToothNumSpace,1);
  844. YY_SingleParam->DisplyRightToothLengthCM = YY_ToothNumCalLengthCM(YY_SingleToothLength,YY_SingleParam->DisplyRightToothNum,1);
  845. YY_SingleParam->DisplyRightToothLengthCMSpace = YY_ToothNumCalLengthCM(YY_SingleToothLength,YY_SingleParam->DisplyRightToothNumSpace,1);
  846. YY_SingleParam->DisplyLeftToothLengthINCH = YY_ToothNumCalLengthInch(YY_SingleToothLength,YY_SingleParam->DisplyLeftToothNum,1);
  847. YY_SingleParam->DisplyLeftToothLengthINCHSpace = YY_ToothNumCalLengthInch(YY_SingleToothLength,YY_SingleParam->DisplyLeftToothNumSpace,1);
  848. YY_SingleParam->DisplyRightToothLengthINCH = YY_ToothNumCalLengthInch(YY_SingleToothLength,YY_SingleParam->DisplyRightToothNum,1);
  849. YY_SingleParam->DisplyRightToothLengthINCHSpace = YY_ToothNumCalLengthInch(YY_SingleToothLength,YY_SingleParam->DisplyRightToothNumSpace,1);
  850. }break;
  851. case YY_GROUP_MODE:
  852. {
  853. for(i=0;i < 5;i++)
  854. {
  855. YY_GroupParam->DisplyLeftToothLengthCM[i] = YY_ToothNumCalLengthCM(YY_SingleToothLength,YY_GroupParam->DisplyLeftToothNum[i],1);
  856. YY_GroupParam->DisplyLeftToothLengthCMSpace[i] = YY_ToothNumCalLengthCM(YY_SingleToothLength,YY_GroupParam->DisplyLeftToothNumSpace[i],1);
  857. YY_GroupParam->DisplyLeftToothLengthINCH[i]= YY_ToothNumCalLengthInch(YY_SingleToothLength,YY_GroupParam->DisplyLeftToothNum[i],1);
  858. YY_GroupParam->DisplyLeftToothLengthINCHSpace[i] = YY_ToothNumCalLengthInch(YY_SingleToothLength,YY_GroupParam->DisplyLeftToothNumSpace[i],1);
  859. }
  860. }break;
  861. }
  862. }
  863. void YY_ReFreshRemainLife(void)
  864. {
  865. unsigned char i;
  866. for(i=0;i<16;i++)
  867. {
  868. YY_ComponentParam->RemainLife[i] = YY_ComponentParam->LeftRightLife[i] - YY_ComponentParam->LeftRightUsedLife[i];
  869. }
  870. }
  871. void YY_DisplayStateRefresh(void)
  872. {
  873. unsigned char i;
  874. switch(YY_bMode)
  875. {
  876. case YY_SINGLE_MODE:
  877. {
  878. }break;
  879. case YY_GROUP_MODE:
  880. {
  881. if(YY_bRunning)
  882. {
  883. for(i=0;i<5;i++)
  884. {
  885. if(i==YY_SystemParam->NowGroup)YY_SystemParam->TotalDisplayState[i] = 1;
  886. else
  887. {
  888. if(YY_GroupParam->OverSetTotal[i] < YY_GroupParam->SetTotal[i])
  889. {
  890. YY_SystemParam->TotalDisplayState[i] = 0;//待加工组
  891. }
  892. else
  893. {
  894. YY_SystemParam->TotalDisplayState[i] = 2;//已完成组
  895. }
  896. }
  897. }
  898. }
  899. else
  900. {
  901. for(i=0;i<5;i++)
  902. {
  903. if(i==(YY_SystemParam->NextGroupBuff - 1))YY_SystemParam->TotalDisplayState[i] = 1;
  904. else
  905. {
  906. if(YY_GroupParam->OverSetTotal[i] < YY_GroupParam->SetTotal[i])
  907. {
  908. YY_SystemParam->TotalDisplayState[i] = 0;//待加工组
  909. }
  910. else
  911. {
  912. YY_SystemParam->TotalDisplayState[i] = 2;//已完成组
  913. }
  914. }
  915. }
  916. }
  917. }break;
  918. }
  919. }
  920. //错误停机
  921. void YY_Error_Action(void)
  922. {
  923. static unsigned long tx_cnt = 0;
  924. if(YY_EGMSTOP_IN == 0) //紧急停止
  925. {
  926. YYa_SetAlarmCode(YY_EGM_ALARM);
  927. }
  928. if(dwTickCount >= YY_ErrorDelay)
  929. {
  930. if(YY_YW_IN) //液位警告
  931. {
  932. YYa_SetAlarmCode(YY_OIL_VOLUME_ALARM);
  933. }
  934. if(YY_TX_IN) //铜线故障
  935. {
  936. tx_cnt++;
  937. if(tx_cnt > 1000)
  938. {
  939. YYa_SetAlarmCode(YY_TONG_XIAN_ALARM);
  940. }
  941. }
  942. else
  943. tx_cnt = 0;
  944. if(YY_CX_IN && YY_MAIN_MOTOR) //叠牙
  945. {
  946. YYa_SetAlarmCode(YY_CHENG_XING_ALARM);
  947. }
  948. if(YY_KD_IN) //卡带故障(布带1)
  949. {
  950. YYa_SetAlarmCode(YY_KA_DAI_ALARM);
  951. }
  952. if(YY_ZIPPER_IN) //没带故障(布带2)
  953. {
  954. YYa_SetAlarmCode(YY_QUE_DAI_ALARM);
  955. }
  956. if(YY_HL_LIMIT_IN) //合链上限、下限位开关(合链1)
  957. {
  958. YYa_SetAlarmCode(YY_JIN_LIAN_ALARM);
  959. }
  960. if(dwTickCount >= YY_OilCheckDelay)
  961. {
  962. YY_OilCheckDelay= dwTickCount+ 100;
  963. //油压不到警告
  964. if(YY_OIL_MOTOR)
  965. {
  966. if(YY_YY_IN)
  967. {
  968. YYa_SetAlarmCode(YY_OIL_PRESSURE_ALARM);
  969. }
  970. }
  971. }
  972. YY_CountYaError();
  973. YY_RefreshLengthInch();
  974. YY_ReFreshRemainLife();
  975. YY_DisplayStateRefresh();
  976. }
  977. }
  978. void YYa_AlarmProtect(void)
  979. {
  980. YY_Error_Action();
  981. //旋转电磁铁动作
  982. if((YY_LEFT_IN || YY_LEFT_OUT) && (dwTickCount >= YY_LCntDelay)) //左边
  983. {
  984. YY_LEFT_IN = 0;
  985. YY_LEFT_OUT = 0;
  986. }
  987. if((YY_RIGHT_IN || YY_RIGHT_OUT) && (dwTickCount >= YY_RCntDelay)) //右边
  988. {
  989. YY_RIGHT_IN = 0;
  990. YY_RIGHT_OUT = 0;
  991. }
  992. }
  993. //检测现在加工是否会换组
  994. unsigned short YY_CheckHaveChangeGroup(void)
  995. {
  996. switch(YY_bMode)
  997. {
  998. case YY_SINGLE_MODE:
  999. {
  1000. return 0;
  1001. }break;
  1002. case YY_GROUP_MODE:
  1003. {
  1004. if(YY_GroupParam->OverSetTotal[YY_SystemParam->NowGroup] == (YY_GroupParam->SetTotal[YY_SystemParam->NowGroup] - 1))
  1005. return 1;
  1006. else
  1007. return 0;
  1008. }break;
  1009. default:return 0;
  1010. }
  1011. }
  1012. //检测剩余齿数够不够完成拉链
  1013. unsigned short YY_CheckRemainToothOk(void)
  1014. {
  1015. unsigned short toothbuff1,toothbuff2;
  1016. switch(YY_bMode)
  1017. {
  1018. case YY_SINGLE_MODE:
  1019. {
  1020. if(((YY_SingleParam->LeftToothNum+YY_SingleParam->LeftToothNumSpace) - (YY_SingleParam->DisplyLeftToothNum+YY_SingleParam->DisplyLeftToothNumSpace)) <= YY_cJieDaiTotal)
  1021. {
  1022. return 1;
  1023. }
  1024. else
  1025. {
  1026. return 0;
  1027. }
  1028. }break;
  1029. case YY_GROUP_MODE:
  1030. {
  1031. toothbuff1 = YY_GroupParam->LeftToothNum[YY_SystemParam->NowGroup] + YY_GroupParam->LeftToothNumSpace[YY_SystemParam->NowGroup];
  1032. toothbuff2 = YY_GroupParam->DisplyLeftToothNum[YY_SystemParam->NowGroup] + YY_GroupParam->DisplyLeftToothNumSpace[YY_SystemParam->NowGroup];
  1033. if(YY_CheckHaveChangeGroup())
  1034. {
  1035. if((toothbuff1 - toothbuff2 + YY_SystemParam->DifferentLengthToothNum) <= YY_cJieDaiTotal)
  1036. {
  1037. return 1;
  1038. }
  1039. else
  1040. {
  1041. return 0;
  1042. }
  1043. }
  1044. else
  1045. {
  1046. if((toothbuff1 - toothbuff2) <= YY_cJieDaiTotal)
  1047. {
  1048. return 1;
  1049. }
  1050. else
  1051. {
  1052. return 0;
  1053. }
  1054. }
  1055. }break;
  1056. default:return 0;
  1057. }
  1058. }
  1059. unsigned short YY_FindNextUserFulGroup(unsigned short now_group)
  1060. {
  1061. unsigned char i;
  1062. for(i=(now_group + 1);i<5;i++)
  1063. {
  1064. if((YY_GroupParam->OverSetTotal[i] < YY_GroupParam->SetTotal[i]) && (YY_GroupParam->SetTotal[i] != 0)) return i;
  1065. }
  1066. for(i=0;i<now_group;i++)
  1067. {
  1068. if((YY_GroupParam->OverSetTotal[i] < YY_GroupParam->SetTotal[i]) && (YY_GroupParam->SetTotal[i] != 0)) return i;
  1069. }
  1070. return 99;
  1071. }
  1072. void YY_ChangeGroupControlLeft(void)
  1073. {
  1074. switch(YY_bMode)
  1075. {
  1076. case YY_SINGLE_MODE:
  1077. {
  1078. }break;
  1079. case YY_GROUP_MODE:
  1080. {
  1081. if(YY_GroupParam->SetTotal[YY_SystemParam->NowGroup] != 0)
  1082. {
  1083. if(YY_GroupParam->OverSetTotal[YY_SystemParam->NowGroup] < YY_GroupParam->SetTotal[YY_SystemParam->NowGroup])
  1084. {
  1085. }
  1086. else
  1087. {
  1088. if(YY_FindNextUserFulGroup(YY_SystemParam->NowGroup) != 99)
  1089. {
  1090. YY_SetLeftPyData(0,YY_SystemParam->DifferentLengthToothNum);
  1091. YY_SetRightPyData(0,YY_SystemParam->DifferentLengthToothNum);
  1092. YY_cStartPYFlag_Left = 1;
  1093. YY_cStartPYFlag_Right = 1;
  1094. YY_SystemParam->NowGroup = YY_FindNextUserFulGroup(YY_SystemParam->NowGroup);
  1095. }
  1096. }
  1097. }
  1098. }
  1099. }
  1100. }
  1101. //搜索全部做完没有
  1102. unsigned long YY_FindCanWorkNum(void)
  1103. {
  1104. unsigned char i;
  1105. switch(YY_bMode)
  1106. {
  1107. case YY_SINGLE_MODE:
  1108. {
  1109. return 1;
  1110. }break;
  1111. case YY_GROUP_MODE:
  1112. {
  1113. for(i=0;i < 5;i++)
  1114. {
  1115. if(YY_GroupParam->OverSetTotal[i] < YY_GroupParam->SetTotal[i])return 1;
  1116. }
  1117. return 0;
  1118. }break;
  1119. default:return 0;
  1120. }
  1121. }
  1122. //左边排牙动作
  1123. /*
  1124. 当在按下复位时就先打6空位,再打6牙
  1125. */
  1126. void YY_Left_Action(void)
  1127. {
  1128. YY_DIAPLAY0 = YY_cTotal;
  1129. YY_DIAPLAY1 = YY_GetSetTotal();
  1130. YY_DIAPLAY2 = YY_FindCanWorkNum();
  1131. if(YY_LEFT_COUNT_IN_UP && YY_bDCTEnable)
  1132. {
  1133. YY_RightCountEnable = 0;
  1134. if(YY_cJieDaiState == 1)
  1135. {
  1136. if(YY_cJieDaiTotal)
  1137. {
  1138. YY_cJieDaiClrTotal++;
  1139. }
  1140. else
  1141. YY_cJieDaiClrTotal = 0;
  1142. }
  1143. if(YY_cJieDaiTotal && YY_cJieDaiState)
  1144. {
  1145. YY_cJieDaiTotal--;
  1146. if(YY_cJieDaiTotal == 0)
  1147. {
  1148. YY_cStartPYFlag_Left = 3;
  1149. YY_cStartPYFlag_Right = 3;
  1150. if(YY_GetLeftSpace() == 0) // 空位设定
  1151. {
  1152. YY_SetLeftPyData(0,YY_cJieDaiClrTotal + 10 + YY_SystemParam->JieTouToothNum);
  1153. YY_SetRightPyData(0,YY_cJieDaiClrTotal + 10 +YY_SystemParam->JieTouToothNum);
  1154. YY_SetLeftSpaceDisplay(0);
  1155. YY_SetLeftDisplay(0);
  1156. YY_SetRightSpaceDisplay(0);
  1157. YY_SetRightDisplay(0);
  1158. YY_cJieDaiState = 0;
  1159. }
  1160. else
  1161. {
  1162. YY_SetLeftPyData(0,YY_cJieDaiClrTotal + 6 + YY_SystemParam->JieTouToothNum);
  1163. YY_SetRightPyData(0,YY_cJieDaiClrTotal + 6 + YY_SystemParam->JieTouToothNum);
  1164. YY_SetLeftSpaceDisplay(0);
  1165. YY_SetLeftDisplay(0);
  1166. YY_SetRightSpaceDisplay(0);
  1167. YY_SetRightDisplay(0);
  1168. YY_cJieDaiState = 0;
  1169. }
  1170. if(YY_cJieDaiState == 2)YY_cJieDaiState = 0;
  1171. if(YY_bDCTEnable)
  1172. {
  1173. YY_SetLeftDCTSpace();
  1174. YY_SetRightDCTSpace();
  1175. }
  1176. }
  1177. }
  1178. if(YY_NowLeftPyKongWei)
  1179. {
  1180. if(YY_cStartPYFlag_Left)
  1181. {
  1182. YY_cStartPYFlag_Left = 0;
  1183. //变为空位,不用铜丝
  1184. if(YY_bDCTEnable)
  1185. {
  1186. YY_SetLeftDCTSpace();
  1187. }
  1188. }
  1189. YY_NowLeftPyKongWei--;
  1190. if(YY_NowLeftPyKongWei == 0)YY_cStartPYFlag_Left = 1;
  1191. }
  1192. else if(YY_NowLeftPyNum)
  1193. {
  1194. if(YY_cStartPYFlag_Left && (YY_cOverTotalLeftFlg == 0))
  1195. {
  1196. YY_cStartPYFlag_Left = 0;
  1197. if(YY_bDCTEnable)
  1198. {
  1199. //变为打牙,
  1200. YY_SetLeftDCTTooth();
  1201. }
  1202. }
  1203. YY_NowLeftPyNum--;
  1204. if(YY_NowLeftPyNum == 0)
  1205. {
  1206. YY_cStartPYFlag_Left = 1;
  1207. YY_cOverTotalLeftFlg = 0;
  1208. }
  1209. }
  1210. else if(YY_GetLeftToothNum() > YY_GetLeftToothNumDisplay()) //打齿状态
  1211. {
  1212. if(YY_cStartPYFlag_Left)
  1213. {
  1214. YY_cStartPYFlag_Left = 0;
  1215. if(YY_bDCTEnable)
  1216. {
  1217. //变为打牙,
  1218. YY_SetLeftDCTTooth();
  1219. }
  1220. }
  1221. YY_LeftToothDisplayAdd();
  1222. if(YY_cJieDaiState)
  1223. {
  1224. if(YY_GetLeftSpace() != 0)
  1225. {
  1226. if(YY_CheckRemainToothOk())
  1227. {
  1228. }
  1229. else
  1230. {
  1231. YY_SetLeftPyData(0,YY_cJieDaiTotal);
  1232. YY_SetLeftSpaceDisplay(0);
  1233. YY_SetLeftDisplay(0);
  1234. YY_SetRightPyData(0,YY_cJieDaiTotal);
  1235. YY_SetRightSpaceDisplay(0);
  1236. YY_SetRightDisplay(0);
  1237. YY_cStartPYFlag_Left = 1;
  1238. YY_cStartPYFlag_Right = 1;
  1239. }
  1240. }
  1241. }
  1242. if(YY_GetLeftToothNum() == YY_GetLeftToothNumDisplay()) //打完齿
  1243. {
  1244. YY_cStartPYFlag_Left = 1;
  1245. YY_LeftOverSet();
  1246. if(YY_GetLeftSpace() == 0)
  1247. {
  1248. if(YY_bChangeNextGroup)
  1249. {
  1250. YY_bChangeNextGroup = 0;
  1251. YY_SystemParam->NowGroup = YY_SystemParam->NextGroupBuff - 1;
  1252. YY_SetLeftPyData(0,YY_SystemParam->DifferentLengthToothNum);
  1253. YY_SetRightPyData(0,YY_SystemParam->DifferentLengthToothNum);
  1254. YY_cStartPYFlag_Left = 1;
  1255. YY_cStartPYFlag_Right = 1;
  1256. }
  1257. YY_ChangeGroupControlLeft();
  1258. YY_SetLeftSpaceDisplay(0);
  1259. YY_SetLeftDisplay(0);
  1260. }
  1261. //按停止 或产量到
  1262. if(YY_bSingStop || (YY_cTotal >= YY_GetSetTotal()) || (YY_FindCanWorkNum() == 0))
  1263. {
  1264. if(YY_GetLeftSpace() == 0)
  1265. {
  1266. if((YY_cTotal >= YY_GetSetTotal()) || (YY_FindCanWorkNum() == 0))
  1267. {
  1268. YY_SetLeftPyData(10,YY_SystemParam->DifferentLengthToothNum);
  1269. YY_SetRightPyData(10,YY_SystemParam->DifferentLengthToothNum);
  1270. YY_cStartPYFlag_Left = 1;
  1271. YY_cStartPYFlag_Right = 1;
  1272. YY_cOverTotalRightFlg = 1;
  1273. YY_cOverTotalLeftFlg = 1;
  1274. }
  1275. }
  1276. YY_Stop_Action();
  1277. if(YY_bSingStop == 0)YY_DISPLAY_STATE = 4;
  1278. }
  1279. YY_LeftOk = 0;
  1280. }
  1281. }
  1282. else if(YY_GetLeftSpace() > YY_GetLeftSpaceDisplay()) //空位状态
  1283. {
  1284. if(YY_cStartPYFlag_Left)
  1285. {
  1286. YY_cStartPYFlag_Left = 0;
  1287. if(YY_bDCTEnable)
  1288. {
  1289. //变为空位,不用铜丝
  1290. YY_SetLeftDCTSpace();
  1291. }
  1292. }
  1293. YY_LeftSpaceDisplayAdd();
  1294. if(YY_GetLeftSpace() == YY_GetLeftSpaceDisplay())
  1295. {
  1296. //只有大于一条拉链时才打牙状态
  1297. if(YY_cJieDaiState)
  1298. {
  1299. if(YY_CheckRemainToothOk())
  1300. {
  1301. }
  1302. else
  1303. {
  1304. if(YY_cJieDaiState != 0)
  1305. {
  1306. YY_SetLeftPyData(0,YY_cJieDaiTotal);
  1307. YY_SetLeftSpaceDisplay(0);
  1308. YY_SetLeftDisplay(0);
  1309. YY_SetRightPyData(0,YY_cJieDaiTotal);
  1310. YY_SetRightSpaceDisplay(0);
  1311. YY_SetRightDisplay(0);
  1312. }
  1313. }
  1314. }
  1315. YY_SetLeftSpaceDisplay(0);
  1316. YY_SetLeftDisplay(0);
  1317. YY_cStartPYFlag_Left = 1;
  1318. YY_LeftOk = 1;
  1319. if(YY_ChangeNextGroupFlg && YY_RightOk)
  1320. {
  1321. YY_RightOk = 0;
  1322. YY_LeftOk = 0;
  1323. YY_ChangeNextGroupFlg = 0;
  1324. YY_SetLeftSpaceDisplay(0);
  1325. YY_SetLeftDisplay(0);
  1326. if(YY_bChangeNextGroup)
  1327. {
  1328. YY_bChangeNextGroup = 0;
  1329. YY_SystemParam->NowGroup = YY_SystemParam->NextGroupBuff - 1;
  1330. YY_SetLeftPyData(0,YY_SystemParam->DifferentLengthToothNum);
  1331. YY_SetRightPyData(0,YY_SystemParam->DifferentLengthToothNum);
  1332. YY_cStartPYFlag_Left = 1;
  1333. YY_cStartPYFlag_Right = 1;
  1334. }
  1335. YY_ChangeGroupControlLeft();
  1336. }
  1337. }
  1338. }
  1339. //如叠牙或数牙导常的情况下,不能送牙
  1340. if((YY_SystemParam->AlarmCode == YY_CHENG_XING_ALARM) || (YY_SystemParam->AlarmCode == YY_TOOTH_NUM_ALARM) || !YY_bDCTEnable)// || M81 || M80)
  1341. {
  1342. YY_SetLeftDCTSpace();
  1343. }
  1344. YY_ProOnceTime = dwTickCount - YY_CalProcessDelay; //计算时间
  1345. YY_CalProcessDelay = dwTickCount;
  1346. }
  1347. }
  1348. void YY_LeftOverSet(void)
  1349. {
  1350. switch(YY_bMode)
  1351. {
  1352. case YY_SINGLE_MODE:
  1353. {
  1354. //产量计数
  1355. //当两边的齿都打完时,产量加1
  1356. if(YY_cTatal_OK)
  1357. {
  1358. YY_cTatal_OK = 0;
  1359. YY_cTotal++;
  1360. YY_AddTotal();
  1361. YY_CalUseLifeFlg = 1;
  1362. YY_bCalculateTotal = 1;
  1363. }
  1364. else
  1365. YY_cTatal_OK = 1;
  1366. }break;
  1367. case YY_GROUP_MODE:
  1368. {
  1369. //产量计数
  1370. //当两边的齿都打完时,产量加1
  1371. if(YY_cTatal_OK)
  1372. {
  1373. YY_cTatal_OK = 0;
  1374. YY_cTotal++;
  1375. YY_AddTotal();
  1376. YY_CalUseLifeFlg = 1;
  1377. YY_bCalculateTotal = 1;
  1378. YY_SaveParamFlg = 1;
  1379. YY_UseLifeNowGroup = YY_SystemParam->NowGroup;
  1380. YY_LastGroup = YY_SystemParam->NowGroup;
  1381. YY_ChangeNextGroupFlg = 1;
  1382. }
  1383. else
  1384. {
  1385. YY_cTatal_OK = 1;
  1386. }
  1387. }break;
  1388. }
  1389. }
  1390. void YY_RightOverSet(void)
  1391. {
  1392. //产量计数
  1393. //当两边的齿都打完时,产量加1
  1394. if(YY_cTatal_OK)
  1395. {
  1396. YY_cTatal_OK = 0;
  1397. YY_cTotal++;
  1398. YY_AddTotal();
  1399. YY_CalUseLifeFlg = 1;
  1400. YY_bCalculateTotal = 1;
  1401. YY_UseLifeNowGroup = YY_SystemParam->NowGroup;
  1402. YY_LastGroup = YY_SystemParam->NowGroup;
  1403. YY_ChangeNextGroupFlg = 1;
  1404. }
  1405. else
  1406. {
  1407. YY_cTatal_OK = 1;
  1408. }
  1409. }
  1410. void YY_Right_Action(void)
  1411. {
  1412. if(YY_RIGHT_COUNT_IN_UP && (YY_RightCountEnable == 0) && YY_bDCTEnable)
  1413. {
  1414. if(YY_NowRightPyKongWei)
  1415. {
  1416. if(YY_cStartPYFlag_Right)
  1417. {
  1418. YY_cStartPYFlag_Right = 0;
  1419. if(YY_bDCTEnable)
  1420. {
  1421. //变为空位,不用铜丝
  1422. YY_SetRightDCTSpace();
  1423. }
  1424. }
  1425. YY_NowRightPyKongWei--;
  1426. if((YY_NowRightPyKongWei == 0))YY_cStartPYFlag_Right = 1;
  1427. }
  1428. else if(YY_NowRightPyNum)
  1429. {
  1430. if(YY_cStartPYFlag_Right && (YY_cOverTotalRightFlg == 0))
  1431. {
  1432. YY_cStartPYFlag_Right = 0;
  1433. //变为打牙,
  1434. if(YY_bDCTEnable)
  1435. {
  1436. YY_SetRightDCTTooth();
  1437. }
  1438. }
  1439. YY_NowRightPyNum--;
  1440. if(YY_NowRightPyNum == 0)
  1441. {
  1442. YY_cStartPYFlag_Right = 1;
  1443. YY_cOverTotalRightFlg = 0;
  1444. }
  1445. }
  1446. else if(YY_GetRightToothNum() > YY_GetRightToothNumDisplay()) //打齿状态
  1447. {
  1448. if(YY_cStartPYFlag_Right)
  1449. {
  1450. YY_cStartPYFlag_Right = 0;
  1451. if(YY_bDCTEnable)
  1452. {
  1453. //变为打牙,
  1454. YY_SetRightDCTTooth();
  1455. }
  1456. }
  1457. YY_RightToothDisplayAdd();
  1458. if(YY_GetRightToothNum() == YY_GetRightToothNumDisplay()) //打齿状态
  1459. {
  1460. YY_cStartPYFlag_Right = 1;
  1461. YY_RightOverSet();
  1462. if(YY_GetRightSpace() == 0)
  1463. {
  1464. YY_SetRightSpaceDisplay(0);
  1465. YY_SetRightDisplay(0);
  1466. if(YY_bChangeNextGroup)
  1467. {
  1468. YY_bChangeNextGroup = 0;
  1469. YY_SystemParam->NowGroup = YY_SystemParam->NextGroupBuff - 1;
  1470. YY_SetLeftPyData(0,YY_SystemParam->DifferentLengthToothNum);
  1471. YY_SetRightPyData(0,YY_SystemParam->DifferentLengthToothNum);
  1472. YY_cStartPYFlag_Left = 1;
  1473. YY_cStartPYFlag_Right = 1;
  1474. }
  1475. YY_ChangeGroupControlLeft();
  1476. }
  1477. //按停止 或产量到
  1478. if(YY_bSingStop || (YY_cTotal >= YY_GetSetTotal()) || (YY_FindCanWorkNum() == 0))
  1479. {
  1480. if(YY_GetLeftSpace() == 0)
  1481. {
  1482. if((YY_cTotal >= YY_GetSetTotal()) || (YY_FindCanWorkNum() == 0))
  1483. {
  1484. YY_SetLeftPyData(10,YY_SystemParam->DifferentLengthToothNum);
  1485. YY_SetRightPyData(10,YY_SystemParam->DifferentLengthToothNum);
  1486. YY_cStartPYFlag_Left = 1;
  1487. YY_cStartPYFlag_Right = 1;
  1488. YY_cOverTotalRightFlg = 1;
  1489. YY_cOverTotalLeftFlg = 1;
  1490. }
  1491. }
  1492. YY_Stop_Action();
  1493. if(YY_bSingStop == 0)YY_DISPLAY_STATE = 4;
  1494. }
  1495. YY_RightOk = 0;
  1496. }
  1497. }
  1498. else if(YY_GetRightSpace() > YY_GetRightSpaceDisplay()) //空位状态
  1499. {
  1500. if(YY_cStartPYFlag_Right)
  1501. {
  1502. YY_cStartPYFlag_Right = 0;
  1503. if(YY_bDCTEnable)
  1504. {
  1505. //变为空位,不用铜丝
  1506. YY_SetRightDCTSpace();
  1507. }
  1508. }
  1509. YY_RightSpaceDisplayAdd();
  1510. if(YY_GetRightSpace() == YY_GetRightSpaceDisplay())
  1511. {
  1512. YY_SetRightSpaceDisplay(0);
  1513. YY_SetRightDisplay(0);
  1514. YY_cStartPYFlag_Right = 1;
  1515. YY_RightOk = 1;
  1516. if(YY_ChangeNextGroupFlg && YY_LeftOk)
  1517. {
  1518. YY_ChangeNextGroupFlg = 0;
  1519. YY_LeftOk = 0;
  1520. YY_RightOk = 0;
  1521. if(YY_bChangeNextGroup)
  1522. {
  1523. YY_bChangeNextGroup = 0;
  1524. YY_SystemParam->NowGroup = YY_SystemParam->NextGroupBuff - 1;
  1525. YY_SetLeftPyData(10,YY_SystemParam->DifferentLengthToothNum);
  1526. YY_SetRightPyData(10,YY_SystemParam->DifferentLengthToothNum);
  1527. YY_cStartPYFlag_Left = 1;
  1528. YY_cStartPYFlag_Right = 1;
  1529. }
  1530. YY_ChangeGroupControlLeft();
  1531. }
  1532. }
  1533. }
  1534. //如叠牙的情况下,不能送牙
  1535. if((YY_SystemParam->AlarmCode == YY_CHENG_XING_ALARM) || (YY_SystemParam->AlarmCode == YY_TOOTH_NUM_ALARM) || !YY_bDCTEnable)// || M81 || M80)
  1536. {
  1537. YY_SetRightDCTSpace();
  1538. }
  1539. }
  1540. }
  1541. void YYa_AutoAction(void)
  1542. {
  1543. YY_Left_Action();
  1544. YY_Right_Action();
  1545. }
  1546. void YYa_SongLiao(void)
  1547. {
  1548. //送丝启动
  1549. if(YY_bSongSi)
  1550. {
  1551. //左送料(送丝)
  1552. if(YY_LEFT_SL_DW_IN)
  1553. {
  1554. YY_LEFT_SL_MOTOR = 1;
  1555. }
  1556. else if(YY_LEFT_SL_UP_IN)
  1557. {
  1558. YY_LEFT_SL_MOTOR = 0;
  1559. }
  1560. //右送料(送丝)
  1561. if(YY_RIGHT_SL_DW_IN)
  1562. {
  1563. YY_RIGHT_SL_MOTOR = 1;
  1564. }
  1565. else if(YY_RIGHT_SL_UP_IN)
  1566. {
  1567. YY_RIGHT_SL_MOTOR = 0;
  1568. }
  1569. }
  1570. else
  1571. {
  1572. YY_LEFT_SL_MOTOR = 0;
  1573. YY_RIGHT_SL_MOTOR = 0;
  1574. }
  1575. }
  1576. // 停止工作
  1577. void YY_Stop_Action(void)
  1578. {
  1579. YY_bWorkState = 0; //M7 工作显示
  1580. if((YY_EGMSTOP_IN == 0) && ((YY_SystemParam->AlarmCode & YY_TOOTH_NUM_ALARM) == 0))YY_bZhuYou = 0; // 注油控制
  1581. YY_bHL = 0;
  1582. YY_bSongSi = 0;
  1583. YY_bPYControl = 0;
  1584. YY_DISPLAY_STATE = 2;
  1585. YY_bRunning = 0;
  1586. YY_bSingStop = 0;
  1587. }
  1588. //启动时检测当前要加工的组别可不可以加工,不可以就切换到可以加工的组别
  1589. unsigned char YY_StartCheckChoose(void)
  1590. {
  1591. switch(YY_bMode)
  1592. {
  1593. case YY_SINGLE_MODE:
  1594. {
  1595. return 1;
  1596. }break;
  1597. case YY_GROUP_MODE:
  1598. {
  1599. if(YY_GroupParam->OverSetTotal[YY_SystemParam->NowGroup] < YY_GroupParam->SetTotal[YY_SystemParam->NowGroup])
  1600. {
  1601. return 1;
  1602. }
  1603. else
  1604. {
  1605. if(YY_FindNextUserFulGroup(YY_SystemParam->NowGroup) != 99)
  1606. {
  1607. if((YY_GroupParam->DisplyLeftToothNumSpace[YY_SystemParam->NowGroup] == 0) && (YY_GroupParam->DisplyRightToothNum[YY_SystemParam->NowGroup] == 0))YY_SystemParam->NowGroup = YY_FindNextUserFulGroup(YY_SystemParam->NowGroup);
  1608. return 1;
  1609. }
  1610. else
  1611. {
  1612. return 0;
  1613. }
  1614. }
  1615. }break;
  1616. default:return 0;
  1617. }
  1618. }
  1619. void YYa_StepCheckStart(void)
  1620. {
  1621. if(YY_bFirstZY == 0)//首次加油已经完成
  1622. {
  1623. if((YY_bStart || YY_START_IN_UP) && !YY_bRunning && YY_bZhuYou && (YY_STOP_IN == 0) && (YY_SystemParam->AlarmCode== 0) && (YY_StartCheckChoose() == 1)&& (YY_cTotal < YY_GetSetTotal()))
  1624. {
  1625. YY_bWorkState = 1; //M7 工作显示
  1626. YY_bHL = 1; //M4 合链控制
  1627. YY_bSongSi = 1; //M5 送丝控制
  1628. YY_bPYControl = 1; //M6 排牙控制
  1629. YY_bZYNow = 1; //M8 马上注油D2时间
  1630. YY_DISPLAY_STATE = 3;
  1631. YY_bRunning = 1;
  1632. // YY_DIAPLAY1++;
  1633. if(!YY_bDCTEnable)
  1634. {
  1635. YY_cStartWorkTime = 3;
  1636. }
  1637. }
  1638. YY_bStart = 0; //M0
  1639. }
  1640. else
  1641. {
  1642. YY_bStart = 0; //M0
  1643. }
  1644. if((YY_cStartWorkTime != 0) && (dwTickCount >= YY_TryDelay))
  1645. {
  1646. YY_cStartWorkTime--;
  1647. YY_SetLeftDCTSpace();
  1648. YY_SetRightDCTSpace();
  1649. YY_TryDelay = dwTickCount + 500;
  1650. }
  1651. //停止
  1652. if(YY_STOP_IN || (YY_bAlarmStop == 1) || YY_bStop)
  1653. {
  1654. // 普通停止是打完当条再停止
  1655. if((YY_bStop || (YY_STOP_IN)) && YY_bDCTEnable)
  1656. {
  1657. if(YY_bPYControl)YY_bSingStop = 1;
  1658. }
  1659. else //其它故障都要立即停止
  1660. {
  1661. if(YY_bRunning)YY_ALARM_LED = 1;
  1662. YY_Stop_Action();
  1663. }
  1664. YY_bStop = 0; //M0 系统复位
  1665. YY_bAlarmStop = 0;
  1666. }
  1667. }
  1668. //零件寿命相关控制和运算
  1669. void YYa_CalParts(void)
  1670. {
  1671. // AddUsedLifeControl();
  1672. if(YY_bClearLife1)
  1673. {
  1674. YY_bClearLife1 = 0;
  1675. YY_ComponentParam->LeftRightLife[0] = 0;
  1676. YY_ComponentParam->LeftRightUsedLife[0] = 0;
  1677. YY_ComponentParam->RefreshTimes[0]++;
  1678. }
  1679. if(YY_bClearTimes1)
  1680. {
  1681. YY_bClearTimes1 = 0;
  1682. YY_ComponentParam->RefreshTimes[0] = 0;
  1683. }
  1684. if(YY_bClearLife2)
  1685. {
  1686. YY_bClearLife2 = 0;
  1687. YY_ComponentParam->LeftRightLife[1] = 0;
  1688. YY_ComponentParam->LeftRightUsedLife[1] = 0;
  1689. YY_ComponentParam->RefreshTimes[1]++;
  1690. }
  1691. if(YY_bClearTimes2)
  1692. {
  1693. YY_bClearTimes2 = 0;
  1694. YY_ComponentParam->RefreshTimes[1] = 0;
  1695. }
  1696. if(YY_bClearLife3)
  1697. {
  1698. YY_bClearLife3 = 0;
  1699. YY_ComponentParam->LeftRightLife[2] = 0;
  1700. YY_ComponentParam->LeftRightUsedLife[2] = 0;
  1701. YY_ComponentParam->RefreshTimes[2]++;
  1702. }
  1703. if(YY_bClearTimes3)
  1704. {
  1705. YY_bClearTimes3 = 0;
  1706. YY_ComponentParam->RefreshTimes[2] = 0;
  1707. }
  1708. if(YY_bClearLife4)
  1709. {
  1710. YY_bClearLife4 = 0;
  1711. YY_ComponentParam->LeftRightLife[3] = 0;
  1712. YY_ComponentParam->LeftRightUsedLife[3] = 0;
  1713. YY_ComponentParam->RefreshTimes[3]++;
  1714. }
  1715. if(YY_bClearTimes4)
  1716. {
  1717. YY_bClearTimes4 = 0;
  1718. YY_ComponentParam->RefreshTimes[3] = 0;
  1719. }
  1720. if(YY_bClearLife5)
  1721. {
  1722. YY_bClearLife5 = 0;
  1723. YY_ComponentParam->LeftRightLife[4] = 0;
  1724. YY_ComponentParam->LeftRightUsedLife[4] = 0;
  1725. YY_ComponentParam->RefreshTimes[4]++;
  1726. }
  1727. if(YY_bClearTimes5)
  1728. {
  1729. YY_bClearTimes5 = 0;
  1730. YY_ComponentParam->RefreshTimes[4] = 0;
  1731. }
  1732. if(YY_bClearLife6)
  1733. {
  1734. YY_bClearLife6 = 0;
  1735. YY_ComponentParam->LeftRightLife[5] = 0;
  1736. YY_ComponentParam->LeftRightUsedLife[5] = 0;
  1737. YY_ComponentParam->RefreshTimes[5]++;
  1738. }
  1739. if(YY_bClearTimes6)
  1740. {
  1741. YY_bClearTimes6 = 0;
  1742. YY_ComponentParam->RefreshTimes[5] = 0;
  1743. }
  1744. if(YY_bClearLife7)
  1745. {
  1746. YY_bClearLife7 = 0;
  1747. YY_ComponentParam->LeftRightLife[6] = 0;
  1748. YY_ComponentParam->LeftRightUsedLife[6] = 0;
  1749. YY_ComponentParam->RefreshTimes[6]++;
  1750. }
  1751. if(YY_bClearTimes7)
  1752. {
  1753. YY_bClearTimes7 = 0;
  1754. YY_ComponentParam->RefreshTimes[6] = 0;
  1755. }
  1756. if(YY_bClearLife8)
  1757. {
  1758. YY_bClearLife8 = 0;
  1759. YY_ComponentParam->LeftRightLife[7] = 0;
  1760. YY_ComponentParam->LeftRightUsedLife[7] = 0;
  1761. YY_ComponentParam->RefreshTimes[7]++;
  1762. }
  1763. if(YY_bClearTimes8)
  1764. {
  1765. YY_bClearTimes8 = 0;
  1766. YY_ComponentParam->RefreshTimes[7] = 0;
  1767. }
  1768. if(YY_bClearLife9)
  1769. {
  1770. YY_bClearLife9 = 0;
  1771. YY_ComponentParam->LeftRightLife[8] = 0;
  1772. YY_ComponentParam->LeftRightUsedLife[8] = 0;
  1773. YY_ComponentParam->RefreshTimes[8]++;
  1774. }
  1775. if(YY_bClearTimes9)
  1776. {
  1777. YY_bClearTimes9 = 0;
  1778. YY_ComponentParam->RefreshTimes[8] = 0;
  1779. }
  1780. if(YY_bClearLife10)
  1781. {
  1782. YY_bClearLife10 = 0;
  1783. YY_ComponentParam->LeftRightLife[9] = 0;
  1784. YY_ComponentParam->LeftRightUsedLife[9] = 0;
  1785. YY_ComponentParam->RefreshTimes[9]++;
  1786. }
  1787. if(YY_bClearTimes10)
  1788. {
  1789. YY_bClearTimes10 = 0;
  1790. YY_ComponentParam->RefreshTimes[9] = 0;
  1791. }
  1792. if(YY_bClearLife11)
  1793. {
  1794. YY_bClearLife11 = 0;
  1795. YY_ComponentParam->LeftRightLife[10] = 0;
  1796. YY_ComponentParam->LeftRightUsedLife[10] = 0;
  1797. YY_ComponentParam->RefreshTimes[10]++;
  1798. }
  1799. if(YY_bClearTimes11)
  1800. {
  1801. YY_bClearTimes1 = 0;
  1802. YY_ComponentParam->RefreshTimes[10] = 0;
  1803. }
  1804. if(YY_bClearLife12)
  1805. {
  1806. YY_bClearLife12 = 0;
  1807. YY_ComponentParam->LeftRightLife[11] = 0;
  1808. YY_ComponentParam->LeftRightUsedLife[11] = 0;
  1809. YY_ComponentParam->RefreshTimes[11]++;
  1810. }
  1811. if(YY_bClearTimes12)
  1812. {
  1813. YY_bClearTimes12 = 0;
  1814. YY_ComponentParam->RefreshTimes[11] = 0;
  1815. }
  1816. if(YY_bClearLife13)
  1817. {
  1818. YY_bClearLife13 = 0;
  1819. YY_ComponentParam->LeftRightLife[12] = 0;
  1820. YY_ComponentParam->LeftRightUsedLife[12] = 0;
  1821. YY_ComponentParam->RefreshTimes[12]++;
  1822. }
  1823. if(YY_bClearTimes13)
  1824. {
  1825. YY_bClearTimes13 = 0;
  1826. YY_ComponentParam->RefreshTimes[12] = 0;
  1827. }
  1828. if(YY_bClearLife14)
  1829. {
  1830. YY_bClearLife14 = 0;
  1831. YY_ComponentParam->LeftRightLife[13] = 0;
  1832. YY_ComponentParam->LeftRightUsedLife[13] = 0;
  1833. YY_ComponentParam->RefreshTimes[13]++;
  1834. }
  1835. if(YY_bClearTimes14)
  1836. {
  1837. YY_bClearTimes14 = 0;
  1838. YY_ComponentParam->RefreshTimes[13] = 0;
  1839. }
  1840. if(YY_bClearLife15)
  1841. {
  1842. YY_bClearLife15 = 0;
  1843. YY_ComponentParam->LeftRightLife[14] = 0;
  1844. YY_ComponentParam->LeftRightUsedLife[14] = 0;
  1845. YY_ComponentParam->RefreshTimes[14]++;
  1846. }
  1847. if(YY_bClearTimes15)
  1848. {
  1849. YY_bClearTimes15 = 0;
  1850. YY_ComponentParam->RefreshTimes[14] = 0;
  1851. }
  1852. if(YY_bClearLife16)
  1853. {
  1854. YY_bClearLife16 = 0;
  1855. YY_ComponentParam->LeftRightLife[15] = 0;
  1856. YY_ComponentParam->LeftRightUsedLife[15] = 0;
  1857. YY_ComponentParam->RefreshTimes[15]++;
  1858. }
  1859. if(YY_bClearTimes16)
  1860. {
  1861. YY_bClearTimes16 = 0;
  1862. YY_ComponentParam->RefreshTimes[15] = 0;
  1863. }
  1864. }
  1865. ///////////////////////////////////////////////////////////////////////////////////////////////
  1866. void YY_LeftToothDisplayAdd(void)
  1867. {
  1868. switch(YY_bMode)
  1869. {
  1870. case YY_SINGLE_MODE:YY_SingleParam->DisplyLeftToothNum++;break;
  1871. case YY_GROUP_MODE:YY_GroupParam->DisplyLeftToothNum[YY_SystemParam->NowGroup]++;break;
  1872. }
  1873. }
  1874. void YY_RightToothDisplayAdd(void)
  1875. {
  1876. switch(YY_bMode)
  1877. {
  1878. case YY_SINGLE_MODE:YY_SingleParam->DisplyRightToothNum++;break;
  1879. case YY_GROUP_MODE:YY_GroupParam->DisplyRightToothNum[YY_SystemParam->NowGroup]++;break;
  1880. }
  1881. }
  1882. void YY_LeftSpaceDisplayAdd(void)
  1883. {
  1884. switch(YY_bMode)
  1885. {
  1886. case YY_SINGLE_MODE:YY_SingleParam->DisplyLeftToothNumSpace++;break;
  1887. case YY_GROUP_MODE:YY_GroupParam->DisplyLeftToothNumSpace[YY_SystemParam->NowGroup]++;break;
  1888. }
  1889. }
  1890. void YY_RightSpaceDisplayAdd(void)
  1891. {
  1892. switch(YY_bMode)
  1893. {
  1894. case YY_SINGLE_MODE:YY_SingleParam->DisplyRightToothNumSpace++;break;
  1895. case YY_GROUP_MODE:YY_GroupParam->DisplyRightToothNumSpace[YY_SystemParam->NowGroup]++;break;
  1896. }
  1897. }
  1898. unsigned long YY_GetLeftToothNum(void)
  1899. {
  1900. switch(YY_bMode)
  1901. {
  1902. case YY_SINGLE_MODE:
  1903. {
  1904. return YY_SingleParam->LeftToothNum;
  1905. }break;
  1906. case YY_GROUP_MODE:
  1907. {
  1908. return YY_GroupParam->LeftToothNum[YY_SystemParam->NowGroup];
  1909. }break;
  1910. default:return 0;
  1911. }
  1912. }
  1913. unsigned long YY_GetRightToothNum(void)
  1914. {
  1915. switch(YY_bMode)
  1916. {
  1917. case YY_SINGLE_MODE:
  1918. {
  1919. return YY_SingleParam->RightToothNum;
  1920. }break;
  1921. case YY_GROUP_MODE:
  1922. {
  1923. return YY_GroupParam->LeftToothNum[YY_SystemParam->NowGroup];
  1924. }break;
  1925. default:return 0;
  1926. }
  1927. }
  1928. unsigned long YY_GetLeftToothNumDisplay(void)
  1929. {
  1930. switch(YY_bMode)
  1931. {
  1932. case YY_SINGLE_MODE:
  1933. {
  1934. return YY_SingleParam->DisplyLeftToothNum;
  1935. }break;
  1936. case YY_GROUP_MODE:
  1937. {
  1938. return YY_GroupParam->DisplyLeftToothNum[YY_SystemParam->NowGroup];
  1939. }break;
  1940. default:return 0;
  1941. }
  1942. }
  1943. unsigned long YY_GetRightToothNumDisplay(void)
  1944. {
  1945. switch(YY_bMode)
  1946. {
  1947. case YY_SINGLE_MODE:
  1948. {
  1949. return YY_SingleParam->DisplyRightToothNum;
  1950. }break;
  1951. case YY_GROUP_MODE:
  1952. {
  1953. return YY_GroupParam->DisplyRightToothNum[YY_SystemParam->NowGroup];
  1954. }break;
  1955. default:return 0;
  1956. }
  1957. }
  1958. unsigned long YY_GetLeftSpace(void)
  1959. {
  1960. switch(YY_bMode)
  1961. {
  1962. case YY_SINGLE_MODE:
  1963. {
  1964. return YY_SingleParam->LeftToothNumSpace;
  1965. }break;
  1966. case YY_GROUP_MODE:
  1967. {
  1968. return YY_GroupParam->LeftToothNumSpace[YY_SystemParam->NowGroup];
  1969. }break;
  1970. default:return 0;
  1971. }
  1972. }
  1973. unsigned long YY_GetRightSpace(void)
  1974. {
  1975. switch(YY_bMode)
  1976. {
  1977. case YY_SINGLE_MODE:
  1978. {
  1979. return YY_SingleParam->RightToothNumSpace;
  1980. }break;
  1981. case YY_GROUP_MODE:
  1982. {
  1983. return YY_GroupParam->LeftToothNumSpace[YY_SystemParam->NowGroup];
  1984. }break;
  1985. default:return 0;
  1986. }
  1987. }
  1988. unsigned long YY_GetLeftSpaceDisplay(void)
  1989. {
  1990. switch(YY_bMode)
  1991. {
  1992. case YY_SINGLE_MODE:
  1993. {
  1994. return YY_SingleParam->DisplyLeftToothNumSpace;
  1995. }break;
  1996. case YY_GROUP_MODE:
  1997. {
  1998. return YY_GroupParam->DisplyLeftToothNumSpace[YY_SystemParam->NowGroup];
  1999. }break;
  2000. default:return 0;
  2001. }
  2002. }
  2003. unsigned long YY_GetRightSpaceDisplay(void)
  2004. {
  2005. switch(YY_bMode)
  2006. {
  2007. case YY_SINGLE_MODE:
  2008. {
  2009. return YY_SingleParam->DisplyRightToothNumSpace;
  2010. }break;
  2011. case YY_GROUP_MODE:
  2012. {
  2013. return YY_GroupParam->DisplyRightToothNumSpace[YY_SystemParam->NowGroup];
  2014. }break;
  2015. default:return 0;
  2016. }
  2017. }
  2018. void YY_SetLeftDCTSpace(void)
  2019. {
  2020. //变为空位,不用铜丝
  2021. YY_LEFT_OUT = 0;
  2022. YY_LEFT_IN = 1;
  2023. YY_LCntDelay = dwTickCount + YY_DCT_OUT_TIME;
  2024. }
  2025. void YY_SetLeftDCTTooth(void)
  2026. {
  2027. //变为排牙
  2028. YY_LEFT_OUT = 1;
  2029. YY_LEFT_IN = 0;
  2030. YY_LCntDelay = dwTickCount + YY_DCT_OUT_TIME;
  2031. }
  2032. void YY_SetRightDCTSpace(void)
  2033. {
  2034. //变为空位,不用铜丝
  2035. YY_RIGHT_OUT = 0;
  2036. YY_RIGHT_IN = 1;
  2037. YY_RCntDelay = dwTickCount + YY_DCT_OUT_TIME;
  2038. }
  2039. void YY_SetRightDCTTooth(void)
  2040. {
  2041. //变为排牙
  2042. YY_RIGHT_OUT = 1;
  2043. YY_RIGHT_IN = 0;
  2044. YY_RCntDelay = dwTickCount + YY_DCT_OUT_TIME;
  2045. }
  2046. void YY_SetLeftPyData(unsigned short cLeftData,unsigned short cLeftKongWei)
  2047. {
  2048. YY_NowLeftPyKongWei = cLeftKongWei;
  2049. YY_NowLeftPyNum = cLeftData;
  2050. }
  2051. void YY_SetRightPyData(unsigned short cRightData,unsigned short cRightKongWei)
  2052. {
  2053. YY_NowRightPyKongWei = cRightKongWei;
  2054. YY_NowRightPyNum = cRightData;
  2055. }
  2056. void YY_SetLeftDisplay(unsigned short source_data)
  2057. {
  2058. switch(YY_bMode)
  2059. {
  2060. case YY_SINGLE_MODE:
  2061. {
  2062. YY_SingleParam->DisplyLeftToothNum = source_data;
  2063. }break;
  2064. case YY_GROUP_MODE:
  2065. {
  2066. YY_GroupParam->DisplyLeftToothNum[YY_SystemParam->NowGroup] = source_data;
  2067. }break;
  2068. }
  2069. }
  2070. void YY_SetRightDisplay(unsigned short source_data)
  2071. {
  2072. switch(YY_bMode)
  2073. {
  2074. case YY_SINGLE_MODE:
  2075. {
  2076. YY_SingleParam->DisplyRightToothNum = source_data;
  2077. }break;
  2078. case YY_GROUP_MODE:
  2079. {
  2080. YY_GroupParam->DisplyRightToothNum[YY_SystemParam->NowGroup] = source_data;
  2081. }break;
  2082. }
  2083. }
  2084. void YY_SetLeftSpaceDisplay(unsigned short source_data)
  2085. {
  2086. switch(YY_bMode)
  2087. {
  2088. case YY_SINGLE_MODE:
  2089. {
  2090. YY_SingleParam->DisplyLeftToothNumSpace = source_data;
  2091. }break;
  2092. case YY_GROUP_MODE:
  2093. {
  2094. YY_GroupParam->DisplyLeftToothNumSpace[YY_SystemParam->NowGroup] = source_data;
  2095. }break;
  2096. }
  2097. }
  2098. void YY_SetRightSpaceDisplay(unsigned short source_data)
  2099. {
  2100. switch(YY_bMode)
  2101. {
  2102. case YY_SINGLE_MODE:
  2103. {
  2104. YY_SingleParam->DisplyRightToothNumSpace = source_data;
  2105. }break;
  2106. case YY_GROUP_MODE:
  2107. {
  2108. YY_GroupParam->DisplyRightToothNumSpace[YY_SystemParam->NowGroup] = source_data;
  2109. }break;
  2110. }
  2111. }
  2112. unsigned long YY_GetTotal(void)
  2113. {
  2114. switch(YY_bMode)
  2115. {
  2116. case YY_SINGLE_MODE:
  2117. {
  2118. return YY_SingleParam->OverTotal;
  2119. }break;
  2120. case YY_GROUP_MODE:
  2121. {
  2122. return YY_GroupParam->AllOverTotal;
  2123. }break;
  2124. default:return 0;
  2125. }
  2126. }
  2127. unsigned long YY_GetSetTotal(void)
  2128. {
  2129. switch(YY_bMode)
  2130. {
  2131. case YY_SINGLE_MODE:return YY_SingleParam->SetTotal;break;
  2132. case YY_GROUP_MODE:return YY_GroupParam->AllSetTotal;break;
  2133. default:return 0;
  2134. }
  2135. }
  2136. void YY_AddTotal(void)
  2137. {
  2138. switch(YY_bMode)
  2139. {
  2140. case YY_SINGLE_MODE:YY_SingleParam->OverTotal++;break;
  2141. case YY_GROUP_MODE:
  2142. {
  2143. YY_GroupParam->AllOverTotal++;
  2144. YY_GroupParam->OverSetTotal[YY_SystemParam->NowGroup]++;
  2145. }break;
  2146. }
  2147. }
  2148. //算单个齿长度
  2149. float YY_CalToothLength(unsigned short roll_diameter,unsigned short tooth_num)
  2150. {
  2151. float buff,buff_num;
  2152. buff = roll_diameter;
  2153. buff_num = tooth_num;
  2154. return (buff * 3.1415926 / buff_num);
  2155. }
  2156. //输入齿数计算长度返回的是单位厘米
  2157. unsigned long YY_ToothNumCalLengthCM(float single_length,unsigned short tooth_num,unsigned long zipper_num)
  2158. {
  2159. float buff1,buff2,buff3;
  2160. buff1 = single_length;
  2161. buff2 = tooth_num;
  2162. buff3 = zipper_num;
  2163. return (unsigned long)(buff1 * buff2 * buff3);
  2164. }
  2165. //输入齿数计算长度返回的是单位英寸
  2166. unsigned long YY_ToothNumCalLengthInch(float single_length,unsigned short tooth_num,unsigned long zipper_num)
  2167. {
  2168. float buff1,buff2,buff3;
  2169. buff1 = single_length;
  2170. buff2 = tooth_num;
  2171. buff3 = zipper_num;
  2172. return (unsigned long)(buff1 * buff2 * buff3 / 2.5399);
  2173. }
  2174. //输入长度厘米算齿数
  2175. unsigned long YY_ToothLengthCMCalNum(float single_length,unsigned short tooth_length,unsigned long zipper_num)
  2176. {
  2177. float buff1,buff2,buff3;
  2178. buff1 = zipper_num;
  2179. buff2 = tooth_length;
  2180. buff3 = single_length;
  2181. return (unsigned long)ceil(buff1 * buff2 / buff3);
  2182. }
  2183. //输入长度厘米算英寸
  2184. unsigned long YY_ToothLengthCMCalInch(float single_length,unsigned short tooth_length,unsigned long zipper_num)
  2185. {
  2186. float buff1,buff2;
  2187. buff1 = tooth_length;
  2188. buff2 = zipper_num;
  2189. return (unsigned long)(buff1 * buff2 / 2.5399);
  2190. }
  2191. //输入厘米长度计算总长度单位米
  2192. unsigned long YY_LengthCalLengthM(unsigned short set_length,unsigned short kongwei_length,unsigned long zipper_num)
  2193. {
  2194. float buff1,buff2,buff3;
  2195. buff1 = set_length;
  2196. buff2 = kongwei_length;
  2197. buff3 = zipper_num;
  2198. return (unsigned long)((buff1 + buff2) * buff3 / 100);
  2199. }
  2200. //输入英寸长度计算总长度
  2201. unsigned long YY_InchLengthCalLength(unsigned short set_length,unsigned short kongwei_length,unsigned long zipper_num)
  2202. {
  2203. float buff1,buff2,buff3;
  2204. buff1 = set_length;
  2205. buff2 = kongwei_length;
  2206. buff3 = zipper_num;
  2207. return (unsigned long)((buff1 + buff2) * buff3 / 2.5399);
  2208. }
  2209. //输入齿数计算长度返回的是单位米
  2210. unsigned long YY_ToothNumCalLength(float single_length,unsigned short tooth_num,unsigned long zipper_num)
  2211. {
  2212. float buff1,buff2,buff3;
  2213. buff1 = single_length;
  2214. buff2 = tooth_num;
  2215. buff3 = zipper_num;
  2216. return (unsigned long)(buff1 * buff2 * buff3 / 1000);
  2217. }
  2218. //输入齿数计算长度返回的是单位米带浮点型
  2219. float YY_ToothNumCalLengthFloat(float single_length,unsigned short tooth_num,unsigned long zipper_num)
  2220. {
  2221. float buff1,buff2,buff3;
  2222. buff1 = single_length;
  2223. buff2 = tooth_num;
  2224. buff3 = zipper_num;
  2225. return (buff1 * buff2 * buff3 / 1000);
  2226. }
  2227. //输入长度英寸算齿数
  2228. unsigned long YY_ToothLengthInchCalNum(float single_length,unsigned short tooth_length,unsigned long zipper_num)
  2229. {
  2230. float buff1,buff2;
  2231. buff1 = zipper_num * tooth_length;
  2232. buff2 = single_length;
  2233. return (unsigned long)ceil(buff1 * 2.5399 / buff2);
  2234. }
  2235. //输入长度英寸算厘米
  2236. unsigned long YY_ToothLengthInchCalCM(float single_length,unsigned short tooth_length,unsigned long zipper_num)
  2237. {
  2238. float buff1,buff2;
  2239. buff1 = tooth_length;
  2240. buff2 = zipper_num;
  2241. return (unsigned long)(buff1 * buff2 * 2.5399);
  2242. }
  2243. #endif