WIP; in midst of testing 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.1 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. Also clear the log enable bit. ; But first, check if B.2 is set, indicating we want keep logging enabled. 20 F2 09 JB B.2, +9 ; Persistent logging enable 30 F1 06 JNB B.1, +6 ; Jump over this if B.1 is not set 53 F0 FC ANL B, #0xFC ; Clear bits 0 and 1 E5 F0 MOV A, B F0 MOVX @DPTR, A ; Update memory ; Init Serial Port 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 20 E0 04 JB ACC.0, +4 ; Got input, step over return ; No input, set Mode1 + REN0 and return 75 98 50 MOV S0CON, #0x50 ; Bits SM1 and REN0 22 RET ; Get S0BUF and send "R" to ack input E5 99 MOV A, S0BUF ; MOV received byte to ACC FB MOV R3, A ; Store received byte in R3 53 98 EE ANL S0CON, #0xEE ; Clear RI0 and REN0 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 ; Check for incoming "l" to enable logging BB 6C 0E CJNE R3, #0x6C, +14 ; Compare to "l" 75 F0 01 MOV B, #1 ; Set bit 0 only E5 F0 MOV A, B F0 MOVX @DPTR, A ; Update XRAM flagbyte ; Send l to ack 75 99 6C MOV S0BUF, #0x6C ; 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 ; Check for incoming "L" to enable persistent logging BB 4C 0E CJNE R3, #0x4C, +14 ; Compare to "L" 75 F0 05 MOV B, #5 ; Set bits 0, 2, request with persistence E5 F0 MOV A, B F0 MOVX @DPTR, A ; Update XRAM flagbyte ; Send l to ack 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 ; Check for incoming "d" to disable logging BB 64 0E CJNE R3, #0x64, +14 ; Compare to "d" 75 F0 00 MOV B, #0 ; Set bit 0 only E5 F0 MOV A, B F0 MOVX @DPTR, A ; Update XRAM flagbyte ; Send l to ack 75 99 64 MOV S0BUF, #0x64 ; 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 ; Check for incoming "x" for XRAM dump BB 78 36 CJNE R3, #0x78, +54 ; Compare to "x" ; send XRAM contents C2 AF CLR IEN0.7 ; Disable interrupts 90 F7 FF MOV DPTR, #F7FF ; Set DPTR to start of XRAM - 1 A3 INC DPTR ; Increment DPTR E5 83 MOV A, DPH ; Get DPH byte B4 FF 07 CJNE A, #0xFF, +7 ; See if we're in the last segment, if not, we can skip checking DPL E5 82 MOV A, DPL ; Get DPL byte B4 FF 00 CJNE A, #0XFF, 0 ; Compare to FF 50 22 JNC +34 ; Carry set it we are less than FF, otherise jump over the loop 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 7A 40 MOV R2, 0x40 ; 64-cycle delay counter DA FE DJNZ R2, 0 E0 MOV A, @DPTR ; Get byte at DPTR address F5 99 MOV S0BUF, A ; Send Byte 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI 80 D4 SJMP -44 ; Send next byte D2 AF SETB IEN0.7 ; Check for incoming "P" to dump port SFRs BB 70 36 CJNE R3, #0x70, +63 ; Compare to "p" E5 80 MOV A, P0 F5 99 MOV S0BUF, A ; Send Byte 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI E5 90 MOV A, P1 F5 99 MOV S0BUF, A ; Send Byte 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI E5 A0 MOV A, P2 F5 99 MOV S0BUF, A ; Send Byte 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI E5 B0 MOV A, P3 F5 99 MOV S0BUF, A ; Send Byte 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI E5 E8 MOV A, P4 F5 99 MOV S0BUF, A ; Send Byte 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI E5 F8 MOV A, P5 F5 99 MOV S0BUF, A ; Send Byte 30 99 FD JNB S0CON.1, $ ; Wait on S0CON.TI to be set: transmit has completed C2 99 CLR S0CON.1 ; Clear S0CON.TI E5 FA MOV A, P6 F5 99 MOV S0BUF, A ; Send Byte 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 BB 6F 1B CJNE R3, #0x6F, +26 ; Compare to "o" 75 F0 08 MOV B, #8 ; bit 2, prestart OBDII 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 ; 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 ; -- EXIT LOOP ; 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 ; Exit routine, ends here 75 98 50 MOV S0CON, #0x50 ; Serial Mode1, REN0 Enabled 22 RET Bytes: 90 FD AE E0 F5 F0 30 F3 01 22 20 F2 09 30 F1 06 53 F0 FC E5 F0 F0 75 AA FC 75 BA 03 43 98 50 53 98 7F 43 87 80 43 D8 80 C2 AC E5 98 20 E0 04 75 98 50 22 E5 99 FB 53 98 EE 75 99 52 30 99 FD C2 99 BB 6C 0E 75 F0 01 E5 F0 F0 75 99 6C 30 99 FD C2 99 BB 4C 0E 75 F0 05 E5 F0 F0 75 99 4C 30 99 FD C2 99 BB 64 0E 75 F0 00 E5 F0 F0 75 99 64 30 99 FD C2 99 BB 78 36 C2 AF 90 F7 FF A3 E5 83 B4 FF 07 E5 82 B4 FF 00 50 22 75 AA FC 75 BA 03 43 98 50 53 98 7F 43 87 80 43 D8 80 C2 AC 7A 40 DA FE E0 F5 99 30 99 FD C2 99 80 D4 D2 AF BB 70 36 E5 80 F5 99 30 99 FD C2 99 E5 90 F5 99 30 99 FD C2 99 E5 A0 F5 99 30 99 FD C2 99 E5 B0 F5 99 30 99 FD C2 99 E5 E8 F5 99 30 99 FD C2 99 E5 F8 F5 99 30 99 FD C2 99 E5 FA F5 99 30 99 FD C2 99 BB 6F 1B 75 F0 08 E5 F0 F0 75 99 4F 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 75 98 50 22 FDAE BITS: 0: Request Logging 1: Request ACK from drive cycle logging routine 2: Keep logging enabled across drive cycles 3: Request for pre-start OBD-II Remember to: Set flagbyte bit 2 from drive cycle routine!