*68HC705C8 REMOTE DISPLAY
*FOR TS-140 Transceiver, and other Kenwood HF Transceivers 
*VERSION 4.6  
*OCTOBER 14, 1995
*Steven N. Bienvenu, NB5F
*Allows optional display of tenths of khz. in single-freq. mode 
*(switchable on-the-fly) by grounding pin 4 @ micro/pullup junct.
*COPYRIGHT 1995; this program may NOT be used or altered for
*commercial purposes or sale, without express permission of the
*author
          
*    Register Equates          
          
PORTA     EQU  $00       LCD DATA/CONTROL PORTS              
PORTB     EQU  $01       EQUATES   
DDRA      EQU  $04          
DDRB      EQU  $05
DDRC      EQU  $06 
                     
BRATE     EQU  $0D       SCI  EQUATES 
SCCR1     EQU  $0E 
SCCR2     EQU  $0F 
SCSR      EQU  $10 
SCDAT     EQU  $11 
 
*    Ram Equates          
          
TEMPA     EQU  $51       ONE BYTE TEMPORARY STORAGE          
TEMPX     EQU  $52       ONE BYTE TEMPORARY STORAGE          
TEMPS     EQU  $53       "SPLIT BLANKED?" FLAG     
TEMPV     EQU  $54       ONE BYTE TEMPORARY STORAGE
TEMPT     EQU  $55       "TENTHS KHZ DIGIT NEED BLANKING?" FLAG
VFO       EQU  $56       VFO DATA BYTE, TEMP. STRG 
 
*    RESERVE RECEIVED DATA MEMORY AREAS 
          
          ORG  $60
 
RDATA     RMB  $28        RESERVES 40 BYTES FOR                  
*                          INPUT DATA
 
RDATB     RMB  $D         RESERVES 13 DATA BYTES
 
 
          ORG  $100       BEGINS PROG @ THIS ADDR          
          
*    SET PORT DATA BIT PATTERNS AND DIRECTIONS          
          
DDREX      LDA  #$07                
           STA  DDRA      PORT A (OUTPUTS: 0-2; INPUTS: 3-7)
           LDA  #$FF
           STA  DDRB      PORT B (ALL OUTPUTS)          
  
         
*    INITIALIZE LCD DISPLAY  
                                                                 
          JSR  LCDLY         DELAY FOR VOLTAGE STABILIZATION
          LDA  #%00110000     
          JSR  WCTRL2             (SOFTWARE
          LDA  #%00110000      
          JSR  WCTRL2             LCD MODULE
          LDA  #%00110000
          JSR  WCTRL2             INITIALIZATION)
          LDA  #%00111000
          JSR  WCTRL2
          LDA  #%00001000
          JSR  WCTRL2
          LDA  #%00000001
          JSR  WCTRL2
          LDA  #%00000110
          JSR  WCTRL2
          LDA  #%00001100     ....TURNS DISPLAY BACK ON
          JSR  WCTRL2
          
          
          LDA  #$00           ASSURES BITS CLEAR
          STA  VFO            FOR LATER TESTING
          
          LDA  #0             CLEAR "SPLIT BLANKED?" FLAG
          STA  TEMPS
          BCLR 0,TEMPT        CLEAR TENTHS KHZ FLAG
*    INITIALIZE SCI 
 
SCIINIT   LDA  #%00110000     SET BAUD RATE 4800 
          STA  BRATE             ( @ 2 MHZ XTAL) 
          LDA  #%01010000     SET SCCR1 TO 9 BITS 
          STA  SCCR1          (GIVES XTRA STOP BIT) 
          LDA  #%00001100     ENABLE SCI RX/TX            
          STA  SCCR2 
 
 
 
*    COMMUNICATIONS ROUTINES 
 
CMD1      FCC  'IF;+'   "INFO" REQ. COMMAND STRING 
CMD2      FCC  'FB;+'    VFO "B" FREQ REQ.  
CMD3      FCC  'FA;+'    VFO "A" FREQ REQ.
GETREDY   CLRX 
SEND      LDA  CMD1,X    SEND INFO REQUEST    
          CMP  #'+       END OF CMD STRING?          
          BEQ  SETSTRT   THEN GET RESPONSE
 
SENDATA   BRCLR  7,SCSR,SENDATA 
          STA    SCDAT 
          INCX 
          BRA  SEND
                                                                 
 
SETSTRT   CLRX   
GETDATA   BRCLR 5,SCSR,GETDATA     RDRF=1? 
          LDA   SCDAT             OK, GET DATA.
          CMP   #'I               CKS FOR PROPER
          BEQ   GOODATA           1ST CHAR. OF STRG
          BRA   GETDATA
AGAIN     BRCLR 5,SCSR,AGAIN
          LDA   SCDAT    
GOODATA   STA   RDATA,X       
          CPX   #37
          BEQ   SWITCH
          INCX
          BRA   AGAIN
         
SWITCH    LDX   #32
          LDA   RDATA,X
          CMP   #'0
          BEQ   JUMP
          BRCLR 5,VFO,IFEMPTY
          JMP   CON             LOADS VFO BYTE IF           
IFEMPTY   LDX   #30             SPLIT IS ON WHEN
          LDA   RDATA,X         RADIO TURNED ON
          STA   VFO 
CON       JMP   CONTIN
                    
JUMP      JMP   OPT1
 
CONTIN    LDX   #30
          LDA   RDATA,X
          CMP   #'0
          BEQ   FB            REQUESTS B IF OP FREQ=A
 
          CLRX
SEND2     LDA   CMD3,X        REQUESTS "A"
          CMP   #'+
          BEQ   BEGIN
SENDATA2  BRCLR 7,SCSR,SENDATA2
          STA   SCDAT
          INCX
          BRA   SEND2
 
FB        CLRX
SEND3     LDA   CMD2,X        REQUESTS "B"
          CMP   #'+
          BEQ   BEGIN
SENDATA3  BRCLR 7,SCSR,SENDATA3
          STA   SCDAT
          INCX
          BRA   SEND3
 
BEGIN     CLRX
DATAGET   BRCLR 5,SCSR,DATAGET     NEW OP FREQ
          LDA   SCDAT              DISP. ROUTINE  
          STA   RDATB,X
          CPX   #13
          BEQ   SWAP
          INCX
          BRA   DATAGET
 
SWAP      LDX   #30
          LDA   RDATA,X
          CMP   VFO
          BEQ   DISPLAY2      IF VFO UNCHANGED,
          LDA   #$C5           PRINT SAME LOC LCD;
          JSR   WCTRL         OTHERWISE, SWITCH 
          JMP   BOT            LOCATIONS
 
DISPLAY2  LDA   #$85
          JSR   WCTRL
BOT       LDX   #5
          LDA   RDATA,X
          CMP   #'0
          BEQ   BLANK
          JSR   DISLET
LOOP      INCX
          CPX   #10
          BEQ   LAST
          LDA   RDATA,X
          JSR   DISLET
          BRA   LOOP
 
BLANK     LDA   #' '
          JSR   DISLET
          BRA   LOOP
 
LAST      LDA   #'.
          JSR   DISLET
          LDA   RDATA,X
          JSR   DISLET
          LDA   #'<
          JSR   DISLET
 
          LDX   #30
          LDA   RDATA,X
          CMP   VFO
          BEQ   DISFB         IF VFO NOT CHANGED,
          LDA   #$85          PRINT @ SAME SPOT;
          JSR   WCTRL         OTHERWISE, SWITCH
          JMP   TOP
 
DISFB     LDA   #$C5
          JSR   WCTRL
TOP       LDX   #5        
          LDA   RDATB,X
          CMP   #'0
          BEQ   BLANK2
          JSR   DISLET
LOOP2     INCX
          CPX   #10
          BEQ   LAST2
          LDA   RDATB,X
          JSR   DISLET
          BRA   LOOP2
 
BLANK2    LDA   #' '
          JSR   DISLET
          BRA   LOOP2
 
LAST2     LDA   #'.
          JSR   DISLET
          LDA   RDATB,X
          JSR   DISLET
          LDA   #' '
          JSR   DISLET
          JMP   MODE
 
 
*****************************          
*        SUBROUTINES        *                     
*****************************          
 
OPT1      BRCLR 7,PORTA,OPT1a        SW. TO DEC. KHZ. DISPLAY?
          
          BRSET 0,TEMPT,BLANKDEC     NEED BLANK TENTHS KHZ POS.?
DISPLAY   LDX   #5
PRINT     LDA   #$85 
          JSR   WCTRL         ROUTINE CHECKS FOR 
          LDA   RDATA,X       ONE OR TWO-DIGIT
          CMP   #'0           MHZ, THEN PRINTS                   
          BEQ   PRINT2        FREQUENCY
          LDA   RDATA,X       
          JSR   DISLET
          INCX
          LDA   RDATA,X
          JSR   DISLET
          LDA   #'.
          JSR   DISLET
 
PRINTLP   INCX
          CPX   #10
          BEQ   MODE
          LDA   RDATA,X
          JSR   DISLET
          BRA   PRINTLP
 
PRINT2    LDA   #' '       ERASES LEADING ZERO
          JSR   DISLET
          INCX
          LDA   RDATA,X
          JSR   DISLET
          LDA   #'.
          JSR   DISLET
PRINTLP2  INCX
          CPX   #10
          BEQ   MODE
          LDA   RDATA,X
          JSR   DISLET
          BRA   PRINTLP2
 
BLANKDEC  LDA   #$8B          BLANKS TENTHS KHZ IF CALLED
          JSR   WCTRL
          LDA   #' '
          JSR   DISLET
          JMP   DISPLAY
 
OPT1a     LDX   #5            OPTIONAL DISPLAY FORMAT ROUTINE
          LDA   #$85               (TENTHS OF KHZ)
          JSR   WCTRL
          LDA   RDATA,X
          CMP   #'0
          BEQ   OPT1b
          JSR   DISLET
          JMP   OPT1c
 
OPT1b     LDA   #' '          ERASES TENS DIGIT
          JSR   DISLET
OPT1c     INCX
          LDA   RDATA,X
          JSR   DISLET
          CPX   #9
          BNE   OPT1c
          LDA   #'.
          JSR   DISLET
          INCX
          LDA   RDATA,X       PRINT TENTHS OF KHZ
          JSR   DISLET
          BSET  0,TEMPT       
 
MODE      LDA   #$C0
          JSR   WCTRL
          LDX   #29
          LDA   RDATA,X       
          CMP   #'1           MODE DETECTION
          BEQ   LSB
          CMP   #'2            AND DISPLAY
          BEQ   USB
          CMP   #'3
          BEQ   CW
          CMP   #'4
          BEQ   FM
          CMP   #'5
          BEQ   AM
          CMP   #'7
          BEQ   CWN
 
LSB       LDA   #'L
          JSR   DISLET
          LDA   #'S
          JSR   DISLET
          LDA   #'B
          JSR   DISLET
          JMP   RIT
          
USB       LDA   #'U
          JSR   DISLET
          LDA   #'S
          JSR   DISLET
          LDA   #'B
          JSR   DISLET
          JMP   RIT
 
CW        LDA   #'C
          JSR   DISLET
          LDA   #'W
          JSR   DISLET
          LDA   #' '
          JSR   DISLET
          JMP   RIT
 
FM        LDA   #'F
          JSR   DISLET
          LDA   #'M
          JSR   DISLET
          LDA   #' '
          JSR   DISLET
          JMP   RIT
 
AM        LDA   #'A
          JSR   DISLET
          LDA   #'M
          JSR   DISLET
          LDA   #' '
          JSR   DISLET
          JMP   RIT
 
CWN       LDA   #'C
          JSR   DISLET
          LDA   #'W
          JSR   DISLET
          LDA   #'N
          JSR   DISLET
          JMP   RIT
 
RIT       LDA   #$8D       DISPLAYS "RIT" IF ON
          JSR   WCTRL
          LDX   #23
          LDA   RDATA,X
          CMP   #'0
          BEQ   RETPROG    TO RETURN TO MAIN STREAM
          LDA   #'R        AND TURN OFF RIT DISPLAY
          JSR   DISLET
          LDA   #'I
          JSR   DISLET
          LDA   #'T
          JSR   DISLET
          JMP   SPLIT
 
RETPROG   LDA   #' '       TURNS OFF RIT DISPLAY
          JSR   DISLET
          LDA   #' '
          JSR   DISLET
          LDA   #' '
          JSR   DISLET
 
SPLIT     LDA   #$80
          JSR   WCTRL
          LDX   #32
          LDA   RDATA,X
          CMP   #'0
          BEQ   SPLITOFF
          LDA   #'S
          JSR   DISLET
          LDA   #'P
          JSR   DISLET
          LDA   #'L
          JSR   DISLET
          LDA   #'T
          JSR   DISLET
          LDA   #1
          STA   TEMPS              SETS "BLANKED?" FLAG
          JMP   GETREDY
 
 
SPLITOFF  BRCLR 0,TEMPS,RECYCLE    ALREADY BLANKED?
          LDA   #' '              BLANKS SPLIT DISPLAY
          JSR   DISLET
          LDA   #' '
          JSR   DISLET
          LDA   #' '
          JSR   DISLET
          LDA   #' '
          JSR   DISLET
          LDA   #$C5
          JSR   WCTRL
          LDX   #8
BLANKSPLT LDA   #' '
          JSR   DISLET
          DECX
          BNE   BLANKSPLT
          BRCLR 7,PORTA,POINTER    IF ONLY POINTER NEEDS BLANKING
          LDA   #$8B
          JSR   WCTRL
          LDA   #' '
          JSR   DISLET
          LDA   #' '
          JSR   DISLET
FINISH    LDA   #0
          STA   TEMPS      CLEARS "BLANKED?" FLAG
          LDX   #30        LOADS VFO BYTE
          LDA   RDATA,X
          STA   VFO
RECYCLE   JMP   GETREDY
 
POINTER   LDA   #$8C       BLANK ONLY THE POINTER, THEN
          JSR   WCTRL         RETURN TO BLANKSPLIT ROUTINE
          LDA   #' '
          JSR   DISLET
          JMP   FINISH
 
 
WCTRL     STX  TEMPX      SAVE X                              
          STA  PORTB      WRITE CONTROL WORD TO BUS          
          BCLR 1,PORTA    SET R/W TO WRITE          
          BCLR 2,PORTA    SET RS TO CONTROL          
          BSET 0,PORTA    ENABLE ON          
          BCLR 0,PORTA    ENABLE OFF          
          LDX  #$07       ]          
DELAY2    DECX            ]       DELAY          
          BNE  DELAY2     ]        FOR          
          CMP  #$02       ]       CONTROL          
          BHI  DELAY4     ]       (42uS)  
           
DELAY3    DECX            XTRA DELAY, FOR CMDS 1&2 
          BNE  DELAY3      (1.644 mS)
          LDX  #$12        
MORE      DECX            
          BNE  MORE
DELAY4    LDX  TEMPX      RESTORE INDEX REGISTER         
ENDCTRL   RTS             RETURN FROM SUBROUTINE         
  
WCTRL2    STX   TEMPX      SAVE X                              
          STA   PORTB      WRITE CONTROL WORD TO BUS          
          BCLR  1,PORTA    SET R/W TO WRITE          
          BCLR  2,PORTA    SET RS TO CONTROL          
          BSET  0,PORTA    ENABLE ON          
          BCLR  0,PORTA    ENABLE OFF          
          LDA   #$03       }
OUT1      CLRX             }    
DELAY5    DECX             }               
          BNE   DELAY5     }  4.6 ms DELAY               
          DECA             }
          BNE   OUT1       }
          LDX   TEMPX      }
          RTS       
                           
  
DISLET    STX   TEMPX     SAVE INDEX REGISTER         
          STA   PORTB     PUT CHARACTER ON BUS         
          BCLR  1,PORTA   SET R/W TO WRITE         
          BSET  2,PORTA   SET RS TO DATA         
          BSET  0,PORTA   TURN ON ENABLE  
          BCLR  0,PORTA   ENABLE OFF         
          LDX   #$07      ]       DELAY 42 uS         
DELAY1    DECX            ]       ASSUMING 1 uS          
          BNE   DELAY1    ]       CLOCK         
          LDX   TEMPX     RESTORE INDEX REGISTER           
          RTS             RETURN FROM SUBROUTINE         
      
 
LCDLY     STX  TEMPX     SAVE X        
  
          LDA  #15       : (DELAY UNTIL LCD READY) 
OUTLP     CLRX           :  X USED AS INNER LOOP 
INNERLP   DECX           :     COUNTER...
          BNE  INNERLP   :  6CYC*256*1uS=1.536ms        
          DECA        
          BNE  OUTLP     :  15*1.536ms=23.04ms DELAY         
          LDX  TEMPX     RESTORE X        
          RTS            RETURN FROM SUBROUTINE        
  
  
          ORG  $1FFE     PROVIDING RESET VECTOR                 
          FDB  DDREX     WITH THESE TWO LINES... 

