广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 5843 个阅读者
 
<< 上页  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.071667 second(s),query:16 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言