;ST7565P*2
CS2   EQU P1.5
CS1   EQU P1.4
RES EQU P1.3  ;RST=/RES
A0    EQU P1.2 ;RS=A0
W_R EQU P1.1
R_D EQU P1.0
      ORG    0000H
      JMP    BEGIN
      ORG    0003H
      JMP    INTOO
      ORG    0013H
      JMP    INTII
BEGIN:   SETB EA
         SETB IT0
         SETB IT1
         CLR EX0
         CLR EX1
         CLR    RES           ;RST  
         NOP
         lcall  delay
         lcall  delay
      
         SETB   RES
         NOP   
         SETB CS1
         SETB CS2
         lcall  delay
         ;MOV     A,#0E2H        ;SOFTWAVE  RST
         ;LCALL  WCOM
         MOV    A,#00101111B     ;POWER SETTING(VF=ON,VR=ON,VC=ON)
         LCALL WCOM1
         MOV A,#11111000B
         LCALL WCOM1
         MOV A,#00000000B
         LCALL WCOM1
         ;lcall wcom2
         MOV     A,#0A2H         ;MOV    A,#0A2H         ;BIAS SELECT =1/9
         LCALL  WCOM1
         ;lcall wcom2
         MOV    A,#10100000B         ;ADC SELECT:  SEG0 TO SEG131
         LCALL  WCOM1
         LCALL  WCOM2
         MOV A,#11001000B            ;SHL SELECT:  COM63 TO COM0
         LCALL  WCOM1
         LCALL  WCOM2                                                                                                                                                                                            
         MOV    A,#00100110B    ;SET V0 VOLTAGE
         LCALL  WCOM1
         MOV    A,#10000001B    ;ELECTRONIC VOLUME MODE SET
         LCALL  WCOM1
         MOV    A,#00110011B     ;ELECTRONIC VOLUME REGISTER SET;
         MOV B,A
         LCALL  WCOM1
         ;MOV    R3,090H     ;WRITE 00H TO DISPLAY DATA RAM
         ;LCALL  TEST
         ;MOV A,#10101100B        ;STATIC INDICATOR OFF
         ;LCALL WCOM

        ;MOV    A,#11111000B
         ;LCALL WCOM
         ;MOV    A,#00000000B
         ;LCALL WCOM
         ;LCALL DELAY
         MOV    A,#040H    ;INITIAL DISPLAY LINE
         LCALL  WCOM1
         LCALL  WCOM2
         MOV    A,#0A6H    ;NORMAL DISPLAY!!!!!!!!!!!
         LCALL  WCOM1
         LCALL  WCOM2
START:
         MOV    A,#0AFH    ;DISPLAY  ON
         LCALL  WCOM1
         LCALL  WCOM2
         MOV    A,#10100101B  ;DISPLAY ALL POINTS ON(TEST1)
         LCALL  WCOM1
         LCALL  WCOM2
         LCALL  DELAY2
         MOV    A,#10100100B  ;return normal
         LCALL  WCOM1
         LCALL  WCOM2

         

         LCALL  TEST2         ;TEST2(WRITE SQUARE)
         LCALL  DELAY2
       
     
         MOV    R3,#00H       ;TSET3(WRITE COLUMN)
         LCALL  TEST
         lcall   delay2
            
         MOV    R3,#08H       ;TEST4(WRITE CHECKER) 
         LCALL  TEST
         LCALL  DELAY2
         
         MOV A,#11001000B            ;SHL SELECT:  COM63 TO COM0
         LCALL  WCOM1
         LCALL  WCOM2   
         LCALL  TEST5         ;TEST5(WRITE BIG CHAR)
         LCALL  DELAY2
         
         MOV    A,#10101110B   ;DISPLAY OFF(TEST6)
         LCALL  WCOM1
         LCALL  WCOM2
         LCALL  DELAY2

         LJMP   START
 INTOO:  PUSH ACC
        MOV A,B
        CJNE A,#00000000B,GO_DEC
        JMP OUT_INTOO
  GO_DEC:DEC A
         MOV B,A
         MOV A,#10000001B
         LCALL WCOM1
         MOV A,B
         LCALL WCOM1
   OUT_INTOO:POP ACC
         RETI
INTII:  PUSH ACC
        MOV A,B
        CJNE A,#00111111B,GO_INC
        JMP OUT_INTII
  GO_INC:INC A
         MOV B,A
         MOV A,#10000001B
         LCALL WCOM1
         MOV A,B
         LCALL WCOM1
   OUT_INTII:POP ACC
         RETI

  TEST:
              MOV      R2,#0B0H
  DISP2:      MOV      A,R2            ;set page address
              LCALL    WCOM1
              LCALL    WCOM2
              MOV      A,#010H         ;set column address MSB
              LCALL    WCOM1
              LCALL    WCOM2
              mov       a,#00h
              ;MOV      A,#00H          ;set column address LSB
              LCALL    WCOM1
              LCALL    WCOM2
              MOV      R1,#15        ;set (8*8)*16characters
     DISP1:   MOV      DPTR,#CHAR


              MOV      R0,#8
    DISP0:
                MOV      A,R3
                MOVC     A,@A+DPTR
                LCALL    WDATA1
                LCALL    WDATA2
                INC      DPTR
                DJNZ     R0,DISP0
                DJNZ     R1,DISP1
                INC      R2
                CJNE     R2,#0B8H,DISP2
                RET
   TEST2:       MOV      A,#10110000B    
                LCALL    WCOM1
                LCALL    WCOM2  
                MOV      A,#00010000B
                LCALL    WCOM1
                LCALL    WCOM2
                MOV      A,#00000000B
                LCALL    WCOM1
                LCALL    WCOM2
                MOV      A,#11111111B
                LCALL    WDATA1
                MOV      A,#00000001B
                LCALL    LOOP1 
                MOV      A,#00000001B
                LCALL    LOOP2
                MOV      A,#11111111B
                LCALL    WDATA2
                MOV      A,#10110001B
                MOV      R5,A    
                LCALL    WCOM1
                LCALL    WCOM2  
                MOV      A,#00010000B
                LCALL    WCOM1
                LCALL    WCOM2
                MOV      A,#00000000B
                LCALL    WCOM1
                LCALL    WCOM2               
                MOV      R6,#6
     TEST2_1:   MOV      A,#11111111B
                LCALL    WDATA1
                MOV      A,#00000000B
                LCALL    LOOP1
                MOV      A,#00000000B
                LCALL    LOOP2
                MOV      A,#11111111B
                LCALL    WDATA2
                INC      R5
                MOV      A,R5
                LCALL    WCOM1
                LCALL    WCOM2
                MOV      A,#00010000B
                LCALL    WCOM1
                LCALL    WCOM2
                MOV      A,#00000000B
                LCALL    WCOM1
                LCALL    WCOM2
                DJNZ     R6,TEST2_1
                MOV      A,#10110111B    
                LCALL    WCOM1
                LCALL    WCOM2  
                MOV      A,#00010000B
                LCALL    WCOM1
                LCALL    WCOM2
                MOV      A,#00000000B
                LCALL    WCOM1
                LCALL    WCOM2
                MOV      A,#11111111B
                LCALL    WDATA1
                MOV      A,#10000000B
                LCALL    LOOP1
                MOV      A,#10000000B
                LCALL    LOOP2
                MOV      A,#11111111B
                LCALL    WDATA2
                RET
                          
    TEST5:      MOV      A,#10110000B
                MOV      R5,A
                LCALL    WCOM1
                LCALL    WCOM2
                MOV      A,#00010000B
                LCALL    WCOM1
                LCALL    WCOM2
                MOV      A,#00000000B
                LCALL    WCOM1
                LCALL    WCOM2
                MOV      R7,#4
     TEST5_1:   MOV R6,  #2
                MOV DPTR,#BIG_CHAR
     TEST5_2:   MOV R3,#120
        TEST5_2_1: MOV A,#0
                MOVC     A,@A+DPTR
                LCALL    WDATA1
                INC DPTR
                DJNZ     R3,TEST5_2_1
                MOV R3,#120
        TEST5_2_2: MOV A,#0
                MOVC     A,@A+DPTR
                LCALL    WDATA2
                INC DPTR
                DJNZ     R3,TEST5_2_2        
                INC      R5
                MOV      A,R5
                LCALL    WCOM1
                LCALL    WCOM2
                MOV      A,#00010000B
                LCALL    WCOM1
                LCALL    WCOM2
                MOV      A,#00000000B
                LCALL    WCOM1
                LCALL    WCOM2
                DJNZ     R6,TEST5_2
                DJNZ R7,TEST5_1
                RET
    LOOP1:       MOV R7,#119
     LOOP1_1:    ;PUSH ACC
                LCALL WDATA1
                ;POP ACC
                DJNZ R7,LOOP1_1
                RET  
     LOOP2:       MOV R7,#119
     LOOP2_1:    ;PUSH ACC
                LCALL WDATA2
                ;POP ACC
                DJNZ R7,LOOP2_1
                RET                 
    DELAY:  MOV     40H,#032H        ;10.05ms
    DEL1: MOV     41H,#030H        
    DEL2: DJNZ    41H,DEL2      ;192us
            DJNZ    40H,DEL1      
            RET
            
    DELAY2: SETB EX0
            SETB EX1
            LCALL DELAY4
            MOV     40H,#15
    DEL21:  MOV     41H,#250
    DEL22:  MOV     42H,#80
    DEL23:  ;MOV C,P2.0
            JB P2.0,KDL
            LCALL DELAY4
  CHECK_KEY:  NOP
              NOP
              ;MOV C,P2.0
              JNB P2.0,BREAK1
              JMP CHECK_KEY
      KDL:  DJNZ    42H,DEL23
            DJNZ    41H,DEL22
            DJNZ    40H,DEL21
      BREAK1: CLR EX0
              CLR EX1
            RET
    DELAY4: MOV     43h,#4
    DEL41:  MOV     44h,#250
    DEL42:  MOV     45h,#200
     DEL43:  DJNZ    45h,DEL43
            DJNZ    44h,DEL42
            DJNZ    43h,DEL41
            RET          
WCOM1:      PUSH ACC
            ;SETB CS2
            CLR CS1
            CLR W_R
            CLR A0
            MOV P0,A
            NOP
            SETB R_D
            NOP
            CLR R_D
            NOP
            SETB CS1
            POP ACC
            RET
WCOM2:      PUSH ACC
            ;SETB CS1
            CLR CS2
            CLR W_R
            CLR A0
            MOV P0,A
            NOP
            SETB R_D
            NOP
            CLR R_D
            NOP
            SETB CS2
            POP ACC
            RET            
WDATA1:     PUSH ACC
            CLR CS1 
            CLR W_R
            SETB A0
            MOV P0,A
            NOP
            SETB R_D
            NOP
            CLR R_D
            NOP
            SETB CS1
            POP ACC
            RET
WDATA2:     PUSH ACC 
            ;SETB CS1
            CLR CS2
            CLR W_R
            SETB A0
            MOV P0,A
            NOP
            SETB R_D
            NOP
            CLR R_D
            NOP
            SETB CS2
            POP ACC
            RET   
             
      CHAR:
           DB      0FFH,000H,0FFH,000H,0FFH,000H,0FFH,000H
           DB      0F0H,0F0H,0F0H,0F0H,00FH,00FH,00FH,00FH
           DB      000H,000H,000H,000H,000H,000H,000H,000H
 BIG_CHAR:          
DB    000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB    000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB    000H,000H,000H,000H,002H,0FEH,0FEH,002H,002H,006H,01CH,0F8H,0E0H,000H,000H,000H
DB    040H,046H,0C6H,0C6H,000H,000H,000H,000H,000H,000H,000H,080H,0C0H,040H,040H,040H
DB    0C0H,0C0H,000H,000H,000H,040H,0C0H,0C0H,0C0H,040H,040H,0C0H,080H,000H,000H,000H
DB    000H,002H,002H,0FEH,0FEH,000H,000H,000H,000H,000H,000H,080H,0C0H,040H,040H,040H
DB    040H,0C0H,080H,000H,000H,000H,040H,0C0H,0C0H,040H,040H,040H,0C0H,0C0H,040H,000H
DB    000H,040H,040H,0F8H,0F8H,040H,040H,000H,000H,000H,000H,000H,000H,080H,0C0H,040H
DB    040H,0C0H,080H,000H,000H,000H,000H,000H,080H,0C0H,040H,040H,0C0H,080H,000H,000H
DB    000H,000H,002H,0FEH,0FEH,0C0H,040H,040H,0C0H,080H,000H,000H,000H,000H,000H,000H
DB    000H,000H,000H,000H,000H,000H,000H,000H,002H,0FEH,0FEH,002H,000H,000H,000H,000H
DB    000H,000H,000H,040H,040H,0F8H,0F8H,040H,040H,000H,000H,000H,000H,000H,000H,080H
DB    0C0H,040H,040H,0C2H,0FEH,0FEH,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB    000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB    000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB    000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB    000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB    000H,000H,000H,000H,020H,03FH,03FH,020H,020H,030H,01CH,00FH,003H,000H,000H,000H
DB    020H,020H,03FH,03FH,020H,020H,000H,000H,000H,000H,000H,039H,03BH,022H,026H,024H
DB    03DH,019H,000H,000H,000H,080H,0FFH,0FFH,0B0H,020H,020H,030H,01FH,00FH,000H,000H
DB    000H,020H,020H,03FH,03FH,020H,020H,000H,000H,000H,000H,019H,03DH,024H,026H,022H
DB    022H,03FH,03FH,030H,030H,000H,000H,080H,087H,0FFH,07CH,00FH,003H,000H,000H,000H
DB    000H,000H,000H,01FH,03FH,020H,030H,010H,000H,000H,000H,000H,00FH,01FH,032H,022H
DB    022H,032H,01BH,00BH,000H,000H,000H,00FH,01FH,030H,020H,020H,031H,019H,008H,000H
DB    000H,000H,020H,03FH,03FH,020H,000H,020H,03FH,03FH,020H,000H,000H,000H,000H,000H
DB    000H,000H,000H,000H,000H,000H,000H,000H,020H,03FH,03FH,020H,020H,020H,020H,038H
DB    018H,000H,000H,000H,000H,01FH,03FH,020H,030H,010H,000H,000H,000H,000H,00FH,01FH
DB    030H,020H,020H,030H,03FH,03FH,020H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB    000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
DB    000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H
       
           

           END

