*** ASSEMBLY SUCCESSFUL ***

0010 AGAIN          009B ALLPSIN        0063 BFCHECK        0072 CHECK_AGAIN    
0092 COMBEGADR      000A COMMAND        004D COMMON         0003 CWADR          
000B DATA           0096 DATABEGADR     0086 DELAY          000E DISABLE        
000F ENABLE         002E NEXTCOM        0039 NEXTDATA       0004 NUMOFC         
0010 NUMOFD         0000 PAADR          0082 PACOUTBIN      0090 PAINCOUT       
0080 PANDCOUT       0001 PBADR          0002 PCADR          0089 PDELAY         
000D READ           0040 SENDCHAR       0041 SENDCHARA      0048 SENDCOM        
0049 SENDCOMA       000C WRITE          


;********************************************************************
;====================================================================
; Program:Hello World
; programmers: Dincer Aydin & Caner Buyuktuna
; function:Displays "Hello World !!!!" on the LCD Screen
;====================================================================
;********************************************************************
; This code requires a 2*16 LCD connected to a 8255 with base address of 00h
; routines sendcomA & sendcom & sendcharA & sendchar have been tested on 
; >> 2*16 Hitachi LCD with HD44780 chip 
; >> Samsung 1*16 LCD with a KS0062F00 chip
; >> 2*16 Epson LCD marked P300020400 SANTIS 1 ,and 
; >> noname 1*16 HD44780 based LCD.
; The Z80 was clocked at 2 MHz and 4,9152 MHz for each display.This was done 
; because the routines mentioned above take many t states and in most cases 
; that will be longer that the time a HD44780 will need to execute a command. 
;
; Connections:
; LCD data bus(pins #14-#7) connected to Port A of a 8255 with 00h base address
; LCD Enable pin(#6) connected to Port C bit #7
; LCD R/W pin(#5) connected to Port C bit #6
; LCD RS pin(#4) connected to Port C bit #5


;8255 port address(base 00h):	
0000               PAADR        EQU  00H             ; Address of PortA
0000               PBADR        EQU  01H             ; Address of PortB
0000               PCADR        EQU  02H             ; Address of PortC
0000               CWADR        EQU  03H             ; Address of Control Word
;stuff to be written into the control word of the 8255:
;Some of the change the state of the ports and some manipulate
;bits on port C
0000               ALLPSIN      EQU  9BH             ; set all ports to input mode
0000               PAINCOUT     EQU  90H             ;A input,C output,B output
0000               PANDCOUT     EQU  80H             ;set all ports to output mode
0000               PACOUTBIN    EQU  82H             ;A output,C output,B input

;bit set/reset commands.These bits are the control signals for the LCD
0000               ENABLE       EQU  0FH             ; set portC bit #6
0000               DISABLE      EQU  0EH             ; reset portC bit #6
0000               READ         EQU  0DH             ; set portC bit #5
0000               WRITE        EQU  0CH             ; reset portC bit #5
0000               COMMAND      EQU  0AH             ; reset portC bit #4
0000               DATA         EQU  0BH             ; set portC bit #4

; Define number of commands and length of string data
0000               NUMOFC       EQU  4H              ; number of commands
0000               NUMOFD       EQU  10H             ; number of string bytes

; initialization:		
0000 31 00 02                   LD   SP,200H         ; Set stack pointer
0003 0E 03                      LD   C,CWADR         
0005 3E 82                      LD   A,PACOUTBIN     ; Ports A&C output,B input
0007 ED 79                      OUT  (C),A           

; *********It all begins here**********:
; This part sends commands to initialize the LCD

0009 CD 86 00                   CALL DELAY           
000C 3E 38                      LD   A,38H           ; function set command
000E 06 04                      LD   B,4             
0010 0E 03         AGAIN:       LD   C,CWADR         
0012 16 0A                      LD   D,COMMAND       
0014 ED 51                      OUT  (C),D           ; select the instruction register 
0016 16 0C                      LD   D,WRITE         
0018 ED 51                      OUT  (C),D           ; reset RW pin for writing to LCD
001A D3 00                      OUT  (PAADR),A       ; place the command into portA
001C 16 0F                      LD   D,ENABLE        
001E ED 51                      OUT  (C),D           ; enable the LCD
0020 16 0E                      LD   D,DISABLE       
0022 ED 51                      OUT  (C),D           ; disable the LCD 
0024 CD 86 00                   CALL DELAY           ; wait for a while
0027 10 E7                      DJNZ AGAIN           ; loop till the command is sent 4 times

; send commands to set input mode, cursor,number of lines ,and etc.
0029 21 92 00                   LD   HL,COMBEGADR    ; set HL to point the first command
002C 06 04                      LD   B,NUMOFC        ; put the number of commands to be sent in B
002E CD 48 00      NEXTCOM:     CALL SENDCOM         ; send (HL) as a command 
0031 23                         INC  HL              ; point the next command
0032 10 FA                      DJNZ NEXTCOM         ; loop till all commands are sent

; This part sends strings to the LCD:
0034 21 96 00                   LD   HL,DATABEGADR   ; set HL to point the first string byte
0037 06 10                      LD   B,NUMOFD        ; put the number of string bytes to be sent in B
0039 CD 40 00      NEXTDATA:    CALL SENDCHAR        ; send (HL) as string data 
003C 23                         INC  HL              ; point the next string byte
003D 10 FA                      DJNZ NEXTDATA        ; loop till all string bytes are sent

003F 76                         HALT                 



; ====================================================================
; Subroutine name:sendcomA & sendcom & sendcharA & sendchar 
; programmer:Caner Buyuktuna & Dincer Aydin
; input:A or (HL)
; output:
; Registers altered:A 
; function:	sendcharA sends the data in A to the LCD
;  	  	sendchar sends the data in (HL) to the LCD
; 		sendcomA sends the command in A to the LCD
;  		sendcom sends the command in (HL) to the LCD	
; ====================================================================
0040 7E            SENDCHAR:    LD   A,(HL)          ; put the data to be sent to the LCD in A
0041 C5            SENDCHARA:   PUSH BC              ; save BC
0042 D5                         PUSH DE              ; save DE
0043 1E 0B                      LD   E,DATA          ;  
0045 C3 4D 00                   JP   COMMON          

0048 7E            SENDCOM:     LD   A,(HL)          
0049 C5            SENDCOMA:    PUSH BC              ; save BC
004A D5                         PUSH DE              ; save DE   
004B 1E 0A                      LD   E,COMMAND       

004D CD 63 00      COMMON:      CALL BFCHECK         ; See if the LCD is busy. If it is busy wait,till it is not.
0050 ED 59                      OUT  (C),E           ; Set/reset RS accoring to the content of register E
0052 16 0C                      LD   D,WRITE         
0054 ED 51                      OUT  (C),D           ; reset RW pin for writing to LCD
0056 D3 00                      OUT  (PAADR),A       ; place data/instrucrtion to be written into portA
0058 16 0F                      LD   D,ENABLE        
005A ED 51                      OUT  (C),D           ; enable the LCD
005C 16 0E                      LD   D,DISABLE       
005E ED 51                      OUT  (C),D           ; disable the LCD 
0060 D1                         POP  DE              ; restore DE
0061 C1                         POP  BC              ; restore BC
0062 C9                         RET                  ; return
; ====================================================================
; Subroutine name:bfcheck
; programmer:Dincer Aydin
; input:
; output:
; Registers altered:D
; function:Checks if the LCD is busy and waits until it is not busy
; ====================================================================

0063 F5            BFCHECK:     PUSH AF              ; save AF
0064 0E 03                      LD   C,CWADR         
0066 16 90                      LD   D,PAINCOUT      
0068 ED 51                      OUT  (C),D           ; make A input,C output,B output
006A 16 0D                      LD   D,READ          
006C ED 51                      OUT  (C),D           ; set RW pin for reading from LCD
006E 16 0A                      LD   D,COMMAND       
0070 ED 51                      OUT  (C),D           ; select the żnstruction register 
0072 16 0F         CHECK_AGAIN: LD   D,ENABLE        
0074 ED 51                      OUT  (C),D           ; enable the LCD
0076 DB 00                      IN   A,(PAADR)       ; read from LCD
0078 16 0E                      LD   D,DISABLE       
007A ED 51                      OUT  (C),D           ; disable the LCD 
007C 07                         RLCA                 ; rotate A left through C flag to see if the busy flag is set
007D DA 72 00                   JP   C,CHECK_AGAIN   ; if busy check it again,else continue
0080 16 80                      LD   D,PANDCOUT      
0082 ED 51                      OUT  (C),D           ; set all ports to output mode
0084 F1                         POP  AF              ; restore AF
0085 C9                         RET                  

;====================================================================
; Subroutine name:DELAY and PDELAY
; programmer(s):Dincer Aydin
; input:the value in HL (for PDELAY only)
; output:-
; Registers altered:H,L
; function:delay 
; for more delay you can add a few nops or or some junk commands using the index 
; registers
; pdelay uses what you put into HL before you called the PDELAY routine 
;====================================================================

0086 21 10 10      DELAY:       LD   HL,1010H        
0089 2D            PDELAY:      DEC  L               
008A C2 89 00                   JP   NZ,PDELAY       
008D 25                         DEC  H               
008E C2 89 00                   JP   NZ,PDELAY       
0091 C9                         RET                  

;====================================================================
; commands and strings
0092 01 80 0C 06   COMBEGADR:   DB   01H,80H,0CH,06H
; clear display,set DD RAM adress,
; turn on display with cursor hidden,set entry mode
; Hello World !!!!
0096 48 65 6C 6C   DATABEGADR:  DB   48H,65H,6CH,6CH
009A 6F 20 57 6F                DB   6FH,20H,57H,6FH
009E 72 6C 64 20                DB   72H,6CH,64H,20H
00A2 21 21 21 21                DB   21H,21H,21H,21H




    Source: geocities.com/siliconvalley/circuit/8882/files

               ( geocities.com/siliconvalley/circuit/8882)                   ( geocities.com/siliconvalley/circuit)                   ( geocities.com/siliconvalley)