daedalusjc
18-09-2010, 07:00 PM
Hi guys,
As you know the adaptronic sends an at command to the obdpro to remove and cel;s that may be current or pending. Now one downfall of this is not having the serial port free to run serial based widebands. So after alot of contemplation and research i've put together a very very simple PIC circuit based on the 16f628a to simply clear cel's every 5 minutes without hogging the CANBUS.
Parts required
1x PIC 16F628a
1x Max232 RS232 line converter
3x 1uF electrolic capacitors
1x 10uF electrolic capacitor
1x momentary switch (Handy for reset)
1x 100n MKT capacitor
1x 12k resistor
You will also need a 5v source such as the spare TPS +5v line or a 12 to 5v converter and also a Male DB9 connector.
<a href="http://s215.photobucket.com/albums/cc175/daedalusjc/?action=view¤t=628uart.gif" target="_blank"><img src="http://i215.photobucket.com/albums/cc175/daedalusjc/628uart.gif" border="0" alt="Photobucket"></a>
All you need to do is compile the code with MPLAB or MPASMWIN and burn it to the PIC
Code
;************************************************* ******************
; Function: Sends ATZ 04 command to obdpro to clear cel's
; Processor: PIC16F628 at 4 MHz using internal RC oscillator
; Hardware: Cutsom breadboard. 628A + Max232
; Filename: 628uart.asm
; Author: Matt Abbott. Base code modified from Lars Peterson
; Email: daedalusjc@amnet.net.au
; Credit: Base code modified from Lars Peterson
;************************************************* ******************
LIST P=16F628, R=DEC ; Use the PIC16F628 and decimal system
#include "P16F628.INC" ; Include header file
__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON
CBLOCK 0x20 ; Declare variable addresses starting at 0x20
dataL
d1
d2
d3
d4
e1
e2
e3
ENDC
ORG 0x000
;
; --------------------------------
; SET ANALOG/DIGITAL INPUTS PORT A
; --------------------------------
;
movlw 7
movwf CMCON
;
; ----------------
; INITIALIZE PORTS
; ----------------
;
movlw b'00000000' ; set up portA
movwf PORTA
movlw b'00000100' ; RB2(TX)=1 others are 0
movwf PORTB
bsf STATUS,RP0 ; RAM PAGE 1
movlw 0xFF
movwf TRISA ; portA all pins input
movlw b'11110010' ; RB7-RB4 and RB1(RX)=input, others output
movwf TRISB
; ------------------------------------
; SET BAUD RATE TO COMMUNICATE WITH ADAPTRONIC SERIAL PORT
; ------------------------------------
; Boot Baud Rate = 9600, No Parity, 1 Stop Bit
;
movlw 0x19 ; 0x19=9600 bps (0x0C=19200 bps)
movwf SPBRG
movlw b'00100100' ; brgh = high (2)
movwf TXSTA ; enable Async Transmission, set brgh
bcf STATUS,RP0 ; RAM PAGE 0
movlw b'10010000' ; enable Async Reception
movwf RCSTA
;
; ------------------------------------
; START UP SETTLE DELAY AND FLUSH
; ------------------------------------
;
clrf dataL
settle decfsz dataL,F
goto settle
movf RCREG,W
movf RCREG,W
movf RCREG,W ; flush receive buffer
;
; ---------
; MAIN LOOP
; ---------
;
call Delay3 ; Initial 5 second delay
nop ; internal delay
call message ; Send ATZ to wake up obdpro in first startup
call Delay3 ; Another 5 second delay
nop ; Loop delay
call message2 ; Send 04 to clear CEL
loop call Delay3 ; send "ATZ" to initialize obd adaptor
call message ; send ATZ once car is running
call Delay ; 5 minute delay to avoid congesting CANBUS
call message2 ; send 04 to clear any pending CEL's
goto loop ; return to start of loop. process duration 5 min 5 seconds
Delay
;299999995 cycles
movlw 0x54
movwf d1
movlw 0xA1
movwf d2
movlw 0xFD
movwf d3
movlw 0x02
movwf d4
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto $+2
decfsz d4, f
goto Delay_0
;1 cycle
nop
;4 cycles (including call)
return
Delay3
;4999993 cycles
movlw 0x2C
movwf e1
movlw 0xE7
movwf e2
movlw 0x0B
movwf e3
Delay3_0
decfsz e1, f
goto $+2
decfsz e2, f
goto $+2
decfsz e3, f
goto Delay3_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
;
; -------------------------------------------------------------
; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING
; -------------------------------------------------------------
;
send movwf TXREG ; send data in W
TransWt bsf STATUS,RP0 ; RAM PAGE 1
WtHere btfss TXSTA,TRMT ; (1) transmission is complete if hi
goto WtHere
bcf STATUS,RP0 ; RAM PAGE 0
return
;
; -------
; MESSAGE
; -------
;
message movlw 'A'
call send
movlw 'T'
call send
movlw 'Z'
call send
movlw 0x0D ; CR
call send
movlw 0x0A ; LF
call send
return
message2 movlw '0'
call send
movlw '4'
call send
movlw 0x0D ; CR
call send
movlw 0x0A ; LF
call send
return
END
As you know the adaptronic sends an at command to the obdpro to remove and cel;s that may be current or pending. Now one downfall of this is not having the serial port free to run serial based widebands. So after alot of contemplation and research i've put together a very very simple PIC circuit based on the 16f628a to simply clear cel's every 5 minutes without hogging the CANBUS.
Parts required
1x PIC 16F628a
1x Max232 RS232 line converter
3x 1uF electrolic capacitors
1x 10uF electrolic capacitor
1x momentary switch (Handy for reset)
1x 100n MKT capacitor
1x 12k resistor
You will also need a 5v source such as the spare TPS +5v line or a 12 to 5v converter and also a Male DB9 connector.
<a href="http://s215.photobucket.com/albums/cc175/daedalusjc/?action=view¤t=628uart.gif" target="_blank"><img src="http://i215.photobucket.com/albums/cc175/daedalusjc/628uart.gif" border="0" alt="Photobucket"></a>
All you need to do is compile the code with MPLAB or MPASMWIN and burn it to the PIC
Code
;************************************************* ******************
; Function: Sends ATZ 04 command to obdpro to clear cel's
; Processor: PIC16F628 at 4 MHz using internal RC oscillator
; Hardware: Cutsom breadboard. 628A + Max232
; Filename: 628uart.asm
; Author: Matt Abbott. Base code modified from Lars Peterson
; Email: daedalusjc@amnet.net.au
; Credit: Base code modified from Lars Peterson
;************************************************* ******************
LIST P=16F628, R=DEC ; Use the PIC16F628 and decimal system
#include "P16F628.INC" ; Include header file
__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON
CBLOCK 0x20 ; Declare variable addresses starting at 0x20
dataL
d1
d2
d3
d4
e1
e2
e3
ENDC
ORG 0x000
;
; --------------------------------
; SET ANALOG/DIGITAL INPUTS PORT A
; --------------------------------
;
movlw 7
movwf CMCON
;
; ----------------
; INITIALIZE PORTS
; ----------------
;
movlw b'00000000' ; set up portA
movwf PORTA
movlw b'00000100' ; RB2(TX)=1 others are 0
movwf PORTB
bsf STATUS,RP0 ; RAM PAGE 1
movlw 0xFF
movwf TRISA ; portA all pins input
movlw b'11110010' ; RB7-RB4 and RB1(RX)=input, others output
movwf TRISB
; ------------------------------------
; SET BAUD RATE TO COMMUNICATE WITH ADAPTRONIC SERIAL PORT
; ------------------------------------
; Boot Baud Rate = 9600, No Parity, 1 Stop Bit
;
movlw 0x19 ; 0x19=9600 bps (0x0C=19200 bps)
movwf SPBRG
movlw b'00100100' ; brgh = high (2)
movwf TXSTA ; enable Async Transmission, set brgh
bcf STATUS,RP0 ; RAM PAGE 0
movlw b'10010000' ; enable Async Reception
movwf RCSTA
;
; ------------------------------------
; START UP SETTLE DELAY AND FLUSH
; ------------------------------------
;
clrf dataL
settle decfsz dataL,F
goto settle
movf RCREG,W
movf RCREG,W
movf RCREG,W ; flush receive buffer
;
; ---------
; MAIN LOOP
; ---------
;
call Delay3 ; Initial 5 second delay
nop ; internal delay
call message ; Send ATZ to wake up obdpro in first startup
call Delay3 ; Another 5 second delay
nop ; Loop delay
call message2 ; Send 04 to clear CEL
loop call Delay3 ; send "ATZ" to initialize obd adaptor
call message ; send ATZ once car is running
call Delay ; 5 minute delay to avoid congesting CANBUS
call message2 ; send 04 to clear any pending CEL's
goto loop ; return to start of loop. process duration 5 min 5 seconds
Delay
;299999995 cycles
movlw 0x54
movwf d1
movlw 0xA1
movwf d2
movlw 0xFD
movwf d3
movlw 0x02
movwf d4
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto $+2
decfsz d4, f
goto Delay_0
;1 cycle
nop
;4 cycles (including call)
return
Delay3
;4999993 cycles
movlw 0x2C
movwf e1
movlw 0xE7
movwf e2
movlw 0x0B
movwf e3
Delay3_0
decfsz e1, f
goto $+2
decfsz e2, f
goto $+2
decfsz e3, f
goto Delay3_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
;
; -------------------------------------------------------------
; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING
; -------------------------------------------------------------
;
send movwf TXREG ; send data in W
TransWt bsf STATUS,RP0 ; RAM PAGE 1
WtHere btfss TXSTA,TRMT ; (1) transmission is complete if hi
goto WtHere
bcf STATUS,RP0 ; RAM PAGE 0
return
;
; -------
; MESSAGE
; -------
;
message movlw 'A'
call send
movlw 'T'
call send
movlw 'Z'
call send
movlw 0x0D ; CR
call send
movlw 0x0A ; LF
call send
return
message2 movlw '0'
call send
movlw '4'
call send
movlw 0x0D ; CR
call send
movlw 0x0A ; LF
call send
return
END