鍩轰簬Codesys鐢⊿T璇█瀹炵幇寰幆闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠g爜瀹炰緥-CODESYS璧勬簮涓嬭浇鍖-閰峰痉缃 - CoDeSys杞欢鏁欑▼涓嬭浇,CoDeSys宸ユ帶璧勮闂ㄦ埛
HSC6490-cn涓浗鍒堕狅紝涓浗鑺瘇
鏌ョ湅: 1592|鍥炲: 0

鍩轰簬Codesys鐢⊿T璇█瀹炵幇寰幆闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠g爜瀹炰緥

[澶嶅埗閾炬帴]
  • TA鐨勬瘡鏃ュ績鎯
    鎱垫噿
    2017-11-9 20:49
  • 绛惧埌澶╂暟: 2 澶

    [LV.1]鍒濇潵涔嶅埌

    鍙戣〃浜 2023-4-12 22:14:17 | 鏄剧ず鍏ㄩ儴妤煎眰 |闃呰妯″紡
    鍩轰簬Codesys鐢⊿T璇█瀹炵幇寰幆闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠g爜瀹炰緥-1.gif


    涓銆 闃熷垪瀹氫箟

    闃熷垪鏄竴绉嶅厛鍏ュ厛鍑(FIFO鈥斺攆irst in first out)绾挎ц〃,瀹冨彧鍏佽鍦ㄨ〃鐨勫墠绔紙front锛夎繘琛屽垹闄ゆ搷浣滐紝鑰屽湪琛ㄧ殑鍚庣锛坮ear锛夎繘琛屾彃鍏ユ搷浣溿
    浜屻侀槦鍒楀疄鐜

    瀹炵幇闃熷垪锛屾垜浠彲浠ヤ娇鐢ㄥ姩鎬佹暟缁勪互鍙婃寚鍚戦槦鍒楀ご閮ㄧ殑绱㈠紩鍜屾寚鍚戦槦鍒楀熬閮ㄧ殑绱㈠紩

    鍩轰簬Codesys鐢⊿T璇█瀹炵幇寰幆闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠g爜瀹炰緥-2.jpg

    渚嬪鎴戜滑鍒嗛厤涓涓渶闀块暱搴︿负6鐨勬暟缁勶紝鎴戜滑鏈澶氬彧鑳芥坊鍔6涓厓绱狅紝鍦ㄧ6娆″厓绱22鍏ラ槦鍚庯紝鍥犱负闃熷垪宸叉弧锛岄槦鍒椾笉鑳芥帴鍙楁洿澶氱殑鍏ラ槦璇锋眰銆

    鍩轰簬Codesys鐢⊿T璇█瀹炵幇寰幆闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠g爜瀹炰緥-3.jpg

    浣嗘槸濡傛灉鎴戜滑灏嗕竴涓厓绱犲嚭闃熷悗锛屽簲璇ュ彲浠ュ啀鎺ュ彈涓涓厓绱狅紝杩欏氨瑕佽冭檻寰幆闃熷垪锛屽彲浠ラ噸鐢ㄨ娴垂鐨勭┖闂淬
    涓夈 寰幆闃熷垪璁捐

    寰幆闃熷垪鏄竴绉嶇嚎鎬ф暟鎹粨鏋勶紝鍏舵搷浣滆〃鐜板熀浜 FIFO锛堝厛杩涘厛鍑猴級鍘熷垯骞朵笖闃熷熬琚繛鎺ュ湪闃熼涔嬪悗浠ュ舰鎴愪竴涓惊鐜傚畠涔熻绉颁负鈥滅幆褰㈢紦鍐插櫒鈥濄
    C 璇█瀹炵幇

    鍔熻兘濡備笅
      Create(k):鏋勯犲櫒锛屽姩鎬佸垱寤篕澶у皬鐨勬暟缁Push(value) : 鍚戝惊鐜槦鍒椾腑鎻掑叆涓涓厓绱狅紝鎴愬姛杩斿洖truepop():浠庡惊鐜槦鍒椾腑鍒犻櫎涓涓厓绱狅紝鎴愬姛杩斿洖trueFront():浠庨槦鍒楀ご閮ㄨ幏鍙栧厓绱狅紝濡傛灉闃熷垪鏄┖锛岃繑鍥-1Rear():浠庨槦鍒楀熬閮ㄨ幏鍙栧厓绱狅紝濡傛灉闃熷垪涓虹┖锛岃繑鍥-1Empty(): 妫娴嬮槦鍒楁槸鍚︿负绌Full() : 妫娴嬮槦鍒楁槸鍚﹀凡婊Destroy:閿姣侀槦鍒
    1. typedefstruct{int*data;//鏁扮粍鎸囬拡int mTail;//灏鹃儴绱㈠紩int mHead;//澶撮儴绱㈠紩int mSize;//鏁扮粍澶у皬} MyQueue;
    2. bool Empty(MyQueue* obj);
    3. bool Full(MyQueue* obj);//鏋勯犲櫒锛屽姩鎬佸垱寤篕澶у皬鐨勬暟缁
    4. MyQueue*Create(int k){
    5. MyQueue *mMyQueue =( MyQueue *)malloc(sizeof(MyQueue));
    6. mMyQueue->data    =(int*)malloc(sizeof(int)*(k));
    7. mMyQueue->mTail   =-1;
    8. mMyQueue->mHead   =-1;
    9. mMyQueue->mSize   =  k;return mMyQueue;}//鍚戝惊鐜槦鍒椾腑鎻掑叆涓涓厓绱狅紝鎴愬姛杩斿洖true
    10. bool Push(MyQueue* obj,int value){if(obj ==0)return false;if(Full(obj))return false;if(Empty(obj))
    11.         obj->mHead  =0;
    12.       
    13.      obj->mTail =(obj->mTail +1)% obj->mSize;
    14.      obj->data[obj->mTail]= value;return true锛
    15. }//浠庡惊鐜槦鍒椾腑鍒犻櫎涓涓厓绱狅紝鎴愬姛杩斿洖true
    16. bool pop(MyQueue* obj){if(obj ==0)return false;if(Empty(obj))return false;if(obj->mHead == obj->mTail){
    17.           obj->mTail  =-1;
    18.           obj->mHead  =-1;return true;}
    19.       obj->mHead =(obj->mHead +1)% obj->mSize;return true;}//浠庨槦鍒楀ご閮ㄨ幏鍙栧厓绱狅紝濡傛灉闃熷垪鏄┖锛岃繑鍥-1intFront(MyQueue* obj){if(obj ==0)return-1;if(Empty(obj))return-1;return obj->data[obj->mHead];}//浠庨槦鍒楀熬閮ㄨ幏鍙栧厓绱狅紝濡傛灉闃熷垪涓虹┖锛岃繑鍥-1intRear(MyQueue* obj){if(obj ==0)return-1;if(Empty(obj))return-1;return obj->data[obj->mTail];}//妫娴嬮槦鍒楁槸鍚﹀凡绌
    20. bool Empty(MyQueue* obj){if(obj==0)return false;if((obj->mHead ==-1)&&(obj->mTail ==-1))return true;return false;}//妫娴嬮槦鍒楁槸鍚﹀凡婊
    21. bool Full(MyQueue* obj){if(obj==0)return false;if((obj->mHead ==((obj->mTail +1)%obj->mSize))&&(obj->mHead !=-1))return true;return false;}//:閿姣侀槦鍒梫oidDestroy(MyQueue* obj){if(obj==0)return;if(obj->data !=0)free(obj->data);if(obj !=0)free(obj);}
    澶嶅埗浠g爜
    Codesys 瀹炵幇

      缂栫▼杞欢锛 Codesys V3.5 SP17杩愯璁惧锛歅C鐢佃剳缂栫▼璇█锛 ST 鎺屾彙濡備綍鍒涘缓鍔ㄦ佹暟缁New鐨勪娇鐢紱浠ュ強鎸囬拡鐨勭伒娲讳娇鐢
    瀹氫箟缁撴瀯浣
    1. //闃熷垪鎿嶄綔鐨勬暟鎹
    2. TYPE QueueElement :
    3. STRUCT
    4.         pData : POINTER TO BaseElement;//鏁扮粍鎸囬拡
    5.         mHead : INT;//澶撮儴绱㈠紩
    6.         mTail : INT;//灏鹃儴绱㈠紩
    7.         mSize : INT;//鏁扮粍澶у皬
    8. END_STRUCT
    9. END_TYPE
    澶嶅埗浠g爜
    鍏朵腑 BaseElement 鏄竴涓埆鍚嶏紝鍏跺畾涔夊涓嬶紝杩欓噷BaseElement 鏄敤鎴疯嚜瀹氫箟鏁版嵁(姣斿缁撴瀯浣)锛岄噰鐢ㄥ埆鍚嶆槸鏂逛究鏇挎崲銆
    1. TYPE BaseElement : INT; END_TYPE
    澶嶅埗浠g爜
    瀹氫箟鍔熻兘鍧 CircularQueue锛屽疄鐜板涓嬪嚱鏁
      Create(k):鏋勯犲櫒锛屽姩鎬佸垱寤篕澶у皬鐨勬暟缁Push(value) : 鍚戝惊鐜槦鍒椾腑鎻掑叆涓涓厓绱狅紝鎴愬姛杩斿洖truePop():浠庡惊鐜槦鍒椾腑鍒犻櫎涓涓厓绱狅紝鎴愬姛杩斿洖trueFront():浠庨槦鍒楀ご閮ㄨ幏鍙栧厓绱狅紝濡傛灉闃熷垪鏄┖锛岃繑鍥-1Rear():浠庨槦鍒楀熬閮ㄨ幏鍙栧厓绱狅紝濡傛灉闃熷垪涓虹┖锛岃繑鍥-1Empty(): 妫娴嬮槦鍒楁槸鍚︿负绌Full() : 妫娴嬮槦鍒楁槸鍚﹀凡婊Destroy:閿姣侀槦鍒Size:鑾峰彇闃熷垪鏁扮粍澶у皬
    绀轰緥濡備笅
    1. PROGRAM PLC_PRG
    2. VAR
    3.         myCircularQueue : CircularQueue;
    4. END_VAR
    5. VAR
    6.         bInit :BOOL:= FALSE;
    7.         isize : INT;
    8.         ivar1: ARRAY[0..10] OF BaseElement;
    9. END_VAR
    澶嶅埗浠g爜
    1. IF bInit = FALSE THEN
    2. bInit := TRUE;
    3. myCircularQueue.Create(10);//鍔ㄦ佸垱寤烘暟缁 澶у皬浣10
    4. isize := myCircularQueue.Size();//鑾峰緱闃熷垪鏁扮粍澶у皬 涓10
    5. myCircularQueue.Push(11);//鍏ラ槦 锛岃繑鍥濼RUE
    6. myCircularQueue.Push(22);//鍏ラ槦 锛岃繑鍥濼RUE
    7. myCircularQueue.Push(33);//鍏ラ槦 锛岃繑鍥濼RUE
    8. myCircularQueue.Push(44);//鍏ラ槦 锛岃繑鍥濼RUE
    9. ivar1[0]:= myCircularQueue.Front();//杩斿洖11
    10. myCircularQueue.Pop();//浠庡惊鐜槦鍒椾腑鍒犻櫎涓涓厓绱狅紝鎴愬姛杩斿洖true
    11. ivar1[1]:= myCircularQueue.Front();//杩斿洖22
    12. END_IF
    澶嶅埗浠g爜
    鍩轰簬Codesys鐢⊿T璇█瀹炵幇寰幆闃熷垪FIFO鏁版嵁缁撴瀯璇︾粏璇存槑+浠g爜瀹炰緥-4.jpg


    鍥涖 Codesys浠g爜涓嬭浇
    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒
    鍥炲

    浣跨敤閬撳叿 涓炬姤

    鎮ㄩ渶瑕佺櫥褰曞悗鎵嶅彲浠ュ洖甯 鐧诲綍 | 绔嬪嵆娉ㄥ唽 鏂版氮寰崥鐧婚檰

    鏈増绉垎瑙勫垯

    椤堕儴qrcode搴曢儴
    鍏虫敞閰峰痉缃戣闃呭彿锛岃幏鍙栨洿澶氳祫璁紒

    QQ|灏忛粦灞|鎵嬫満鐗|Archiver|閰峰痉璁哄潧 ( 鑻廔CP澶16065247鍙-1 )|缃戠珯鍦板浘

    GMT+8, 2024-11-23 19:51 , Processed in 0.153137 second(s), 60 queries .

    閰峰痉缃

    © 2001-2013 Hicodesys. 鎶鏈敮鎸 by 閰峰痉缃

    蹇熷洖澶 杩斿洖椤堕儴 杩斿洖鍒楄〃