⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 embedded small table crc16 routines.htm

📁 CRC16的源程序
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0068)http://www.digitalnemesis.com/ash/projects/EmbeddedCRC16/default.htm -->
<HTML><HEAD><TITLE>Embedded Small Table CRC16 Routines</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff><BASEFONT face="Verdana, Arial, Helvetica">
<CENTER>
<H2>Embedded Small Table CRC16 Routines</H2>
<H3>By Ashley Roll</H3>
<P>14 May 2002.</P></CENTER>
<P>To generate a CRC16 value efficiently, one needs to use a table driven 
algorithm. The generation of these tables fairly simple but the code is often 
hard to find and is almost always designed for generating a 256 entry table for 
operating on 8 bits at a time.</P>
<P>In Embedded Systems there are often severe space limitations and a full table 
of 256 16 bit entries would never fit. However the CRC16 algorithm does not 
require such a large table to work. It can be done smaller. On the PIC micro 
processors, a nibble (4 bit) implementation can be achieved fairly easily and 
this requres only a table of 16 16-bit values or 32 bytes.</P>
<P>This code was developed from the explanations and examples at <A 
href="http://www.geocities.com/SiliconValley/Pines/8659/crc.htm">http://www.geocities.com/SiliconValley/Pines/8659/crc.htm</A> 
This is a good reference for those wanting to understand what is happening in 
the CRC algorithm.</P>
<P>The <A 
href="http://www.digitalnemesis.com/ash/projects/EmbeddedCRC16/ex4bit.c">ex4bit.c</A> 
file contains an implementation of the CCITT CRC16 which processes the message 
data in 4-bit chunks. This sould be easily portable to any processor. I didn't 
optimise the code to allow easier understanding of what it is doing. This code 
allows a very small 16 element table to be used. Note that the lookup value is 
actually a 16-bit number and most small embedded processors are only able to 
deal with an 8-bit table lookup so I've split the data accross two tables.</P>
<P>A PIC Assmebler implementation, <A 
href="http://www.digitalnemesis.com/ash/projects/EmbeddedCRC16/piccrc.asm">piccrc.asm</A> 
can also be found. This is the version containing some optimisation from Scott 
Dattalo. This results in 74 instruction cycles to update the CRC registers for 
each byte of message data. The two lookup tables are merged into one larger one. 
It can probably be optimised further (Scott suggested some other optimisations, 
but they make the code much harder to understand). This code was written to work 
on a PIC12C508 and so should be portable to any PIC processor. The original 
version (85 instructions) can be found in <A 
href="http://www.digitalnemesis.com/ash/projects/EmbeddedCRC16/piccrcorig.asm">piccrcorig.asm</A>.</P>
<P>To see how the lookup table was generated, please refer to the <A 
href="http://www.digitalnemesis.com/ash/projects/EmbeddedCRC16/gentable.c">gentable.c</A> 
file. This is a simple C program to generate the tables for a given 
polynomial.</P>
<HR>

<P>I haven't verified that the actual CRC16 value is correct yet as I don't have 
any other implementations to refer too. The example code above uses the CCITT 
standard polynomial 0x1021 and initialises the CRC register to 0xFFFF, also as 
specified in the CCITT standard.</P>
<P>If anyone has some test vectors that I can try with the resulting CRC value 
I'd appreciate if you would send them to me.</P>Ashley Roll <!-- disguise email address --><A 
href="mailto:ash@digitalnemesis.com">ash@digitalnemesis.com</A> 
</BASEFONT></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -