Hardware
Utilizando la misma arquitectura de hardware desarrollado para el brico anterior, y tras las modificaciones necesarias en el
software, s
e ha desarrollado
un interfase básico para establecer comunicación con la ECU.
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "CAN Diagnosis (ISO15765)"
ClientHeight = 7800
ClientLeft = 45
ClientTop = 330
ClientWidth = 6345
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 7800
ScaleWidth = 6345
StartUpPosition = 3 'Windows Default
Begin VB.TextBox Text2
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H0000FFFF&
Height = 195
Left = 2400
MaxLength = 1
TabIndex = 9
Text = "2"
Top = 720
Width = 495
End
Begin VB.TextBox Text5
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H0000FFFF&
Height = 195
Left = 3840
MaxLength = 2
TabIndex = 6
Text = "00"
Top = 720
Width = 495
End
Begin VB.TextBox Text4
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H0000FFFF&
Height = 195
Left = 3120
MaxLength = 1
TabIndex = 5
Text = "1"
Top = 720
Width = 495
End
Begin VB.CommandButton Command6
Caption = "Enviar"
Enabled = 0 'False
Height = 375
Left = 4800
TabIndex = 4
Top = 540
Width = 1095
End
Begin VB.CommandButton Command3
Caption = "Borrar"
Height = 375
Left = 120
TabIndex = 3
Top = 1440
Width = 1095
End
Begin VB.CommandButton Command2
Caption = "Cerrar COM"
Enabled = 0 'False
Height = 375
Left = 120
TabIndex = 2
Top = 960
Width = 1095
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "Courier New"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 5580
Left = 1800
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 1
Top = 1800
Width = 4050
End
Begin VB.CommandButton Command1
Caption = "Abrir COM"
Height = 375
Left = 120
TabIndex = 0
Top = 480
Width = 1095
End
Begin MSCommLib.MSComm MSComm1
Left = 120
Top = 2160
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = 0 'False
InputLen = 1
RThreshold = 1
BaudRate = 115200
End
Begin VB.Label Label9
Caption = "Query:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1440
TabIndex = 14
Top = 120
Width = 615
End
Begin VB.Label Label8
Caption = "Response:"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1440
TabIndex = 13
Top = 1440
Width = 975
End
Begin VB.Shape Shape2
Height = 6015
Left = 1440
Top = 1560
Width = 4695
End
Begin VB.Shape Shape1
Height = 975
Left = 1440
Top = 240
Width = 4695
End
Begin VB.Label Label7
Caption = "ID"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1860
TabIndex = 12
Top = 480
Width = 375
End
Begin VB.Label Label3
Caption = "7DF"
Height = 255
Left = 1800
TabIndex = 11
Top = 720
Width = 375
End
Begin VB.Label Label2
Caption = "Nº datos"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 2250
TabIndex = 10
Top = 480
Width = 855
End
Begin VB.Label Label5
Caption = "PID"
Enabled = 0 'False
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 3930
TabIndex = 8
Top = 480
Width = 375
End
Begin VB.Label Label4
Caption = "MODE"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 3090
TabIndex = 7
Top = 480
Width = 645
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
MSComm1.PortOpen = True
Command1.Enabled = False
Command2.Enabled = True
Command6.Enabled = True
End Sub
Private Sub Command2_Click()
MSComm1.PortOpen = False
Command1.Enabled = True
Command2.Enabled = False
Command6.Enabled = False
End Sub
Private Sub Command3_Click()
Text1.Text = ""
End Sub
Private Sub Command6_Click()
MSComm1.Output = Text2.Text & Text4.Text & Left$(Text5.Text, 1)_
& Right$(Text5.Text, 1) & vbCr
End Sub
Private Sub MSComm1_OnComm()
Dim BUFUSART As String
Dim CabeceraID As String
If MSComm1.CommEvent = comEvReceive Then
BUFUSART = MSComm1.Input
Select Case Asc(BUFUSART)
Case 13 'Reconocimiento caracter "CR" (return).
Text1.SelStart = Len(Text1.Text)
Text1.SelText = CODIGO & vbCrLf
CODIGO = "" 'Limpiar buffer
Case 31 To 126 'Filtro de caracteres.
CODIGO = CODIGO & BUFUSART
End Select
End If
End Sub
Attribute VB_Name = "Module1"
Option Explicit
Public CODIGO As String
Software
La aplicación que usaremos para interactuar con el
vehículo es básicamente un “hiperterminal” con la opción
de introducir el comando de una manera sencilla.
Está desarrollada en Visual Basic 6.0 (ya ha llovido), que
utilizando un control de gestión de puertos RS232 y un
mínimo código, se encarga de enviar los datos necesarios
vía puerto serie para que el interfase lo empaquete en el
datagrama final y este sea enviado al vehículo.
Como comento, desde la aplicación solo se envía los
datos correspondiente a los controles que están en
amarillo, es decir, un digito para “Nº datos”, otro dígito
para “MODE” y dos últimos dígitos que corresponden al
valor “PID”.
Una vez recogida esta información por el interfase, se
encapsula dentro de la trama CAN donde quedan añadida
la cabecera ID el valor LEN (tamaño de paquete), etc
En el apartado “Response” se mostrará la recepción del
mensaje CAN previa conversión de binario a decimal en la
propia interfase. Una vez que recibe un CR (return) por
parte de la interfase se da por terminado en mensaje y se
muestra en su totalidad.
El funcionamiento es tan básico que apenas requiere
explicación. Pulsar “Abrir COM” para utilizar el puerto
serie COM1 y escribir el paquete CAN que se quiere
generar. Pulsar Enviar y la respuesta aparecerá en el
apartado “Query”.
Aparecerán dos signos de interrogación “??” para
indicarnos que el interfase está esperando a que le
enviemos un Query.
Código Visual Basic.
En la foto se puede ver lo reducido del sistema.
Data_D2:
movlw
d'32'
; Dejar separador.
call
TxUsart
; Tomar el Byte de Datos de RXB0D0 y convertirlo a ASCII.
movf
RXB0D1, W
call
HexAscii
; Convertir ambos nibles.
movlw
D'2'
; ¿Solo dos Datos?
cpfseq
FTempDA
bra
Data_D3
return
Data_D3:
movlw
d'32'
; Dejar separador.
call
TxUsart
; Tomar el Byte de Datos de RXB0D0 y convertirlo a ASCII.
movf
RXB0D2, W
call
HexAscii
; Convertir ambos nibles.
movlw
D'3'
; ¿Solo tres Datos?
cpfseq
FTempDA
bra
Data_D4
return
Data_D4:
movlw
d'32'
; Dejar separador.
call
TxUsart
; Tomar el Byte de Datos de RXB0D0 y convertirlo a ASCII.
movf
RXB0D3, W
call
HexAscii
; Convertir ambos nibles.
movlw
D'4'
; ¿Solo cuatro Datos?
cpfseq
FTempDA
bra
Data_D5
return
Data_D5:
movlw
d'32'
; Dejar separador.
call
TxUsart
; Tomar el Byte de Datos de RXB0D0 y convertirlo a ASCII.
movf
RXB0D4, W
call
HexAscii
; Convertir ambos nibles.
movlw
D'5'
; ¿Solo cinco Datos?
cpfseq
FTempDA
bra
Data_D6
return
Data_D6:
movlw
d'32'
; Dejar separador.
call
TxUsart
; Tomar el Byte de Datos de RXB0D0 y convertirlo a ASCII.
movf
RXB0D5, W
call
HexAscii
; Convertir ambos nibles.
movlw
D'6'
; ¿Solo seis Datos?
cpfseq
FTempDA
bra
Data_D7
return
Data_D7:
movlw
d'32'
; Dejar separador.
call
TxUsart
; Tomar el Byte de Datos de RXB0D0 y convertirlo a ASCII.
movf
RXB0D6, W
call
HexAscii
; Convertir ambos nibles.
movlw
D'7'
; ¿Solo siete Datos?
cpfseq
FTempDA
bra
Data_D8
return
Data_D8:
movlw
d'32'
; Dejar separador.
call
TxUsart
; Tomar el Byte de Datos de RXB0D0 y convertirlo a ASCII.
movf
RXB0D7, W
call
HexAscii
; Convertir ambos nibles.
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Conversor Hexadecimal a ASCII. Conversión y envio.
;---------------------------------------------------------------------------------
ConvHexAscii:
movwf
FTempCHA
movlw
D'9'
cpfsgt
FTempCHA
; skip if f > w
bra
MenorHA
MayorHA:
movf
FTempCHA,W
addlw
D'55'
; Convertirlo a ASCII A...F.
bra
SalHexAscii
MenorHA:
movf
FTempCHA,W
addlw
D'48'
; Convertirlo a ASCII 0...9.
SalHexAscii:
call
TxUsart
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Conversor Hexadecimal a ASCII. Tratamiento nibles.
;---------------------------------------------------------------------------------
HexAscii:
movwf
FTempHA
; Tomar el nible superior y conv. a ASCII.
swapf
FTempHA,W
andlw
B'00001111'
; Aplicar máscara.
call
ConvHexAscii
movf
FTempHA,W
; Tomar el nible inferior y conv. a ASCII.
andlw
B'00001111'
; Aplicar máscara.
call
ConvHexAscii
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Conversor ASCII a Hexadecimal.
;---------------------------------------------------------------------------------
AsciiHex:
movwf
FTempAH
movlw
A'9'
cpfsgt
FTempAH
; skip if f > w
bra
MenorAH
MayorAH:
; De A .... F.
movlw
D'55'
subwf
FTempAH,W
; f - w -> w
return
MenorAH:
; De 0 .... 9.
movlw
D'48'
subwf
FTempAH,W
; f - w -> w
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Retroceso de carro y avance de linea USART.
;---------------------------------------------------------------------------------
CR:
movlw
D'13'
call
TxUsart
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Transmisión caracter USART (del conversor RS232-CAN al PC).
;---------------------------------------------------------------------------------
TxUsart:
btfss
PIR1,TXIF
;Se garantiza que si el buffer está
bra
TxUsart
;ocupado no se sobrescribe.
movwf
TXREG
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Recepción caracter USART (del PC al conversor RS232-CAN).
;---------------------------------------------------------------------------------
RxUsart:
btfss
PIR1,RCIF
;Caracter recibido.
bra
RxUsart
movf
RCREG,W
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Configuración PORT:
;
RA0 pulsador P0.
RC0 Led L0.
;
RA1 pulsador P1.
RC1 Led L1.
;---------------------------------------------------------------------------------
IniPort:
movlw
0Fh
; Configura RA como digital.
movwf
ADCON1
setf
TRISA
; RA<7:0> como entradas.
movlw b'11111100'
;RC<7:2> como entradas y
movwf TRISC
;RC<1:0> salidas.
bcf
PORTC,0
bcf
PORTC,1
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Configuración TIMER0:
;---------------------------------------------------------------------------------
IniTimer0:
movlw
b'10000101'
; ON, 16bit timer, internal clock,
movwf
T0CON
;prescaler:64
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Configuración USART Transmisor. 115.200bps 8-N-1
;---------------------------------------------------------------------------------
IniUsart:
movlw b'00001000'
movwf BAUDCON
;BRG16=1
movlw
.42
;.129->9600 bps - Clock 20Mhz
movwf
SPBRG
movlw
b'00100100'
;TXEN=1, SYNC=0, BRGH=1
movwf
TXSTA
clrf
RCSTA
bsf
RCSTA,CREN
;CPEN = 1 habilita recepción.
bsf
RCSTA,SPEN
;SPEN = 1 habilita el puerto serie.
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
;
Configuración CAN.
;
Xtal 20Mhz 500Kbs(2uS) Tq=100nS NBT=20*100nS=2uS
;
;
Sync.Seg Pre.Seg Phase Seg.1 Phase Seg.2
;
1 3 8 8
;
;
Mascara SID 7FF.
Filtro SID 7E8.
;---------------------------------------------------------------------------------
ConfCAN:
movlw
b'10000000'
; Request Configuration mode.
movwf
CANCON
; Set to Configuration Mode.
; Wait for CAN bus to be idle before switching to Configure Mode.
ConfigWait:
movf
CANSTAT, W
; Read current mode state.
xorlw
b'10000000'
; Interested in OPMODE bits only.
tstfsz
WREG
; Is it Configuration mode yet?
bra
ConfigWait
; No. Continue to wait...
; Module is in Configuration mode now.
movlw
b'00000000'
; (1+Tq)00, (TQ=(2 x 1)/FOSC)000000
movwf
BRGCON1
;
movlw
b'10111010'
; 1 0 (8 x TQ)111 (3 x TQ)010
movwf
BRGCON2
;
movlw
b'00000111'
; 0 0 - - - (8 x TQ)111
movwf
BRGCON3
;
movlw
b'00100000'
; Rec. only valid messages SID.
movwf
RXB0CON
; Disable double buffer of RX0
movlb
.15
; Banco 15.
; Colocar valores Mascara (SID 7FFh).
movlw
b'11111111'
; SID<10:8> SID<7:4> SID<3>
movwf
RXM0SIDH
; (7)111 (F)1111 (F)1...
movlw
b'11100000'
; SID<2:0> — EXIDEN — EID<17:16>
movwf
RXM0SIDL
; (F).111 - 0 - 00
; Colocar valores Filtro (SID 7E8h)
movlw
b'11111101'
; SID<10:8> SID<7:4> SID<3>
movwf
RXF0SIDH
; (7)111 (E)1110 (8)1...
movlw
b'00000000'
; SID<2:0> — EXIDEN — EID<17:16>
movwf
RXF0SIDL
; (8).000 - 0 - 00
movlb
0
; Banco 0.
; Fin configuración CAN.
movlw
b'00000000'
; Out of CAN setup mode.
movwf
CANCON
; Request Normal Mode.
return
;---------------------------------------------------------------------------------
;End of program
END
;---------------------------------------------------------------------------------
;
Diagnosis OBD desde linea CAN-BUS
;
Peugeot 308
;---------------------------------------------------------------------------------
LIST P=18F2480, F=INHX32
;procesador.
#include <P18F2480.INC>
;include procesador.
;---------------------------------------------------------------------------------
; Configuracion bits
CONFIG
FCMEN = OFF, OSC = HS, IESO = OFF
CONFIG
PWRT = OFF, BOREN = BOHW, BORV=1
CONFIG
WDT=OFF, WDTPS = 16
CONFIG
MCLRE = ON
CONFIG
LPT1OSC = OFF, PBADEN = OFF
CONFIG
DEBUG = OFF
CONFIG
XINST = OFF, LVP = OFF, STVREN = ON, CP0 = OFF
CONFIG
CP1 = OFF, CPB = OFF, CPD = OFF, WRT0 = OFF, WRT1 = OFF, WRTB = OFF
CONFIG
WRTC = OFF, WRTD = OFF, EBTR0 = OFF, EBTR1 = OFF, EBTRB = OFF
;---------------------------------------------------------------------------------
; Definir variables.
;---------------------------------------------------------------------------------
CBLOCK 0
MENSA_USART
FTemp
; Temporal de uso general.
FTempHA
; Temp. Hex - Ascii.
FTempCHA
; Temp. Hex - Ascii.
FTempAH
; Temp. Ascii - Hex.
FTempDA
; Temp. Data Len.
DigNDatos
; Digito nº de datos adicionales.
DigMODE
; Digito MODE.
DigPIDH
; Digito PID alto.
DigPIDL
; Digito PID bajo.
RetLinea
; Retorno linea.
ENDC
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Reset vector
;---------------------------------------------------------------------------------
ORG
0x0000
goto
Main
; Go to start.
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Inicio.
;---------------------------------------------------------------------------------
ORG
0x00A0
Main:
movlw
d'13'
movwf
RetLinea
; Preparar valor retorno de linea.
call
IniPort
; Inicializa puertos.
call
IniTimer0
; Inicializa TIMER0.
call
IniUsart
; Inicializa USART.
call
ConfCAN
; Config. CAN.
LoopCAN:
call
PeticionDatos
; Petición de códigos a enviar a CANBUS.
call
EnviarMensaCAN
; Transmisión mensaje vía CANBUS.
clrf
TMR0H
; Preparando temporización de respuesta CAN.
clrf
TMR0L
bcf
INTCON, TMR0IF
TempRespuestaCAN:
btfsc
RXB0CON, RXFUL
; ¿Hay recep. mensaje CAN?
call
LecturaCAN
; Lectura de mensajes CAN.
btfss
INTCON, TMR0IF
; Fin espera de respuesta mensaje CAN.
bra
TempRespuestaCAN ; Espera mensaje CAN.
bra
LoopCAN
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Petición de datos vía RS232 y enviarlos por el CANBUS (SAE Standard).
; Byte 0 1 2 3 4 5 6
7
; Nº de bytes NºDatos(1) MODE(1) PID(2) ----- no usados -----
;---------------------------------------------------------------------------------
PeticionDatos:
call
CR
movlw
A'?'
call
TxUsart
call
TxUsart
call
CR
; Petición de digito NDatos.
call
RxUsart
cpfseq
RetLinea
bra
DigNDatos_P
bra
PeticionDatos
DigNDatos_P:
call
AsciiHex
movwf
DigNDatos
; Petición de digito MODE.
call
RxUsart
cpfseq
RetLinea
bra
DigMODE_P
bra
PeticionDatos
DigMODE_P:
call
AsciiHex
movwf
DigMODE
; Petición de los digitos PID.
call
RxUsart
cpfseq
RetLinea
bra
DigPIDH_P
bra
PeticionDatos
DigPIDH_P:
call
AsciiHex
movwf
DigPIDH
call
RxUsart
cpfseq
RetLinea
bra
DigPIDL_P
bra
PeticionDatos
DigPIDL_P:
call
AsciiHex
movwf
DigPIDL
; Petición retorno de linea.
call
RxUsart
cpfseq
RetLinea
bra
PeticionDatos
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
;
Enviar mensaje CAN
;
ID Byte0(nºdatos) Byte1(MODE) Byte2(PIDcode) Byte3
...
; 0x7DF x x xx
-- --
;
Datos de retorno: 1.
;---------------------------------------------------------------------------------
EnviarMensaCAN:
bsf
PORTC,1
; Preparación mensaje a enviar.
movlb
.15
movf
DigNDatos,W
; Byte0: Número de datos adicionales.
movwf
TXB0D0
movf
DigMODE,W
; Byte1: MODE.
movwf
TXB0D1
swapf
DigPIDH,W
; Byte2: PID.
iorwf
DigPIDL,W
movwf
TXB0D2
movlw
00h
; No usados.
movwf
TXB0D3
movlw
00h
;
''
movwf
TXB0D4
movlw
00h
;
''
movwf
TXB0D5
movlw
00h
;
''
movwf
TXB0D6
movlw
00h
;
''
movwf
TXB0D7
;Nº de datos a transmitir = 8
movlw
08h
movwf
TXB0DLC
; Tamaño datos.
;Transmitir ID = 7DF
movlw
B'11111011'
; SID<10:8> SID<7:4> SID<3>
movwf
TXB0SIDH
; (7)111 (D)1101 (F)1...
movlw
B'11100000'
; SID<2:0> — EXIDE — EID<17:16>
movwf
TXB0SIDL
; (F).111 - 0 - 00
movlw
B'00001000'
; Transmitir mensaje.
movwf
TXB0CON
EnvioMesaCAN:
btfsc
TXB0CON, TXREQ
bra
EnvioMesaCAN
movlb
.0
bcf
PORTC,1
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
;
Lectura mensajes CAN.
;---------------------------------------------------------------------------------
LecturaCAN:
bsf
PORTC,0
; Señalizar recepción mensaje CAN.
call
StID_Ascii
call
StLen_Ascii
call
Data_Ascii
SalirLecturaCAN:
bcf
RXB0CON, RXFUL ; Limpiar flag RXFUL mensaje CAN.
clrf
PIR3
bcf
PORTC,0
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Lectura-conversion Standar ID a ASCII .
;---------------------------------------------------------------------------------
StID_Ascii:
call
CR
; Tomar el nible superior de RXB0SIDH y convertirlo a ASCII.
movf
RXB0SIDH,W
movwf
FTemp
swapf
FTemp,F
rrncf
FTemp,W
andlw
B'00000111'
; Aplicar máscara.
call
ConvHexAscii
; Convertir solo el nible inferior.
; Tomar el nible inferior de RXB0SIDH y convertirlo a ASCII.
movf
RXB0SIDH,W
movwf
FTemp
rrncf
FTemp,W
andlw
B'00001111'
; Aplicar máscara.
call
ConvHexAscii
; Convertir solo el nible inferior.
; Tomar el seminible superior de RXB0SIDL y convertirlo a ASCII.
movf
RXB0SIDL,W
; Tomar el nible superior.
movwf
FTemp
swapf
FTemp,F
rrncf
FTemp,W
andlw
B'00000111'
; Aplicar máscara.
movwf
FTemp
btfsc
RXB0SIDH,0
bsf
FTemp,3
movf
FTemp,W
call
ConvHexAscii
; Convertir solo el nible inferior.
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Lectura-conversion Standard Data Lenght a ASCII.
;---------------------------------------------------------------------------------
StLen_Ascii:
movlw
d'32'
; Dejar separador.
call
TxUsart
; Tomar el nible inferior de RXB0DLC y convertirlo a ASCII.
movf
RXB0DLC, W
movwf
FTemp
andlw
B'00001111'
; Aplicar máscara.
call
ConvHexAscii
; Convertir solo el nible inferior.
return
;---------------------------------------------------------------------------------
;---------------------------------------------------------------------------------
; Lectura-conversion campo de Datos a ASCII.
;---------------------------------------------------------------------------------
Data_Ascii:
movf
RXB0DLC, W
movwf
FTempDA
andlw
B'00001111'
; Aplicar máscara.
movwf
FTempDA
; ¿Cero Datos?
movlw
D'0'
cpfseq
FTempDA
bra
Data_D1
return
Data_D1:
movlw
d'32'
; Dejar separador.
call
TxUsart
; Tomar el Byte de Datos de RXB0D0 y convertirlo a ASCII.
movf
RXB0D0, W
call
HexAscii
; Convertir ambos nibles.
movlw
D'1'
; ¿Solo un Dato?
cpfseq
FTempDA
bra
Data_D2
return
Firmware microcontrolador
El OBD se ha realizado con el conector de un vehículo de
desguace al cual se han soldado los pines necesarios y se
ha añadido una pequeña pletina de plastico con una ranura
para garantizar la correcta posición.
Los diodos LEDs y los pulsadores no son necesarios, se utilizaron
durante el proceso de desarrollo para depurar el software.
Aspecto incial de la aplicación.
Bricos Peugeot 308