廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 5841 個閱讀者
 
<< 上頁  1   2  >>(共 2 頁)
發表文章 發表投票 回覆文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
tgs0910 手機
個人頭像
個人文章 個人相簿 個人日記 個人地圖
初露鋒芒
級別: 初露鋒芒 該用戶目前不上站
推文 x1 鮮花 x61
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

大大不好意思
在請教一下可不可以說的清楚一點
我比較喜歡用下面的程式:

; /* 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裡
希望大大幫幫小弟 謝謝



獻花 x0 回到頂端 [10 樓] From:臺灣 | Posted:2007-03-20 18:14 |
cmovies
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x20
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

CRC16:
xrl   a, r5       ; uIndex = uchCRCHi ^ *puchMsg++;
mov   r7, a
mov   dptr, #auchCRCHi
movc   a, @a+dptr
xrl   a, r6    
mov   r5, a       ; uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex];
mov   dptr, #auchCRCLo
mov   a, r7
movc   a, @a+dptr
mov   r6, a       ; uchCRCLo = auchCRCLo[uIndex];
ret

MOV R5, #0FFH
MOV R6, #0FFH
MOV A, 20H
CALL CRC16
MOV A, 21H
CALL CRC16
MOV A, 22H
CALL CRC16
MOV A, 23H
CALL CRC16
MOV A, 24H
CALL CRC16
MOV A, 25H
CALL CRC16
; R5, R6 就是你要的 CRC16 HI, LO

因為不曉的你的接收怎麼寫的, 我先假設收到5 bytes


獻花 x0 回到頂端 [11 樓] From:臺灣中華HiNet | Posted:2007-03-21 03:12 |

<< 上頁  1   2  >>(共 2 頁)
首頁  發表文章 發表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.077588 second(s),query:16 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言