版權(quán)屬作者所有,不可作為商業(yè)用途。轉(zhuǎn)載注明出處。謝謝合作。 FUNCTION_BLOCK FB100 TITLE ='CRC_16' AUTHOR : GXW FAMILY : CRC NAME : CRC VERSION : '1.0' VAR_INPUT DB_NO : BLOCK_DB; //Number of the data block which is checked by CRC START_ADR : INT; //start address the checked data DATA_LEN : INT; //how long the checked data whih byte END_VAR VAR_OUTPUT CRC_HI : BYTE; CRC_LO : BYTE; END_VAR VAR Lab_CRCHI_0 : ARRAY [0..127] OF INT := B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41; Lab_CRCHI_1 : ARRAY [0..127] OF INT := B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#01, B#16#C0, B#16#80, B#16#41, B#16#00, B#16#C1, B#16#81, B#16#40; Lab_CRCLO_0 : ARRAY [0..127] OF INT := B#16#00, B#16#C0, B#16#C1, B#16#01, B#16#C3, B#16#03, B#16#02, B#16#C2, B#16#C6, B#16#06, B#16#07, B#16#C7, B#16#05, B#16#C5, B#16#C4, B#16#04, B#16#CC, B#16#0C, B#16#0D, B#16#CD, B#16#0F, B#16#CF, B#16#CE, B#16#0E, B#16#0A, B#16#CA, B#16#CB, B#16#0B, B#16#C9, B#16#09, B#16#08, B#16#C8, B#16#D8, B#16#18, B#16#19, B#16#D9, B#16#1B, B#16#DB, B#16#DA, B#16#1A, B#16#1E, B#16#DE, B#16#DF, B#16#1F, B#16#DD, B#16#1D, B#16#1C, B#16#DC, B#16#14, B#16#D4, B#16#D5, B#16#15, B#16#D7, B#16#17, B#16#16, B#16#D6, B#16#D2, B#16#12, B#16#13, B#16#D3, B#16#11, B#16#D1, B#16#D0, B#16#10, B#16#F0, B#16#30, B#16#31, B#16#F1, B#16#33, B#16#F3, B#16#F2, B#16#32, B#16#36, B#16#F6, B#16#F7, B#16#37, B#16#F5, B#16#35, B#16#34, B#16#F4, B#16#3C, B#16#FC, B#16#FD, B#16#3D, B#16#FF, B#16#3F, B#16#3E, B#16#FE, B#16#FA, B#16#3A, B#16#3B, B#16#FB, B#16#39, B#16#F9, B#16#F8, B#16#38, B#16#28, B#16#E8, B#16#E9, B#16#29, B#16#EB, B#16#2B, B#16#2A, B#16#EA, B#16#EE, B#16#2E, B#16#2F, B#16#EF, B#16#2D, B#16#ED, B#16#EC, B#16#2C, B#16#E4, B#16#24, B#16#25, B#16#E5, B#16#27, B#16#E7, B#16#E6, B#16#26, B#16#22, B#16#E2, B#16#E3, B#16#23, B#16#E1, B#16#21, B#16#20, B#16#E0; Lab_CRCLO_1 : ARRAY [0..127] OF INT := B#16#A0, B#16#60, B#16#61, B#16#A1, B#16#63, B#16#A3, B#16#A2, B#16#62, B#16#66, B#16#A6, B#16#A7, B#16#67, B#16#A5, B#16#65, B#16#64, B#16#A4, B#16#6C, B#16#AC, B#16#AD, B#16#6D, B#16#AF, B#16#6F, B#16#6E, B#16#AE, B#16#AA, B#16#6A, B#16#6B, B#16#AB, B#16#69, B#16#A9, B#16#A8, B#16#68, B#16#78, B#16#B8, B#16#B9, B#16#79, B#16#BB, B#16#7B, B#16#7A, B#16#BA, B#16#BE, B#16#7E, B#16#7F, B#16#BF, B#16#7D, B#16#BD, B#16#BC, B#16#7C, B#16#B4, B#16#74, B#16#75, B#16#B5, B#16#77, B#16#B7, B#16#B6, B#16#76, B#16#72, B#16#B2, B#16#B3, B#16#73, B#16#B1, B#16#71, B#16#70, B#16#B0, B#16#50, B#16#90, B#16#91, B#16#51, B#16#93, B#16#53, B#16#52, B#16#92, B#16#96, B#16#56, B#16#57, B#16#97, B#16#55, B#16#95, B#16#94, B#16#54, B#16#9C, B#16#5C, B#16#5D, B#16#9D, B#16#5F, B#16#9F, B#16#9E, B#16#5E, B#16#5A, B#16#9A, B#16#9B, B#16#5B, B#16#99, B#16#59, B#16#58, B#16#98, B#16#88, B#16#48, B#16#49, B#16#89, B#16#4B, B#16#8B, B#16#8A, B#16#4A, B#16#4E, B#16#8E, B#16#8F, B#16#4F, B#16#8D, B#16#4D, B#16#4C, B#16#8C, B#16#44, B#16#84, B#16#85, B#16#45, B#16#87, B#16#47, B#16#46, B#16#86, B#16#82, B#16#42, B#16#43, B#16#83, B#16#41, B#16#81, B#16#80, B#16#40; END_VAR VAR_TEMP uchCRCHi : BYTE; /// 高CRC字節(jié) uchCRCLo : BYTE; /// 低CRC字節(jié) uIndex : INT; /// CRC表索引 CArray : INT; /// END_VAR BEGIN uchCRCHi := B#16#FF; /// 高CRC字節(jié) uchCRCLo := B#16#FF; /// 低CRC字節(jié) FOR CArray := 0 TO DATA_LEN - 1 BY 1 DO uIndex := BYTE_TO_INT(uchCRCHi XOR DB_NO.DB[START_ADR + CArray]); // 計算CRC IF uIndex >=128 THEN uchCRCHi := uchCRCLo XOR INT_TO_BYTE (Lab_CRCHI_1[uIndex - 128]); uchCRCLo := INT_TO_BYTE (Lab_CRCLO_1[uIndex - 128]); ELSE uchCRCHi := uchCRCLo XOR INT_TO_BYTE (Lab_CRCHI_0[uIndex]); uchCRCLo := INT_TO_BYTE (Lab_CRCLO_0[uIndex]); END_IF; END_FOR; CRC_HI := uchCRCHi; CRC_LO := uchCRCLo; END_FUNCTION_BLOCK OB1中調(diào)用FB100: DB8002: |
|