Values: B Per-loop holding for flagbyte - B register because it's bit addressable, unlike R(x). R3 Per-loop holding for S0BUF byte 0xFDAE Flagbyte Memory Address ----- ; Get Flagbyte to B register 90 FD AE MOV DPTR, #0xFDAE ; Logging Flagbyte E0 MOVX A, @DPTR ; Get byte to ACC F5 F0 MOV B, A ; Move to B ; Handle pre-start OBD-II request - Abandon ship if this is set. 30 F3 01 JNB B.3 +1 ; Pre-start OBD-II Requested 22 RET ; The running routine sets B.2 when it logs so we can distinguish drive cycles. ; If this is the first loop of pre-start after a drive cycle, clear out the flagbyte. ; This allows us to distinguish drive cycles. 30 F2 09 JNB B.2, +9 ; Jump over this if B.2 is not set C2 F0 CLR B.0 C2 F1 CLR B.1 C2 F2 CLR B.2 E5 F0 MOV A, B F0 MOVX @DPTR, A ; Update memory ; Init Serial Port C2 AC CLR IEN0.4 ; Turn off serial interrupt 75 AA FC MOV S0RELL, 0xFC ; vvv 75 BA 03 MOV S0RELH, 0x3 ; S0REL = 0x3FC -- 125000 baud with SMOD set 43 98 50 ORL S0CON, 0x50 ; Set bits SM1 and REN0 53 98 7F ANL S0CON, 0x7F ; Clear bit SM0 - Ensure Mode 1 8Bit UART 43 87 80 ORL PCON, #0x80 ; set PCON0.7 (SMOD), bitrate doubler 43 D8 80 ORL ADCON0, #0x80 ; Set ADCON0.7 (BD), enable baud rate generator C2 AC CLR IEN0.4 ; Turn off serial interrupt ; Check for pending input E5 98 MOV A, S0CON 30 E0 77 JNB ACC.0, +119 E5 99 MOV A, S0BUF ; MOV received byte to ACC FB MOV R3, A ; Store received byte in R3 C2 98 CLR S0CON.0 ; Clear S0CON.RI0 Received Byte Flag ; Send "RCV" to ack input 75 99 52 MOV S0BUF, #0x52 ; Send R 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI 75 99 43 MOV S0BUF, #0x43 ; Send C 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI 75 99 56 MOV S0BUF, #0x56 ; Send V 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI ; Check for incoming "l" to enable logging BB 6C 1E CJNE R3, #0x6C, +30 ; Compare to "l" 75 F0 03 MOV B, #3 ; Bits 0 and 1 - Logging enabled, request enable on next drive cycle E5 F0 MOV A, B F0 MOVX @DPTR, A ; Update XRAM flagbyte ; Send LOG 75 99 4C MOV S0BUF, #0x4C ; Send L 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI 75 99 4F MOV S0BUF, #0x4F ; Send O 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI 75 99 47 MOV S0BUF, #0x47 ; Send G 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI ; Check for incoming "o" to enable pre-start OBD-II ; This will cause this routine to abort until after the drive cycle logging routine clears the bit ; This means we don't have to do this more than once in a no-start condition unless we remove +12v to the ECU BB 6F 2B CJNE R3, #0x6F, +43 ; Compare to "o" 75 F0 08 MOV B, #8 ; bit 3, pre-start OBD-II E5 F0 MOV A, B F0 MOVX @DPTR, A ; Update XRAM flagbyte ; Send "OBD" 75 99 4F MOV S0BUF, #0x4F ; Send O 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI 75 99 42 MOV S0BUF, #0x42 ; Send B 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI 75 99 44 MOV S0BUF, #0x44 ; Send D 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI ; Reapply the settings found in the RESET routine used to initally configure the serial port 75 98 90 MOV S0CON, #0x90 75 BA 03 MOV S0RELH, #3 75 AA CC MOV S0RELL, #0xCC 53 87 7F ANL PCON, #7F 22 RET ; Send current state ; This gets the current flagbyte, adds 41h to it, and outputs it. ; 41h is ascii "A" -- so if the byte was 3, it would output a single "D". This is mainly for debugging/confirmation. E5 F0 MOV A, B ; Flagbyte to A 24 41 ADD A, #0x41 ; 0x41 ASCII "A" F5 99 MOV S0BUF, A ; Send flagbyte 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI C2 AC CLR IEN0.4 ; Turn off serial interrupt C2 98 CLR S0CON.0 ; Clear S0CON.RI recieve byte flag 22 RET Bytes: 90 FD AE E0 F5 F0 30 F3 01 22 30 F2 09 C2 F0 C2 F1 C2 F2 E5 F0 F0 C2 AC 75 AA FC 75 BA 03 43 98 50 53 98 7F 43 87 80 43 D8 80 C2 AC E5 98 30 E0 77 E5 99 FB C2 98 75 99 52 30 99 FD C2 99 75 99 43 30 99 FD C2 99 75 99 56 30 99 FD C2 99 BB 6C 1E 75 F0 03 E5 F0 F0 75 99 4C 30 99 FD C2 99 75 99 4F 30 99 FD C2 99 75 99 47 30 99 FD C2 99 BB 6F 2B 75 F0 08 E5 F0 F0 75 99 4F 30 99 FD C2 99 75 99 42 30 99 FD C2 99 75 99 44 30 99 FD C2 99 75 98 90 75 BA 03 75 AA CC 53 87 7F 22 E5 F0 24 41 F5 99 30 99 FD C2 99 C2 AC C2 98 22 FDAE BITS: 0: Logging enabled 1: Request log enable 2: Ack log enable from drivecycle logging routine 3: Request for pre-start OBD-II Remember to: Set flagbyte bit 2 from drive cycle routine! - TODO: keybyte "m" to initiate XRAM dump -- loop incrementing DPTR over F800 to FFFF and outputing to serial