;THIS PROGRAM IS HT1621 LCD DISPLAY
;VDD=5.0V  IF VDD<5.0V	PLEASE TO DELAY
;RECEIVE AND TRANSMIT BYTR'TIME
;
FSR	EQU	4H
RB	EQU	6H
GENR0	EQU	09H
GENR1	EQU	0AH
WD_RG	EQU	0BH

;the registers of LCD DISPLAY DATA
DA_AG0	EQU	10H  ;SEG0 SEG1
DA_AGF	EQU	1FH  ;SEG30 SEG31
;
;RB BITS
CS	EQU	 0   ;ABLE BIT
WDA	EQU	 1   ;DATA PORT
WCLK	EQU	 2   ;WRITE COLK
RCLK	EQU	 3   ;READ COLK
;
;the VALUE of LCD work mode
BISA	EQU	 52H ; 1/3 bisa  4 COM
;
;----------------
;the table of HT1621 WORK MODE VALUE
ON_VALUE
	ADDWF	2
	RETLW	06H	;LCD ON
	RETLW	02H	;SYS ON

	RETLW	10H	;TONE OFF
	RETLW	BISA	;BISA1/3  4 COM
	RETLW	28H	;32K XTAL
	RETLW	0AH	;WDT DISABLE

	RETLW	00	;/IRQ DISABLE  *
	RETLW	0C6H	;NORMAL MODE   *

;-------
;TRANSMIT BITS SUBROUTINE
;fristly  transmit high bit of byte
TRAM_DATA
	MOVWF	GENR0

	BCF	RB,WCLK
	RLF	WD_RG
	BTFSS	3,0
	GOTO	$+3

	BSF	RB,WDA
	GOTO	$+2

	BCF	RB,WDA

	NOP
	NOP
	BSF	RB,WCLK

	NOP
	NOP
	NOP
	NOP
	NOP
	BCF	RB,WCLK
	DECFSZ	GENR0
	GOTO	TRAM_DATA+1
	RETLW	0
;-------
;RECEIVING BITS SUBROUTINE
;fristly  receive high bit of byte
RCIV_DATA
	BCF	RB,RCLK

	NOP
	NOP
	NOP
	NOP
	BSF	RB,RCLK
	NOP
	NOP

	BTFSS	RB,WDA
	GOTO	$+3
	BSF	3,0
	GOTO	$+2

	BCF	3,0
	RLF	0H
	DECFSZ	GENR0
	GOTO	RCIV_DATA
	RETLW	0
;
;-------
;TRANSMIT CONTROL CODES OF LCD DISPLAY SUBROUTINE
ON_LCD
	MOVWF	GENR1

	MOVLW	80H	 ;HI_W3 BITS:100
	MOVWF	WD_RG

	MOVLW	3
	CALL	TRAM_DATA
ON_LCD0
	MOVLW	7H
	SUBWF	GENR1,W
	MOVLW	00H	 ;HI_W1 BIT: 0
	BTFSC	3,0
	MOVLW	10H	 ;HI_W1 BIT: 1
	MOVWF	WD_RG

	MOVLW	1H
	CALL	TRAM_DATA

	MOVFW	GENR1
	CALL	ON_VALUE ;LO_8 BITS
	MOVWF	WD_RG

	MOVLW	8
	CALL	TRAM_DATA

	DECFSZ	GENR1
	GOTO	ON_LCD0
	RETLW	0
;
;TRANSMIT DISPLAY DATAES SUBROUTINE
DIS_DATA
	MOVWF	GENR1
	MOVLW	0A0H
	MOVWF	WD_RG	;WRITE CONTROL

	MOVLW	3H
	CALL	TRAM_DATA

	MOVLW	00
	MOVWF	WD_RG	;WRITE ADDRESS
	MOVLW	6H
	CALL	TRAM_DATA

      ; MOVLW	DA_AG0-1
      ; MOVWF	FSR
DIS_DATA0
	INCF	FSR
	MOVFW	0H
	MOVWF	WD_RG	;DISPLAY CODE

	MOVLW	8
	CALL	TRAM_DATA

	DECFSZ	GENR1	;DISPLAY WHICH SEGMENT REGSTER
	GOTO	DIS_DATA0
	RETLW	0H
;==========================
;
;because in the HT1621 command code'high bit and memory
;address code'high-bit is fristly transmitted,and
;data'low-bit is fristly transmitted and received, but
;this program fristly transmit and receiv high-bit.
;please to attenate display dataes assemble'modle.
;
;INTITIALIZE PORT_B
	MOVLW	0F0H
	TRIS	RB
	MOVLW	0FH
	MOVWF	RB

	MOVLW	4	; CPU OSC=4MHz
	OPTION
;
;SET HT1621 WORK MODE
	BCF	RB,CS	;CS=0
	MOVLW	8H
	CALL	ON_LCD	;TRANSMIT HT1621 WORK MODE VALUE
	MOVLW	0FH
	IORWF	RB	;CS=1
	NOP
;
;==========================
;WRITE OPERATION
;DISPLAY DATA PUT IN DA_AG0(10H) REGSTER TO DA_AGF(1FH) REGISTER
	BCF	RB,CS	;CS=0

	MOVLW	DA_AG0-1 ;DISPLAY SEGMENT REGSTER
	MOVWF	FSR
	MOVLW	10H	 ;32 SEGMENTS
	call	DIS_DATA

	MOVLW	0FH	;CS=1
	IORWF	RB
;
;==========================
;READ OPERATION
	MOVLW	0C0H
	MOVWF	WD_RG	;WRITE CONTROL

	BCF	RB,CS
	MOVLW	3H
	CALL	TRAM_DATA

	MOVLW	00
	MOVWF	WD_RG	;WRITE ADDRESS
	MOVLW	6H
	CALL	TRAM_DATA
;
;READ OUT DATAES PUT IN DA_AG0(10H) TO DA_AGF(1FH) REGSTER
	BSF	RB,WCLK

	MOVLW	10H	;32 SEGMENTS
	MOVWF	GENR1
	MOVLW	DA_AG0
	MOVWF	FSR

	BCF	RB,RCLK ;RCLK=0
AG_RD
	BSF	GENR0,3 ;READ BYTES
	CALL	RCIV_DATA
;
	INCF	FSR
	DECFSZ	GENR1
	GOTO	AG_RD
;
	MOVLW	0FH
	IORWF	RB
;
;
