Sie sind auf Seite 1von 7

CAC HAM TH VIEN Th vien chuan cua phan mem Step 7 gom cac ham he thong SFC, khoi

ham he thong SFB, cac ham FC va khoi ham FB, giup cho viec lap trnh thuan tien bi cac ham viet san. Ngoai ra con co cac ham to chc OB hoat ong khi khi ong PLC, lam viec theo chu ky. Chung ta co the bo sung cac ham khac vao th vien cua Step 7 mot cach de dang. Cac ham th vien c them vao mot iem trong khoi chng trnh bang cach vao menu Insert- Program Elements Libraries, sau o lan lt vao cac muc con trong o, chon ham phu hp roi bam chuot phai chon paste

Phan sau gii thieu chi tiet mot so ham. 1/ Cac ham trong th vien TI-S7 Converting blocks 1.1/ Cac ham x ly bit a/ at mot loat bit: FC83

Khi I0.0 = 1, 10 bit t M0.0 en M1.1 len 1. Neu ham thc hien ung ENO va Q4.0 bang 1. a ch bit au tien S_bit dung con tro P#, tro en vung nh bit (I, Q, M, D), so bit N la hang so hay I, Q, M, D, L, P
A JNB CALL S_BIT:= N := _001: A = I0.0 _001 "SET" 10 BR Q4.0 P#M 0.0

b/ at mot loat byte lap tc : FC101

Khi I0.0 = 1, hai byte t PB2 se len 1 (P#P2.0 tro en bit P2.0), so N la so byte can at len 1 nhan 8. c/ Xoa mot loat bit: FC82

d) Xoa mot loat bit lap tc : FC100

1.2/ Ham di chuyen khoi gian tiep : FC81 Di chuyen mot khoi d lieu byte, word hay word kep t khoi nguon co a ch au gian tiep S_DATA chieu dai LENGTH en khoi ch co a ch au gian tiep D_DATA, ba thong so nay dung bien con tro P#. Thong so E_TYPE cho biet loai d lieu theo qui nh sau: B#16#02 = BYTE, B#16#04 = WORD, B#16#05 = INT, B#16#06 = DWORD,
B#16#07 = DINT, B#16#08 = REAL

Trc lenh: S_DATA DBX0.0 = P#DB1.DBX50.0 // a ch au khoi nguon la DBW50 DBW50 = W#16#2424 DBW52 = W#16#2525 LENGTH DBW10 = W#16#0002 // Khoi d lieu hai word D_DATA DBX20.0= P#DB2.DBX10.0 // D9a ch au khoi ch la DBW10 DBW10 = W#16#0000

DBW12 = W#16#0000 Sau lenh : D_DATA DBW10 = W#16#2424 DBW12 = W#16#2525

1.3/ Ham chuyen oi a/ Giai ma 7 oan: FC93 oi mot word hexa 4 digit IN (I,M,D,P, hang so) ra 4 byte ma 7 oan cua tng digit, xuat ra a ch OUT t kep (Q, M, D, L, P)

I 0.0 JNB _001 CALL "SEG" IN :=W#16#1234 OUT:=MD0 _001: NOP 0

b/ oi ASCII sang HEX oi chuoi ASCII dai N ky t (I, Q, M, L, P) gom cac ky t A..F, so 0..9 , moi ky t chiem 2 byte a ch con tro IN ( I, Q, M,D,L) ra so Hex tng ng, mot byte ng vi hai ky t a ch con tro OUT (Q, M, D, L) . RET_VAL la word tra ve ket qua thc hien (I, Q, M, D, L, P) W#16#0000 neu ung.

c/ oi HEX sang ASCII: FC95

d/ Ham oi tam SCALE : FC105 Chuyen oi so nguyen IN (I, Q, M, D, L, P, Hang so) ra so thc OUT (I, Q, M, D, L, P) trong khoang LO_LIM va HI_LIM theo cong thc OUT = [ ((FLOAT (IN) K1)/(K2K1)) * (HI_LIM LO_LIM) ] + LO_LIM HI_LIM, LO_LIM la cac gia tr thc (I, Q, M, D, L, P, Hang so) K1, K2 tuy thuoc trang thai ngo ieu khien BIPOLAR BIPOLAR=1: so IN la lng cc, K1 = 27648.0, K2 = +27648.0 BIPOLAR=0: so IN la n cc, K1 = 0.0, K2 = +27648.0

e/ Ham oi tam ngc UNSCALE : FC106 Chuyen oi so thc IN gia hai gia tr LO_LIM va HI_LIM thanh so nguyen n cc hay lng cc OUT theo cong thc OUT = [ ((INLO_LIM)/(HI_LIMLO_LIM)) * (K2K1) ] + K1

f/ Bo chnh sm- tre pha: FB90 Thc hien phep hieu chnh sm tre pha tren tn hieu vao IN, o li GAIN, thi gian sm pha LG_TIME, thi gian tre pha LG_TIME, chu ky lay mau SAMPLE_T va cho ra tn hieu OUT

Instance DB80 LD_TIME DBD12 = 2.0 LG_TIME DBD16 = 2.0 GAIN DBD20 = 1.0 PREV_IN DBD24 = 6.0 PREV_OUT DBD28 = 6.0 Before execution: IN MD10 = 2.0 OUT MD20 = 0.0

After execution: Instance DB80 PREV_IN DBD24 = 2.0 PREV_OUT DBD28 = 2.0 OUT MD20 = 2.0

2/ CAC HAM IEC (International Electrotechnical Commission) 2.1/ Ham thi gian FC1 AD_DT_TM Cong bien DT va TIME FC3 D_TOD_DT Ket hp DATE va TIME_OF_DAY thanh DT FC6 DT_DATE Rut ra DATE t DT FC7 DT_DAY Rut ra ngay trong tuan t DT FC8 DT_TOD Rut ra TIME_OF_DAY t DT FC9 EQ_DT DT So sanh bang hai DT FC12 GE_DT DT So sanh ln hn hay bang hai DT FC14 GT_DT DT So sanh ln hn hai DT FC18 LE_DT DT So sanh nho hn hay bang hai DT FC23 LT_DT DT So sanh nho hn hai DT FC28 NE_DT DT So sanh khong bang hai DT FC33 S5TI_TIM oi S5TIME ra TIME FC34 SB_DT_DT Tr hai bien DT FC35 SB_DT_TM Tr DT va TIME FC40 TIM_S5TI oi TIME ra S5TIME a/ Ham FC3: Ket hp ngay thang nam (DATE) bien IN1 (I, Q, M, D, Hang) vi gi trong ngay (TIME OF DAY) bien IN2 (I, Q, M, D, L, Hang) thanh bien RET_VAL loai DT (bien ky hieu). Bien IN1 trong khoang DATE# 1990-01-01 va DATE#2089-12-31. V du: Bang khai bao bien trong local block cua chng trnh goi Name Type Declarati Comment on IN_TIME TIME_OF_DAY TEMP Start time IN_DATE DATE TEMP Start date OUT_TIME_DATE DATE_AND_TIME TEMP Start date/time converted
Network 2 L D#2006127 T #IN_DATE L TOD#20:0:0.0 T #IN_TIME Network 3: CALL FC 3 IN1 := #IN_DATE IN2 := #IN_TIME RET_VAL := #OUT_TIME_DATE

b/ Ham FC1 Cong gi IN1 dang DT (bien ky hieu ) vi khoang thi gian IN2 dang TIME, RET_VAL la bien ky hieu dang DT. 2.2/oi so ra chuoi va ngc lai

FC5 FC16 FC30 FC37

DI_STRNG I_STRNG R_STRNG STRNG_DI

oi oi oi oi

DINT ra STRING INT ra STRING REAL ra STRING, STRING ra DINT, chuoi dai toi a 11 so

FC38 STRNG_I oi STRING ra INT, chuoi dai toi a 6 so FC39 STRNG_R oi STRING ra REAL, chuoi co dang v.nnnnnnnExx 2.3/ So sanh Chuoi FC10 EQ_STRNG FC13 GE_STRNG FC15 GT_STRNG FC19 LE_STRNG FC24 LT_STRNG FC29 NE_STRNG 2.4/ Lenh x ly chuoi FC2 CONCAT Ket hp hai chuoi FC4 DELETE Bo mot chuoi FC11 FIND Tm mot chuoi FC17 INSERT Xen mot chuoi FC20 LEFT Tach chuoi ben trai FC21 LEN Tnh chieu dai bien STRING FC26 MID Tach oan gia FC31 REPLACE Thay mot chuoi FC32 RIGHT Tach chuoi ben phai 2.5/ Lenh so thc FC22 LIMIT Tao ham gii han bien vao gia hai tr MN va MX FC25 MAX Chon gia tr ln nhat gia ba bien vao FC27 MIN Chon gia tr nho nhat gia ba bien vao FC36 SEL Chon mot trong hai ngo vao tuy bien ieu khien 3/ Ham he thong SFC x ly khoi