Hola camaradas, bueno estoy adaptando el codigo del CCR16 corregido en
http://www.joegeluso.com/ para que corra en VB
pero tengo problemas
intro el mensaje y toda la vida me devuelve le valor de inicio de CRC=&HFFFF&
Vean el codigo.
Const poly = &H1021&
Public CRC As Long
Dim lentext As Integer
Dim sMessage As String
Sub Form_Load()
InitFunctionsShift
Dim icrc As Long
sMessage = "A"
icrc = hacer
Debug.Print "crc16(" & sMessage & ")=" & Hex(icrc)
End Sub
Private Function hacer() As Long
Dim i As Integer
Dim ch As Integer
CRC = &HFFFF&
lentext = 0
For i = 1 To Len(sMessage)
ch = Asc(Mid$(sMessage, i, 1))
crc_bueno ch
lentext = lentext + 1
Next i
CRC = restante_crc
hacer = CRC
End Function
Sub crc_bueno(ch As Integer)
Dim i As Integer
Dim v As Integer
Dim flag As Byte
v = &H80&
For i = 0 To i < 8
If (CRC And &H8000&) Then
flag = 1
Else
flag = 0
End If
CRC = ShiftLeft(CRC, 1)
If (ch And v) Then
CRC = CRC + 1
End If
If flag Then
CRC = CRC Xor poly
End If
v = ShiftRight(v, 1)
Next i
End Sub
Function restante_crc() As Long
Dim i As Integer
Dim flag As Byte
For i = 0 To i < 16
If (CRC And &H8000&) Then
flag = 1
Else
flag = 0
End If
CRC = ShiftLeft(CRC, 1)
If flag Then
CRC = CRC Xor poly
End If
Next i
restante_crc = CRC
End Function
Por favor veanlo, comentenlo y corrijanlo.