flat assembler
Message board for the users of flat assembler.

Index > Main > How to initialize an LCD module?

Author
Thread Post new topic Reply to topic
delta67



Joined: 18 Jul 2012
Posts: 19
delta67
Hi all,

I want to initialise a 2x16 LCD module, connected to an 8088 SBC but my code didn't work!!
There's NO ram on the board
Q=4MHz then CLK = 4/3 Mhz

Code:
; 2x16 LCD module connected to the 8088 SBC via 8255 PIO:
; - D4-D7 are connected to portC C4-C7
; - RS is connected to PORTC C0
; - E is connected to portB B0
; 8255 : PORTA= 00    PORTB=01    PORTC=02      PORT COMMAND=03
;=========================================
    rom_size  = 2000h ;  8K byte EPROM 
    rom_start = 100000h - rom_size
    rom_empty = 0FFh
;=========================================
    use16
;-----------------------------------------
start:
        ; init 8255
        mov al, 80h  ; MODE 0 and  all ports as outputs
        out 03h, al ; send to command port
        

  ;  wait  >15mS
    mov cx,07FFFh  ; ?? s
delay1:
    loop delay1
        
        mov bl, 03h   ;  send  "3" three times to initialize the LCD in mode 8bits
        mov al, 030h
        out 02, al ;  send  first "3" on  C4-C7  , RS=0
again:  mov al, 01h  
        out 01h, al  ; portB B0=1  (E=1)
        nop
        nop
        mov al, 00h   
        out 01h, al  ; E=0


        ;   wait >5mS
        mov cx,01FFFh
delay2:
    loop delay2
        
        dec bl   ; "3" sent 3 times?
        jnz again  ; NO , then repeat
        ; YES , now LCD is in 8bits mode 8 
        ;----------------------------------------------
        
        mov al, 020h ; mode 4bits
        out 02h, al ;  send "2" on C4-C7  , RS=0
        mov al, 01h  
        out 01h, al  ; portB B0=1  (E=1)
        nop
        nop
        mov al, 00h   
        out 01h, al  ; E=0
        
        ;   wait 5mS
         mov cx,0FFFh
delay3:
    loop delay3
        
        ;       At this point, the normal 4 wire command routine can be used 
        ;---------------------------------------------------------------------------------
        ; Now we send the command "28h"  Function set, 4 wire, 2 lines, 5x7 font
        mov al, 020h ; 
        out 02h, al ;   send "2" on C4-C7  , RS=0
        out 01h, al  ; portB B0=1  (E=1)
        nop
        nop
        mov al, 00h   
        out 01h, al  ; E=0
        nop
        
        mov al, 080h ; 
        out 02h, al ;   send "8" on C4-C7  , RS=0
        mov al, 01h  
        out 01h, al  ; portB B0=1  (E=1)
        nop
        nop
        mov al, 00h   
        out 01h, al  ; E=0
        
        ;   wait 5mS
        mov cx,0FFFh
delay4:
    loop delay4
        ;---------------------------------------------------------------------------------
        ; Now we send the command "0Ch"   = Display on, cursor off,  blink off
        ; mov al, 00h ;  AL is already cleared
        out 02h, al ;  send "0" on C4-C7  , RS=0
        mov al, 01h  
        out 01h, al  ; portB B0=1  (E=1)
        nop
        nop
        mov al, 00h   
        out 01h, al  ; E=0
        nop
        
        mov al, 0C0h ; 
        out 02h, al ;   send "C" on C4-C7  , RS=0
        mov al, 01h  
        out 01h, al  ; portB B0=1  (E=1)
        nop
        nop
        mov al, 00h   
        out 01h, al  ; E=0
        
        ;   wait 5mS
        mov cx,0FFFh
delay5:
    loop delay5
 
        ;---------------------------------------------------------------------------------
        ; Now we send the command "06h"   = Address increment, no scrolling
        
        ; mov al, 00h ;  AL is already cleared
        out 02h, al ;   send "0" on C4-C7  , RS=0
        mov al, 01h  
        out 01h, al  ; portB B0=1  (E=1)
        nop
        nop
        mov al, 00h   
        out 01h, al  ; E=0
        nop
        
        mov al, 060h ; 
        out 02h, al ;   send "6" on C4-C7  , RS=0
        mov al, 01h  
        out 01h, al  ; portB B0=1  (E=1)
        nop
        nop
        mov al, 00h   
        out 01h, al  ; E=0
        
        ;   wait 5mS
        mov cx,0FFFh
delay6:
    loop delay6
        
        
        ;---------------------------------------------------------------------------------
        ; Now we send the command "01h"  Clear LCD command
        
        ; mov al, 00h ;  ALis already cleared
        out 02h, al ;   send "0" on C4-C7  , RS=0
        mov al, 01h  
        out 01h, al  ; portB B0=1  (E=1)
        nop
        nop
        nop
        mov al, 00h   
        out 01h, al  ; E=0
        nop
        
        mov al, 010h ; 
        out 02h, al ;   send "1" on C4-C7  , RS=0
        mov al, 01h  
        out 01h, al  ; portB B0=1  (E=1)
        nop
        nop
        nop
        mov al, 00h   
        out 01h, al  ; E=0
        
        ;   wait 5mS
        mov cx,0FFFh
delay7:
    loop delay7
        
;============================================= 
;       Send a character data to LCD
        ;write 'E'   (45h)  to the LCD
        mov al, 041h    
        out 02h, al ;   send "4" on C4-C7  , 1 on C0 (RS=1)
        nop
        nop
        mov al, 01h  
        out 01h, al  ; portB B0=1  (E=1)
        nop
        nop
        mov al, 00h   
        out 01h, al  ; E=0
        nop
        
        mov al, 051h   
        out 02h, al ;   send "5" on C4-C7  ,1 on C0 (RS=1)
        nop
        nop
        mov al, 01h  
        out 01h, al  ; portB B0=1  (E=1)
        nop
        nop
        mov al, 00h   
        out 01h, al  ; E=0
        
;=============================
                hlt   ; stop  
    
Post 20 Jul 2012, 16:36
View user's profile Send private message Reply with quote
delta67



Joined: 18 Jul 2012
Posts: 19
delta67
Thanks to SHOORICK I finally fixed the code:

Code:
; 2x16 LCD module connected to the 8088 SBC via 8255 PIO:
; - D4-D7 are connected to portC C4-C7
; - E is connected to PORTC C0
; - RS is connected to portC C1
; 8255 : PORTA= 00    PORTB=01    PORTC=02      PORT COMMAND=03
;=========================================
    rom_size  = 2000h ; for a 8K octet EPROM you should set the rom_size to $2000
    rom_start = 100000h - rom_size
    rom_empty = 0FFh
;=========================================
    use16
;-----------------------------------------
start:
  ; init 8255
 mov al, 80h  ; MODE 0 and  all ports as outputs
     out 03h, al ; send on command port

        ;  wait  >15mS
    mov cx,07FFFh  ; ?? s
delay1:
    loop delay1
  ;----------------------------------------------
     
    mov al, 020h ; mode 4bits
      mov sp,@F
   JMP lcd_command
@@:
   dw @F
@@:    
    ;   wait 5mS
         mov cx,0FFFh
delay2:
    loop delay2
     
    ;       At this point, the normal 4 wire command routine can be used 
       ;---------------------------------------------------------------------------------
  ; Now we send the command "28h"  Function set, 4 wire, 2 lines, 5x7 font
  mov al, 028h ; 
        mov sp,@F
   JMP lcd_command
@@:
   dw @F
@@:
        ;   wait 5mS
        mov cx,0FFFh
delay3:
    loop delay3
      ;---------------------------------------------------------------------------------
  ; Now we send the command "0Ch"   = Display on, cursor off,  blink off
    mov al, 0x0C ; 
        mov sp,@F
   JMP lcd_command
@@:
   dw @F
@@:
        ;   wait 5mS
        mov cx,0FFFh
delay4:
    loop delay4
      ;---------------------------------------------------------------------------------
  ; Now we send the command "06h"   = Address increment, no scrolling
       mov al, 0x06 ; 
        mov sp,@F
   JMP lcd_command
@@:
   dw @F
@@:
        ;   wait 5mS
        mov cx,0FFFh
delay5:
    loop delay5
      
            ;---------------------------------------------------------------------------------
  ; Now we send the command "01h"  Clear LCD command

    mov al, 0x01 ; 
        mov sp,@F
   JMP lcd_command
@@:
   dw @F
@@:
        ;   wait 5mS
        mov cx,0FFFh
delay6:
    loop delay6
      
;============================================= 
;        Send a character data to LCD
        ;write 'E'   (45h)  to the LCD
    mov al, 0x45 ; 
        mov sp,@F
   JMP lcd_data
@@:
   dw @F
@@:       
  hlt
;========================================
lcd_command:
    xor bl,bl ; set RS=0
    jmp lcd_write
lcd_data:
    mov bl,2 ; set RS=1
lcd_write:
    mov ah,al ; al - byte to send
    and al,0xF0
    or   al,bl
    out 0x02,al
    mov al,0x01; E is connected to C0
    out 0x03,al   ; turn E on
    dec al
    out 0x03,al   ; turn E off
    mov al,ah
    mov cl,4
    shl al,cl
    and al,0xF0
    or   al,bl
    out 0x02,al
    mov al,0x01; 
    out 0x03,al   ; turn E on
    dec al
    out 0x03,al   ; turn E off
    ret
 
    ;-----------------------------------------
    times rom_size - 16 - $ db rom_empty ; on remplit l'espace vide par FFh sauf les derniers 16 octets
;-----------------------------------------
boot:             ; vecteur reset : FFFF0
    jmp (rom_start shr 4):start
;-----------------------------------------
    times rom_size - $ db rom_empty ; on remplit le rest vide du 16 octets
        
    
        
Post 23 Jul 2012, 22:21
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.