tgs0910
|
分享:
▼
大大不好意思 在请教一下可不可以说的清楚一点 我比较喜欢用下面的程式:
; /* Table of CRC values for high-order byte */ auchCRCHi equ $ db 00h, C1h, 81h, 40h, 01h, C0h, 80h, 41h, 01h, C0h db 80h, 41h, 00h, C1h, 81h, 40h, 01h, C0h, 80h, 41h db 00h, C1h, 81h, 40h, 00h, C1h, 81h, 40h, 01h, C0h db 80h, 41h, 01h, C0h, 80h, 41h, 00h, C1h, 81h, 40h db 00h, C1h, 81h, 40h, 01h, C0h, 80h, 41h, 00h, C1h db 81h, 40h, 01h, C0h, 80h, 41h, 01h, C0h, 80h, 41h db 00h, C1h, 81h, 40h, 01h, C0h, 80h, 41h, 00h, C1h db 81h, 40h, 00h, C1h, 81h, 40h, 01h, C0h, 80h, 41h db 00h, C1h, 81h, 40h, 01h, C0h, 80h, 41h, 01h, C0h db 80h, 41h, 00h, C1h, 81h, 40h, 00h, C1h, 81h, 40h db 01h, C0h, 80h, 41h, 01h, C0h, 80h, 41h, 00h, C1h db 81h, 40h, 01h, C0h, 80h, 41h, 00h, C1h, 81h, 40h db 00h, C1h, 81h, 40h, 01h, C0h, 80h, 41h, 01h, C0h db 80h, 41h, 00h, C1h, 81h, 40h, 00h, C1h, 81h, 40h db 01h, C0h, 80h, 41h, 00h, C1h, 81h, 40h, 01h, C0h db 80h, 41h, 01h, C0h, 80h, 41h, 00h, C1h, 81h, 40h db 00h, C1h, 81h, 40h, 01h, C0h, 80h, 41h, 01h, C0h db 80h, 41h, 00h, C1h, 81h, 40h, 01h, C0h, 80h, 41h db 00h, C1h, 81h, 40h, 00h, C1h, 81h, 40h, 01h, C0h db 80h, 41h, 00h, C1h, 81h, 40h, 01h, C0h, 80h, 41h db 01h, C0h, 80h, 41h, 00h, C1h, 81h, 40h, 01h, C0h db 80h, 41h, 00h, C1h, 81h, 40h, 00h, C1h, 81h, 40h db 01h, C0h, 80h, 41h, 01h, C0h, 80h, 41h, 00h, C1h db 81h, 40h, 00h, C1h, 81h, 40h, 01h, C0h, 80h, 41h db 00h, C1h, 81h, 40h, 01h, C0h, 80h, 41h, 01h, C0h db 80h, 41h, 00h, C1h, 81h, 40h
; /* Table of CRC values for low-order byte */ auchCRCLo equ $ db 00h, C0h, C1h, 01h, C3h, 03h, 02h, C2h, C6h, 06h db 07h, C7h, 05h, C5h, C4h, 04h, CCh, 0Ch, 0Dh, CDh db 0Fh, CFh, CEh, 0Eh, 0Ah, CAh, CBh, 0Bh, C9h, 09h db 08h, C8h, D8h, 18h, 19h, D9h, 1Bh, DBh, DAh, 1Ah db 1Eh, DEh, DFh, 1Fh, DDh, 1Dh, 1Ch, DCh, 14h, D4h db D5h, 15h, D7h, 17h, 16h, D6h, D2h, 12h, 13h, D3h db 11h, D1h, D0h, 10h, F0h, 30h, 31h, F1h, 33h, F3h db F2h, 32h, 36h, F6h, F7h, 37h, F5h, 35h, 34h, F4h db 3Ch, FCh, FDh, 3Dh, FFh, 3Fh, 3Eh, FEh, FAh, 3Ah db 3Bh, FBh, 39h, F9h, F8h, 38h, 28h, E8h, E9h, 29h db EBh, 2Bh, 2Ah, EAh, EEh, 2Eh, 2Fh, EFh, 2Dh, EDh db ECh, 2Ch, E4h, 24h, 25h, E5h, 27h, E7h, E6h, 26h db 22h, E2h, E3h, 23h, E1h, 21h, 20h, E0h, A0h, 60h db 61h, A1h, 63h, A3h, A2h, 62h, 66h, A6h, A7h, 67h db A5h, 65h, 64h, A4h, 6Ch, ACh, ADh, 6Dh, AFh, 6Fh db 6Eh, AEh, AAh, 6Ah, 6Bh, ABh, 69h, A9h, A8h, 68h db 78h, B8h, B9h, 79h, BBh, 7Bh, 7Ah, BAh, BEh, 7Eh db 7Fh, BFh, 7Dh, BDh, BCh, 7Ch, B4h, 74h, 75h, B5h db 77h, B7h, B6h, 76h, 72h, B2h, B3h, 73h, B1h, 71h db 70h, B0h, 50h, 90h, 91h, 51h, 93h, 53h, 52h, 92h db 96h, 56h, 57h, 97h, 55h, 95h, 94h, 54h, 9Ch, 5Ch db 5Dh, 9Dh, 5Fh, 9Fh, 9Eh, 5Eh, 5Ah, 9Ah, 9Bh, 5Bh db 99h, 59h, 58h, 98h, 88h, 48h, 49h, 89h, 4Bh, 8Bh db 8Ah, 4Ah, 4Eh, 8Eh, 8Fh, 4Fh, 8Dh, 4Dh, 4Ch, 8Ch db 44h, 84h, 85h, 45h, 87h, 47h, 46h, 86h, 82h, 42h db 43h, 83h, 41h, 81h, 80h, 40h
CRC16: xrl a, uchCRCHi ; uIndex = uchCRCHi ^ *puchMsg++; mov r7, a mov dptr, #auchCRCHi movc a, @a+dptr xrl a, uchCRCLo mov uchCRCHi, a ; uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex]; mov dptr, #auchCRCLo mov a, r7 movc a, @a+dptr mov uchCRCLo, a ; uchCRCLo = auchCRCLo[uIndex]; ret
SendReadHolding: mov uchCRCHi, #0FFh mov uchCRCLo, #0FFh ; mov a, #01h ; Address call SendChar call CRC16 mov a, #03h ; Function Code = 03 (Read Holding Registers) call SendChar call CRC16 ; mov a, #00h call SendChar call CRC16 mov a, #00h ; Register Address 0000h call SendChar call CRC16 ; mov a, #00h call SendChar call CRC16 mov a, #01h ; Regisetr Count 0001h call SendChar call CRC16 ; mov a, uchCRCHi call SendChar mov a, uchCRCLo call SendChar ret 小弟太笨了实在是看不懂
我要如何把收到的串列资料丢到 20H -N H 假如我连续收到30H,31H,32H, 就把30H丢到20H的位址里 31H 21H 32H 22H 如果是30H-35H 就把30H 20H 31H 21H 32H 22H 33H 23H 34H 24H 35H 25H 然后把20H-25H位址做CRC16的判断 然后将CRC16的数值HI丢到R5 LO R6里 希望大大帮帮小弟 谢谢
|