| поискавой системы для электроныых деталей |
|
CS4210 датащи(PDF) 32 Page - National Semiconductor (TI) |
|
|
|
|||||||||||||||||||||||||||||
CS4210 датащи(HTML) 32 Page - National Semiconductor (TI) |
|
32 / 102 page ![]() www.national.com 32 Revision 1.0 Operational Description (Continued) Figure 3-1. CRC1 and CRC2 Sample Code ff ff ff ff ff ff ff ff -> CRC1 = feh, CRC2 = 70h 01 23 45 67 89 ab cd ef -> CRC1 = 19h, CRC2 = 07h 00 00 00 00 00 00 00 00 -> CRC1 = bfh, CRC2 = f4h #include <stdio.h> typedef unsigned char uchar_t; typedef unsigned short ushort_t; typedef unsigned long long_t; ushort_t calc_crc(ushort_t r, uchar_t d); ushort_t rev16(ushort_t src); /* main routine */ int main(int argc, char *argv[]) { ushort_t residual = 0xffff; int din; uchar_t byte; uchar_t crc1, crc2; while(scanf("%2x", &din ) != EOF ) { byte = din; printf("%2.2x ", byte); residual = calc_crc(residual, byte); }; printf("\n"); residual = rev16(residual); crc1 = ~(residual & 0x00ff); crc2 = ~(residual>>8); printf("CRC1 = %2.2hxh\n", crc1); printf("CRC2 = %2.2hxh\n", crc2); return(0); /* calc_crc - apply a byte of data to the 16-bit CRC */ } ushort_t calc_crc(ushort_t r, uchar_t d) { ushort_t bit_in; int i; for(i=0;i<8;i++) { bit_in = (d>>i) & 0x0001; if((r>>15) ^ bit_in) r = (((r<<1) & 0x7ffb) | ((r>>15 ^ ((r>>14)&0x0001) ^ bit_in) << 15) | ((r>>15 ^ ((r>>1)&0x0001) ^ bit_in) << 2) | 0x0001 ); else r<<= 1; } return(r); } ushort_t rev16(ushort_t src) { return( ((src&0x0001)<<15) | ((src&0x0002)<<13) | ((src&0x0004)<<11) | ((src&0x0008)<<9) | ((src&0x0010)<<7) | ((src&0x0020)<<5) | ((src&0x0040)<<3) | ((src&0x0080)<<1) | ((src&0x0100)>>1) | ((src&0x0200)>>3) | ((src&0x0400)>>5) | ((src&0x0800)>>7) | ((src&0x1000)>>9) | ((src&0x2000)>>11) | ((src&0x4000)>>13) | ((src&0x8000)>>15); } |
|
ссылки URL |
| Вашему бизинису помогли Аллдатащит? [ DONATE ] |
Что такое Аллдатащит | реклама | контакт | Конфиденциальность | Ссылка на техническое описание | обмен ссыками | поиск по производителю All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |