Hi,
This compiles (to 122 words for a 16F628) but I've got no hardware to try it out, "should" work though ;-)
Code:
Diag VAR BYTE[5] ' Array for complete message
DTC_High VAR Byte ' Upper byte of message
DTC_Low VAR Byte ' Lower byte of message
i VAR BYTE ' General purpose
'Get the top two bits of the high byte and shift it down so
'it becomes 0-3. Then convert to the correct character.
i = (DTC_High & %11000000) >> 6 ' Temp now 0-3 (borrow Diag[1] for this op)
Lookup i, [32,19,18,37], Diag[0]
' Now extract the next four "digits" in the same way.
Diag[1] = DTC_High & %00110000 ' Isolate bits 4,5
Diag[1] = Diag[1] >> 4 ' Shift down to bits 0,1
Diag[2] = DTC_High & %00001111 ' Isolate bits 0-3
Diag[3] = DTC_Low & %11110000 ' Isolate upper four bits
Diag[3] = Diag[3] >> 4 ' Shift down
Diag[4] = DTC_Low & %00001111 ' Isolate lower four bits
' Now, if Diag[0] is 32 we add 48 to it and it becomes 80 which
' is the ASCII code for "U". If Diag[1] is 2 we add 48 to that
' so it becomes 50 which is the ASCII code for "2" and so on.
HSEROUT["Error code: "]
For i = 0 to 4
HSEROUT[Diag[i] + 48]
Next
/Henrik.
Bookmarks