; ; Juha Niinikoski 12.2.1999 ; GM ALDL bus display v1.0 ; operates on Motorola HC12A4 processor ; I/O routines added 13.2.1999 ; fault finding 19.2.1999 ; diag display indexes corrected 20.2.1999 ; checksum logic found & added 21.2.1999 ; some timing problems corrected, found more ; parameter indexes, selector knob IRQ routines added, ; more display stuff 22.2.1999 v1.1 ; TCC slip parameter found 26.2.1999 ; ; Memory Map Equates RAMSTART: EQU $0800 ; start of internal ram RAMEND : EQU $0BFF ; END of internal ram ; STACK: EQU RAMEND ; top of stack ; ROMBS: EQU $F000 ; start of rom ; #include equates.asm ; include register equates ; ; Ram variables ; ORG RAMSTART ; ; capture buffer start ; BUFL: FCB #BUFFE-#BUFFER+1 ; BUFFER: FCB $01 ;#0 FCB $00 ;#1 ; FCB $00 ;#2 Fault code bits FCB $00 FCB $00 ;#4 FCB $00 FCB $00 FCB $00 FCB $00 FCB $00 ;#9 FCB $00 ;#10 FCB $00 FCB $00 FCB $00 FCB $00 ;#14 FCB $00 ;#15 FCB $00 FCB $00 FCB $00 ; FCB $04 ;#19 ? ; TB: FCB $12 ;#20 Throttle % ; FCB $12 ;#21 (throttle % duplicate ?) ; FCB $83 ;#22 ; TTEMP: FCB $47 ;#23 Trans Temp ; ERPM: FCB $14 ;#24 RPM Engine FCB $C9 ;#25 ; IRPM: FCB $15 ;#26 RPM Input ? FCB $E4 ;#27 ; TRPM: FCB $15 ;#28 RPM Turbine ? FCB $5F ;#39 ; SPEED: ; is this speed or ?? ORPM: FCB $00 ;#30 RPM Output FCB $00 ;#31 ; FCB $00 ;#32 FCB $19 ;#33 FCB $2B ;#34 FCB $2A ;#35 FCB $00 ;#36 FCB $40 ;#37 BATT: FCB $89 ;#38 Battery voltage FCB $00 ;#39 ; FCB $00 ;#40 Vechicle speed ? ; FCB $FF ;#41 Torque sig (PSI) ; FCB $FF ;#42 PCS DES Amp (V) ; FCB $FF ;#43 Press ctrl amp (V) ; FCB $FF ;#44 ;14 FCB $37 ;#45 ;36 ;37 FCB $14 ;#46 ; CGEAR: FCB $00 ;#47 Current Gear ? ; TCC Duty cycle ? FCB $40 ;#48 FCB $60 ;#49 FCB $48 ;#50 FCB $00 ;#51 FCB $00 ;#52 FCB $00 ;#53 FCB $00 ;#54 FCB $01 ;#55 FCB $F8 ;#56 FCB $FF ;#57 FCB $00 ;#58 FCB $00 ;#59 FCB $1E ;#60 FCB $00 ;#61 ; TCCSL: FCB $FC ;#62 TCC slip (RPM) FCB $D5 ;#63 ; FCB $9E ;#64 FCB $9E ;#65 FCB $00 ;#66 FCB $08 ;#67 FCB $01 ;#68 FCB $06 ;#69 FCB $26 ;#70 FCB $01 ;#71 FCB $00 ;#72 ; FCB $02 ;#73 Shift fail ? FCB $10 ;#74 1-2 Shift (sec) ? FCB $20 ;#75 2-3 FCB $40 ;#76 3-4 ; FCB $00 ;#77 FCB $00 ;#78 FCB $00 ;#79 FCB $1C ;#80 FCB $C4 ;#81 ; PROMID: FCB $23 ;#82 Prom ID 9189 = 23E5h FCB $E5 ;#83 ; BBITS: FCB $19 ;#84 BREQ EQU %10000000 ; BRAKE REQUEST = 1 ACREQ EQU %01000000 ; AC REQUEST = 1 ; PRBIT: FCB $B7 ;#85 BRAKE EQU %00100000 ; BRAKE APPLIED = 0 ACON EQU %01000000 ; AC ON = 1 PRNMASK EQU %00011100 ; BUFFE: FCB $B1 ;#86 Frame Checksum byte ; FCB $0 ;________________________________ ; BUFNDX RMB 2 ; CAPTURE BUFFER INDEX DLYCTR RMB 2 ; DELAY COUNTER N*100YS TEMP RMB 1 ; GENERAL TEMP STORAGE CSUM RMB 1 ; CHECK SUM OB RMB 1 ; BINARY OUTPUT WORKING REG OBCTR RMB 1 ;____________________________________ OCH RMB 1 ; OUTPUT CHANEL SELECTOR ; 0=RS232, 1=ALDL, 2=LCD1, 3=LCD2 RS232 EQU 0 ALDL EQU 1 LCD1 EQU 2 LCD2 EQU 3 ;_________________________________ ; BIN TO DECIMAL CONVERSION TEMPORARYSTORAGE SAVEA RMB 1 ; ACCUMULATOR A SAVEX RMB 2 ; STORE DATA POINTER SAVEX1 RMB 2 ; POINTER TO CONSTANTS ASCIIC RMB 5 ; ASCII CHARACTERS ASCBUFE RMB 1 ; THIS SHOULD BE INIT TO 0 SIGN RMB 1 ; SIGN CHARACTER ; DEBU RMB 1 ; DEBUG INDICATOR ;_______________________________ ; LCD DRIVER EQUATES LCD_DATA EQU PORTA LCD_CTRL EQU PORTB E EQU $1 ;E FOR NORMAL DISPLAYS E1 EQU $8 ;E1 FOR BIG 4 X 40 DISPLAY E2 EQU $10 ;E2 FOR BIG 4 X 40 DISPLAYS RW EQU $4 RS EQU $2 ; DIAG EQU $20 ;DIAG REQUEST BIT DIAG2 EQU $40 ;DIAG PAGE 2 ; ; LCD DRIVER VARIABLES TIME RMB 2 ;DELAY COUNTER ; ; SELECTOR KNOB VARIABLES FA: EQU $20 ; PHASE A BIT FB: EQU $40 ; PHASE B BIT BUT: EQU $80 ; BUTTON PRESSED BIT IRQEN: EQU $40 ; IRQ ENABLE BIT ; KNOBV: RMB 1 ; KNOB U / DOWN VALUE BUTPR: RMB 1 ; BUTTON PRESSED OBVAL: RMB 1 ; ;______________________________________________ ; ORG ROMBS ; START OF PROGRAM ROM ; ;______________________________________________ START: LDS #STACK ; initialize stack pointer ; LDAA #BUFFE-BUFFER+1 ; DEBUG CAPTURE BUFFER STAA BUFL ; STORE CAPTURE BUFFER LENGTH JSR BUFINIT ; INIT DEBUG CAPTURE BUFFER ; CLR ASCBUFE ; SET EOT TO PRINT BUFFER ; ; INIT LCD PORTS A & B ; CLR LCD_CTRL CLR LCD_DATA LDAB #$FF STAB DDRA ;A&B PORTS = OUTPUTS LDAB #%00011111 STAB DDRB ;B/D5 = DIAG INPUT ;B PULL UPS ARE ON ; JSR INITLCD ; ; #1 (ALDL) SARJAPORTIN ALUSTUS 8192 NOPEUTEEN ; LDAA #61 STAA SC1BDL LDAA #%00001100 STAA SC1CR2 ; ; #0 RS232 SARJAPORTIN ALUSTUS 9600 NOPEUTEEN ; LDAA #52 STAA SC0BDL LDAA #%00001100 STAA SC0CR2 ; ; INIT KNOB I/O ; LDAA #FA+FB+BUT ; SET KEY INT BITS STAA KWIED CLR KNOBV CLR BUTPR CLI ; ENABLE IRQS ; ; INIT AD CONVERTER ; LDAA #$80 STAA ATDCTL2 ; TURN CONVERTER ON LDAA #$70 STAA ATDCTL5 ; START SCANNER ; ; ; INIT COP ; LDAA #$07 ;PUT COP AT WORK STAA COPCTL ;RESET OCCURS AFTER 1S INACTIVITY JSR COP_RESET ;_______________________________________________ ; ; Herätetään TCM, lähetetään komento ja luetaan ; data bufferiin sekä lähetetään RS232 väylälle ; MOVB #LCD1, OCH ; SELECT LCD1 LDAA #4 JSR LCDADDR ; CENTER TEXT LDX #BANNER JSR OSTRC ; PRINT IT ; MOVB #LCD2, OCH LDAA #9 JSR LCDADDR ; CENTER TEXT LDX #HUMTXT JSR OSTRC JSR DLY500 JSR COP_RESET ; MOVB #ALDL, OCH ; SELECT ALDL CHANELL LDX #COMMAND1 ; WAKE UP STRING ??? JSR OSTRB ; WAKE UP ALDL BUS JSR DLY100 ; WAIT 100 MS JSR DLY100 ; 200 IS NEDED IF FRAME COMES ANYWAY ; JSR COP_RESET ; ;___________________________________ MAIN: LDX #COMMAND1 ; READ DATA COMMAND MOVB #ALDL, OCH ; SELECT ALDL CHANELL JSR OSTRB ; SEND TO ALDL BUS ; MOVW #BUFFER, BUFNDX ; CAPTURE BUFFER ADDRESS JSR COP_RESET CLR DEBU ; CLEAR DEBUG INDICATOR LDAA SC1DRL ; CLEAR CARBAGE FROM ALDL IN ; MAIN1: MOVB #RS232, OCH ; SELECT RS232 OUTPUT JSR INCH1 ; READ FROM ALDL JSR OUTC ; ECHO TO RS232 BUS FOR PC ; CMPA HE1 ; WAIT FOR HEADER (1) BYTE BNE MAIN1 STAA CSUM ; START CHECKSUM CALCULATION MAIN2: MOVB #1, DEBU JSR INCH1 JSR OUTC ; CMPA HE2 ; WAIT FOR HEADER (2) BYTE BNE MAIN2 MOVB #2, DEBU ADDA CSUM ; CALCULATE CHECKSUM STAA CSUM ; ; START READING TO DATA BUFFER ; IF THIS FAILS (TAKES TOO LONG) COP RESTE OCCURES ; MOVW #BUFFER, BUFNDX ; CAPTURE BUFFER ADDRESS ; CAP0: JSR INCH1 ;DATA FROM ALDL BUS JSR OUTC ;ECHO ALSO TO RS232 BUS ; CAP1: LDX BUFNDX ;STORE DATA TO BUFFER A=DATA STAA 0,X ADDA CSUM ; CALCULATE CHECKSUM STAA CSUM CPX #BUFFE ;LAST BYTE ? BEQ CAP2 INX STX BUFNDX ;INCREMENT BUFFER INDEX BRA CAP0 ;MORE TO COME ; CAP2: JSR COP_RESET ;___________________________________ ; ; DISPLAY BUFFER DATA ; JSR LCD_CLR ; CLEAR LCD ; MOVB #LCD1, OCH ; OUTPUT TO UPPER LCD LDAA #0 ; ROW 0, POS 0 JSR LCDADDR ; BRSET PORTB, DIAG, NORM ; DIAG REQUEST ? JMP DDIS NORM: BRSET PORTB, DIAG2, NORM1 ; SECOND PAGE JMP NORM2 ;___________________________________ ; ; NORMAL DISPLAY PAGE 1 ; NORM1: LDX #ERTXT ;SHOW ENGINE RPM JSR OSTRC LDD ERPM JSR OUTRPM ; LDX #IRTXT ;SHOW INPUT RPM JSR OSTRC LDD IRPM JSR OUTRPM ; LDX #VSTXT ;SHOW VEHICLE SPEED JSR OSTRC LDAB SPEED JSR OUTSPEED ;________ LDAA #41 ; ROW 1, POS 0 JSR LCDADDR ; LDX #TRTXT ;SHOW TCC RPM JSR OSTRC LDD TRPM JSR OUTRPM ; LDX #ORTXT ;SHOW OUTPUT RPM JSR OSTRC LDD ORPM JSR OUTRPM ; LDX #TTTXT ; SHOW TRANS TEMP JSR OSTRC LDAB TTEMP JSR OUTTEMP ; ;______________________ MOVB #LCD2, OCH ; SELECT LOWER (SECOND) LCD LDAA #0 ; FIRST ROW, POS 0 JSR LCDADDR ; LDX #TSTXT ; SHOW TCC SLIP RPM JSR OSTRC LDD TCCSL JSR OUTTCC ; SHOW SIGNED VALUE ; LDX #BTXT ; SHOW BATTERY VOLTAGE JSR OSTRC LDAB BATT JSR OUTBATT LDX #TBTXT ; SHOW THROTTLE % JSR OSTRC LDAB TB JSR OUTPROS ;_____________ LDAA #41 ; SECOND ROW OF DISP 2, POS 0 JSR LCDADDR ; JSR OPRN ; PRINT SELECTOR JSR CGPRN ; SHOW CURRENT GEAR ; LDAB TB ; TEST BAR DISPLAY WITH THROTTLE JSR OUTBAR ; LBRA OVER ;_______________________ ; ; NORMAL DISPLAY SECOND PAGE ; NORM2: ; JSR CGPRN ; PRINT CURRENT GEAR ; LDAA #41 ; SECOND ROW OF DISP 2, POS 0 JSR LCDADDR ; JSR PRNBIT ; SHOW OTHER BITS ;___________________ MOVB #LCD2, OCH ; SELECT LOWER (SECOND) LCD LDAA #0 ; FIRST ROW, POS 0 JSR LCDADDR ; JSR PRNID ; SHOW PROM ID ; LDAA #41 ; SECOND ROW OF DISP 2, POS 0 JSR LCDADDR ; LDX #ADTXT ; SHOW A/D CONVERTERS JSR OSTRC CLRA LDY #ADR0H ; FIRST A/D CHANNELL JSR OUT10HEX ; SHOW 5 FIRST CONVERTERS ; LBRA OVER ;___________________________ ; ; DIAGNOSTIC DISPLAY PAGES ; DDIS: BRCLR PORTB, DIAG2, DDIS2 ; LDAA #$20 ; DIAG PRINTOUT IF DIAG=0 LDY #BUFFER+20 JSR OUT10HEX ; LDAA #41 ; ROW 1, POS 0 JSR LCDADDR LDAA #$30 ; DIAG PRINTOUT IF DIAG=0 LDY #BUFFER+30 JSR OUT10HEX ; MOVB #LCD2, OCH ; SELECT LOWER (SECOND) LCD LDAA #0 ; FIRST ROW, POS 0 JSR LCDADDR LDAA #$40 ; DIAG PRINTOUT IF DIAG=0 LDY #BUFFER+40 JSR OUT10HEX ; LDAA #41 ; SECOND ROW OF DISP 2, POS 0 JSR LCDADDR LDAA #$50 ; DIAG PRINTOUT IF DIAG=0 LDY #BUFFER+50 JSR OUT10HEX BRA OVER ;______________ DDIS2: LDAA #$60 ; DIAG PRINTOUT IF DIAG=0 LDY #BUFFER+60 JSR OUT10HEX ; LDAA #41 ; ROW 1, POS 0 JSR LCDADDR LDAA #$70 ; DIAG PRINTOUT IF DIAG=0 LDY #BUFFER+70 JSR OUT10HEX ; MOVB #LCD2, OCH ; SELECT LOWER (SECOND) LCD LDAA #0 ; FIRST ROW, POS 0 JSR LCDADDR LDAA #$80 ; DIAG PRINTOUT IF DIAG=0 LDY #BUFFER+80 JSR OUT10HEX ; LDX #CSTXT ; CHECKSUM JSR OSTRC LDAA CSUM JSR OUT2H ; LDAA #41 ; SECOND ROW OF DISP 2, POS 0 JSR LCDADDR ; LDAA #'#' JSR OUTC LDX #BUFFER LDAA KNOBV LEAX A,X ; SET WHERE TO DUSPLAY TAB PSHX JSR OUTSPEED ; SHOW INDEX IN DECIMAL PULX LDD 0,X JSR OUT4HS ; SHOW IN 16 BIT LDAA 0,X JSR OUT2HS ; SHOW 8 BIT LDAA 0,X JSR OUTBINS ; SHOW AS BINARY JSR OUTS LDAA KNOBV JSR OUT2HS LDAA BUTPR JSR OUT2HS ; BRA OVER ; LDAA #$00 ; DIAG PRINTOUT IF DIAG=0 LDY #BUFFER JSR OUT10HEX ; OVER: ;____________________________ ; JSR COP_RESET JSR DLY500 ; WAIT 500 MS JSR COP_RESET ; JMP MAIN ; NEW ROUND ;____________________________________________________________ ; ; FAULT PROCESSING ; THIS EXECUTES IF COP RESET OCCURES ; FLT: LDS #STACK ; initialize stack pointer CLR LCD_CTRL CLR LCD_DATA LDAB #$FF STAB DDRA ;A&B PORTS = OUTPUTS LDAB #%00011111 STAB DDRB ;B/D5 = DIAG INPUT ;B PULL UPS ARE ON JSR INITLCD JSR COP_RESET MOVB #LCD1, OCH ; OUTPUT TO UPPER LCD LDX #FAUTXT JSR OSTRC LDD BUFNDX ; SHOW WHERE WE STOPPED SUBD #BUFFER JSR OUT4HS LDAA DEBU JSR OUT2HS ; SHOW DEBUG POINTER JSR COP_RESET JSR DLY500 ;WAIT 500 MS JSR COP_RESET JSR DLY500 ;WAIT 500 MS JSR COP_RESET JSR DLY500 ;WAIT 500 MS JSR COP_RESET JMP START ; RESTART WHOLE THING ; ;____________________________________________________________ ; ; SERIAL CHANNELL SUBROUTINES. ACCUMULATORS ARE PRESERVED ; A = DATA ; OUTCH1: PSHB ; 1 = ALDL KANAVA OU1: LDAB SC1SR1 ANDB #$80 BEQ OU1 STAA SC1DRL ;MERKKI LAHTI PULB RTS ; OUTCH0: PSHB ; 0 = RS232 PAATEKANAVA OU0: LDAB SC0SR1 ANDB #$80 BEQ OU0 STAA SC0DRL ;MERKKI LAHTI PULB RTS ; INCH1: PSHB ; 1 = ALDL KANAVA INPUT INC1: LDAB SC1SR1 ANDB #%00100000 ;ONKO RDRF ? BEQ INC1 LDAA SC1DRL ;HAETAAN MERKKI PULB RTS ; INCH0: PSHB ; 0 = RS232 KANAVA INPUT INC0: LDAB SC0SR1 ANDB #%00100000 ;ONKO RDRF ? BEQ INC0 LDAA SC0DRL ;HAETAAN MERKKI PULB RTS ;_________________________________________________ ; ; GENERAL OUTPPUT CHARACTER ROUTINE ; A = CAHARACTER, OCH = CHANELL ; OUTC: PSHA LDAA OCH ; SELECT CHANELL CMPA #0 BNE OUTC1 PULA BRA OUTCH0 ; 0 = RS232 OUTC1 CMPA #1 BNE OUTC2 PULA BRA OUTCH1 ; 1 = ALDL OUTC2 CMPA #2 BNE OUTC3 PULA LBRA LCD_WRITE1 ; 2 = LCD1 OUTC3 PULA LBRA LCD_WRITE2 ; 3 = LCD2 ; ; OUTPUT ONE SPACE ; OUTS: LDAA #$20 BRA OUTC ;______________________________________________ ; ; OUTPUT 4 HEX CHARACTERS + SPACE FROM D OUT4HS: PSHB JSR OUT2H PULA ;SWAP BYTES BRA OUT2HS ;___________________________________________ ; OUTPUT 2 HEX CHARACTERS+ SPACE FROM A OUT2HS: PSHA JSR OUT2H LDAA #$20 JSR OUTC ; PUT TO GENERAL OUTPUT PULA RTS ;___________________________________ OUT2H: PSHA ANDA #$F0 LSRA ; SHIFT RIGHT & FILL WITH 0 LSRA LSRA LSRA JSR OUTH PULA ANDA #$0F JSR OUTH RTS ; OUTH: ORAA #$30 CMPA #$39 ;NUMBERS 0-9 BHI OUTH1 BRA OUTH2 OUTH1: ADDA #$07 ;MAKE IT A - F OUTH2: JSR OUTC ; PUT TO GENERAL OUTPUT RTS ; ;___________________________________________________ ; ; PRINT BINARY STRING POINTED BY X TO GENERAL OUTPUT ; FIRST BYTE OF STRING IS NUMBER OF BYTES ! ; OSTRB: LDAB 0,X ;HOW MANY TO GO ? INX OSTRB1: LDAA 0,X ;FETCH BYTE JSR OUTC ;PUT TO OUTPUT INX DECB BNE OSTRB1 RTS ; ; PRINT ASCII CHARACTER STRING POINTED BY X TO GENERAL OUTPT ; NUL (0) IS EOT ; OSTRC: LDAA 0,X ;FETCH BYTE BEQ OSTRC1 ; EOT JSR OUTC ;PUT TO OUTPUT INX BRA OSTRC OSTRC1: RTS ; ; PRINT ASCII CHARACTER STRING + 2 SPACES ; OSTRC2S: JSR OSTRC LDX #SSTR JSR OSTRC RTS ; ; PRINT 8 BIT VALUE IN BINARY FORMAT ; OUTBIN: PSHA STAA OB MOVB #8, OBCTR ; OUTB1: LDAA OB BMI OUTB2 LDAA #$30 ; 0 BRA OUTB3 OUTB2: LDAA #$31 ; 1 OUTB3: JSR OUTC ASL OB DEC OBCTR BNE OUTB1 PULA RTS ; OUTBINS: ; PRINT BINARY + SPACE JSR OUTBIN BRA OUTS ; ;________________________________________ ; ; SCALED TRANSMISSION VALUE OUTPUTS ; ; 16 - BIT VALUE IN D DIVIDED BY 8 ; D = OUTPUT VALUE ; OUTRPM: LDX #8 IDIV ;D/8 PSHX PULD ; TRANSFER OUTCOME TO D JSR CVBTD ; DO BIN => ASCII CONV JSR ZSUPP ; REMOVE LEADING ZEROS INX ; DROP MSB OFF JSR OSTRC2S ; PRINT CONVERTED CHARACTERS RTS ; ; 16 - BIT SIGNED VALUE IN D DIVIDED BY 8 ; D = OUTPUT VALUE ; OUTTCC: LDX #8 ; TCC SLIP IS SIGNED 16 BIT VALUE MOVB #$20, SIGN ; GUESS POSITIVE TSTA BPL OUTTC1 ; IS POSITIVE STD SAVEX LDD #$0000 SUBD SAVEX MOVB #$2D, SIGN ; IS NEGATIVE ; OUTTC1: IDIV ;D/8 SIGNED PSHX PULD ; TRANSFER OUTCOME TO D JSR CVBTD ; DO BIN => ASCII CONV JSR ZSUPP ; REMOVE LEADING ZEROS LDAA SIGN STAA 0,X ; WRITE SIGN OVER MSB JSR OSTRC2S ; PRINT CONVERTED CHARACTERS RTS ; ; VECHICLE SPEED 0 - 255 KPH ; B = OUTPUT VALUE ; OUTSPEED: CLRA JSR CVBTD INX INX JSR OSTRC2S ; PRINT CONVERTED CHARACTERS RTS ; ; BATTERY VOLTAGE 0 -25.5 v ; B = OUTPUT VALUE ; OUTBATT: CLRA JSR CVBTD ; DO BIN => ASCII CONV INX LDD 1,X STD 0,X LDAA #'.' STAA 2,X JSR OSTRC2S RTS ; ; THROTTLE % 0 - 99 % ; B = OUTPUT VALUE ; OUTPROS: LDAA #100 ; FIRST MULTIPLY BY 100 MUL ; A X B LDX #256 IDIV ; D / X PSHX PULD ; TRANSFER OUTCOME TO D JSR CVBTD ; DO BIN TO ASCII CONV INX INX ; REDUCE TO 3 DIGITS JSR OSTRC2S RTS ; ; TEMPERATURE DEGREES CELCIUS -40 - +215 ; B = TEMP OUTTEMP: CLRA ; PREPARE D FOR CONVERSION SUBB #40 ; SEE IF POSITIVE SIDE BHI OUTT1 ADDB #40 ; RSTORE ORIGINAL VALUE LDAA #40 SBA ; CALCULATE VALUE BELOW 0 TAB CLRA JSR CVBTD ; DO CONVERSION LDAA #'-' STAA 2,X BRA OUTT2 OUTT1: JSR CVBTD ; DO CONVERSION OUTT2: INX INX ; REDUCE TO 3 DIGITS JSR OSTRC2S RTS ; ; OUTPUT 10 BYTES IN HEX FORMAT ; A = HEADER NUMBER Y POINTS TO STRING ; OUT10HEX: PSHA LDAA #'#' JSR OUTC PULA JSR OUT2HS JSR OUTS ; PRINT HEADER FOR LINE ; MOVB #10, TEMP OUT101: LDAA 0,Y ; PRINT HEX BYTES POINTED BY Y JSR OUT2HS INY DEC TEMP BNE OUT101 RTS ; ; OUTPUT 0 - 26 LONG BAR ; B = 0 -255 INPUT VALUE ; OUTBAR: CLRA LDX #10 ; DIVIDE BY 10 IDIV PSHX PULD ; B = LOOP COUNT STAB TEMP INC TEMP LDAA #$FF ; BAR CHARACTER OBAR1: DEC TEMP BEQ OBAR2 ; EXIT JSR OUTC BRA OBAR1 OBAR2: RTS ; ; OUTPUT GEAR SELECTOR LABEL ; READ SELECTOR BITS FROM PRBIT ; OPRN: LDAB PRBIT ; GET SWITCH ETC BITS ANDB #PRNMASK ; ADJUST SHIFT BITS TO INDEX LSRB ; LEAVE IT 2 x VALUE FOR WORD LOOKUP LDX #PRNOD ; COMPUTE AND LOAD LDX B,X ; CORRECT TEXT STRING ADDRESS TO X JSR OSTRC ; OUTPUT SELECTOR LABEL RTS ; PRNOD: FDB #XTXT ; 0 = ILLEGAL VALUE FDB #ODTXT FDB #XTXT ; 2 = ILLEGAL FDB #DTXT FDB #RTXT FDB #PTXT ; 6 = PARK / NEUTRAL FDB #ITXT FDB #IITXT ; ; SHOW CURRENT GEAR VALUE ; CGPRN: LDX #CGTXT ; SHOW CURRENT GEAR JSR OSTRC LDAA CGEAR INCA ; ADJUST VALUE JSR OUT2HS JSR OUTS ; ADJUST LENGTH RTS ; ; SHOW PROM ID ; PRNID: LDX #PRTXT ; SHOW PROM ID JSR OSTRC LDD PROMID JSR OUT4HS JSR OUTS ; ADJUST LENGTH RTS ; ; SHOW MISELANOUS BITS AC & BRAKE ; PRNBIT: BRCLR BBITS, BREQ, BITP1 LDX #BRRTXT JSR OSTRC ; BITP1: BRSET PRBIT, BRAKE, BITP2 LDX #BRTXT JSR OSTRC ; BITP2: BRCLR BBITS, ACREQ, BITP3 LDX #ACRTXT JSR OSTRC ; BITP3: BRCLR PRBIT, ACON, BITP4 LDX #ACTXT JSR OSTRC ; BITP4: RTS ;_________________________________________ ; ; LCD DISPLAY SUBROUTINES ; ; VAR_DELAY: LDAB #199 ; 100 ys DELAY @ 8MHz L1: NOP DBNE B, L1 DEC TIME BNE VAR_DELAY RTS LCD_WRITE1: ;THIS ROUTINE WRITES 4 X 40 UPPER HALF ;& NORMAL DISPLAYS STAA LCD_DATA ;LCD WRITE BYTE BSET LCD_CTRL, E+E1 NOP BCLR LCD_CTRL, E+E1 BRA L20 ; LCD_WRITE2: ;THIS ROUTINE WRITES 4 X 40 LOWER HALF STAA LCD_DATA ;LCD WRITE BYTE BSET LCD_CTRL, E2 NOP BCLR LCD_CTRL, E2 BRA L20 ; LCD_WRITE: ;THIS ROUTINE WRITES ALL DISPLAYS STAA LCD_DATA ;LCD WRITE BYTE BSET LCD_CTRL, E+E1+E2 NOP BCLR LCD_CTRL, E+E1+E2 L20: LDAA #120 ;#107 ; 40 ys DELAY L2: DBNE A, L2 RTS ;_______________________________ ; ; SETS LCD CURSOR ADDRESS ACCORDING OCH SELECTOR ; A = ADDRESS, DESTROYS B ; LCDADDR: LDAB OCH CMPB #LCD1 BEQ LCD_ADDR1 BRA LCD_ADDR2 ; LCD_ADDR1: ;THIS ROUTINE SETS ADDRESS FOR UPPER ; HALF & NORMAL DISPLAYS BCLR LCD_CTRL, RS ;SEND LCD ADDRESS ORAA #$80 ; D7 = ALLWAYS 1 STAA LCD_DATA BSET LCD_CTRL, E+E1 NOP BCLR LCD_CTRL, E+E1 BRA L40 LCD_ADDR2: ;THIS ROUTINE SETS ADDRESS FOR LOWER ;HALF OF 4 X 40 DISPLAY BCLR LCD_CTRL, RS ;SEND LCD ADDRESS ORAA #$80 ; D7 = ALLWAYS 1 STAA LCD_DATA BSET LCD_CTRL, E2 NOP BCLR LCD_CTRL, E2 BRA L40 ; LCD_ADDRB: ;THIS ROUTINE SETS ADDRESS FOR ALL DISPLAYS BCLR LCD_CTRL, RS ;SEND LCD ADDRESS ORAA #$80 ; D7 = ALLWAYS 1 STAA LCD_DATA BSET LCD_CTRL, E+E1+E2 NOP BCLR LCD_CTRL, E+E1+E2 L40: LDAA #160 ; 40+ ys DELAY L4: DBNE A, L4 ; BSET LCD_CTRL, RS ; SET TO DATA MODE ; LDAA #106 ; 40 ys DELAY L41: DBNE A, L41 RTS ; LCD_CLR: ;CLEARS ALL DISPLAYS BCLR LCD_CTRL, RS ; SET LCD TO COMMAND MODE LDAA #$01 ; CLEAR DISPLAY, SET CURSOR ADDR = 0 STAA LCD_DATA BSET LCD_CTRL, E+E1+E2 NOP BCLR LCD_CTRL, E+E1+E2 MOVB #25, TIME ; WAIT 2.5 ms JSR VAR_DELAY BSET LCD_CTRL, RS ; BACK TO DATA MODE RTS ;___________________ ; INITLCD: ; INIT ALL DISPLAYS MOVB #150, TIME ;WAIT 15ms JSR VAR_DELAY ; MOVB #$38, LCD_DATA ;LCD INIT COMMAND BSET LCD_CTRL, E+E1+E2 ;ALL DISPLAYS NOP BCLR LCD_CTRL, E+E1+E2 ; MOVB #41, TIME ;WAIT 4.1 ms JSR VAR_DELAY ; MOVB #$38, LCD_DATA ;LCD SECOND INIT COMMAND BSET LCD_CTRL, E+E1+E2 NOP BCLR LCD_CTRL, E+E1+E2 ; MOVB #1, TIME ;WAIT 100 ys JSR VAR_DELAY ; LDAA #$38 ;THIRD LCD INIT COMMAND JSR LCD_WRITE ;LCD MODULE ACCEPTS WRITES ; FUNCTION SET COMMAND ; 8-BIT BUS, 2 ROWS, 5X7 MATRIX LDAA #$38 ; DISPLAY ON, CURSOR OFF, NO BLINK JSR LCD_WRITE LDAA #$0C JSR LCD_WRITE LDAA #$01 ; CLEAR DISPLAY, SET CURSOR ADDR = 0 JSR LCD_WRITE MOVB #18, TIME ; WAIT 1.8 ms JSR VAR_DELAY LDAA #$06 ; INCREMENT, NO DISPLAY SHIFT JSR LCD_WRITE ; BSET LCD_CTRL, RS ; SET LCD DATA MODE RTS ; ; ;________________________________________ *REVISION1 *CONVERTBINARY TO DECIMAL & STORE 5 CHAR *CALLINGSEQUENCE *(A,B) BINARY VALUE *(X) POINTER TO STORE DECIMAL CHARS *JSR CVBTD CONVERT ; CVBTD LDX #ASCIIC STX SAVEX ; SAVE DATA POINTER LDX #K10K ; (X) POINTER TO CONSTANTS CVDEC1 CLR SAVEA ; INZ DEC CHAR CVDEC2 SUBB 1,X SBCA 0,X BCS CVDEC5 ; OVERFLOW INC SAVEA ; INC CHAR BEING BUILT BRA CVDEC2 CVDEC5 ADDB 1,X ; RESTORE PARTICAL RESULT ADCA 0,X PSHA STX SAVEX1 LDX SAVEX ; X-STORE CHAR POINTER LDAA SAVEA ADDA #$30 ; MAKE ASCII CHAR STAA 0,X PULA RESTORE A INX STX SAVEX LDX SAVEX1 ; X-POINTER TO CONSTANTS INX INX CPX #K10K+10 BNE CVDEC1 LDX #ASCIIC RTS *CONSTANTSFOR CONVERSION K10K FDB 10000 FDB 1000 FDB 100 FDB 10 FDB 1 ; ; SUPPRESS 4 LEADING ZEROS IN ASCII CONVERSION BUFFER ; ZSUPP: LDAB #$20 ; SPACE LDAA #$30 ; TEST IF 0 CMPA 0,X BNE ZSUP9 STAB 0,X CMPA 1,X BNE ZSUP9 STAB 1,X CMPA 2,X BNE ZSUP9 STAB 2,X CMPA 3,X BNE ZSUP9 STAB 3,X ZSUP9: RTS ; BUFINIT: LDX #BUFFER LDAA #00 BUFI1: STAA 0,X CPX #BUFFE BEQ BUFI2 INX BRA BUFI1 BUFI2: RTS ; ; DELAY LOOPS ; DLY100: LDX #1000 ;DELAY 100 MS STX DLYCTR BRA VARDEL ; DLY500: LDX #5000 ;500 MS DELAY STX DLYCTR BRA VARDEL ; VARDEL: LDX DLYCTR ;SET DELAY L00: LDAB #199 ;VARIABLE DELAY DLYCTR * 100YS L11: NOP DBNE B, L11 DEX BNE L00 RTS ; ; WATCH DOG RESET ; COP_RESET: ldaa #$55 ; get 1st COP reset value staa COPRST ; store it ldaa #$AA ; get 2nd COP reset value staa COPRST ; store it rts ;___________________________________________________ ; ; Interrupt routines ; ; Selector knob routines ; KEYINT: SEI ; PREVENT RECURSIVE IRQ S ; BRCLR KWIFD, BUT, NOTBUT INC BUTPR ; TEST SELECT BUTTON FIRST ; NOTBUT: BRCLR KWIFD, FA, ISFB ; TEST IF PHASE A BRCLR PORTD, FB, NOTFAI INC KNOBV BRA NOTFN NOTFAI: DEC KNOBV BRA NOTFN ; ISFB: BRCLR KWIFD, FB, NOTFN ; TEST IF PHASE B BRCLR PORTD, FA, NOTFBD DEC KNOBV BRA NOTFN NOTFBD: INC KNOBV ; NOTFN: LDAA KWIFD STAA KWIFD ; RESET INTERRUPTS NOP NOP CLI ; ENABLE INTERRUPTS RTI ; ; ;_______________________________________________________ ; ; COMMAND STRINGS ; COMMAND1: ; READ DATA COMAND FCB 5 ; NUMBER OF BYTES ; FCB $F5 FCB $57 FCB $01 FCB $00 FCB $B3 ; COMMAND CHECKSUM ; COMMAND2: ; CLEAR CODES COMMAND FCB 4 ; FCB $F5 FCB $56 FCB $0A FCB $AB ; COMMAND CHECKSUM ; ; HEADER BYTES ; HE1: FCB $F5 HE2: FCB $AB ; ; OTHER STRINGS ; ADTXT: FCC 'A/D ' FCB 0 FAUTXT: FCC 'Fault COP interrupt ' FCB 0 CSTXT: FCC 'Cs=' FCB 0 BANNER: FCC 'JN ALDL display 20.2.1999 v. 1.1' FCB 0 HUMTXT: FCC 'for Hummer TCM readout' FCB 0 SSTR: FCC ' ' ; 2 SPACES FCB 0 PRTXT: FCC 'Prom ID ' FCB 0 BTXT: FCC 'Batt. V ' FCB 0 ERTXT: FCC 'Eng RPM ' FCB 0 TRTXT: FCC 'TCC RPM ' FCB 0 IRTXT: FCC 'Inp RPM ' FCB 0 ORTXT: FCC 'Out RPM ' FCB 0 TBTXT: FCC 'Thro % ' FCB 0 TTTXT: FCC 'T-temp ' FCB 0 VSTXT: FCC 'VSpeed ' FCB 0 TSTXT: FCC 'TCCslp ' FCB 0 CGTXT: FCC 'CGr= ' FCB 0 PTXT FCC 'P/N ' ; GEAR SELECTOR STRINGS FCB 0 RTXT FCC 'R ' FCB 0 ODTXT FCC 'OD ' FCB 0 DTXT FCC 'D ' FCB 0 IITXT FCC '2 ' FCB 0 ITXT FCC '1 ' FCB 0 XTXT FCC '??? ' ; UNKNOWN / ILLEGAL POSITION FCB 0 BRRTXT FCC 'Brake_req ' FCB 0 ACRTXT FCC 'AC_req ' FCB 0 BRTXT FCC 'Brake_ON ' FCB 0 ACTXT FCC 'AC_ON ' FCB 0 ; ;____________________________________ ; VECTORS ; ORG $FFF2 ;KEY INT VECTOR IRQV FDB KEYINT XIRQV FDB START SWIV FDB START TRAPV FDB START COPFAIV FDB FLT ;COP FAILURE RESTART COPCLOV FDB FLT ;COP CLOCK MONITOR RESTART RESETV FDB START ;RESTART VECTOR ; END