3-wire interface for standard LCD-modules

This circuit is a simple 3-wire interface for standard HD44780 and compatible LCD-text-modules. The example code only contains parts for direct display control.
Instead of HCT164, also a LS164 can be used.


Interface schematics

Source code for Microchip PIC controller.


; Microchip PIC @ 4MHz
;------------------------------------------------------------------------
;Variblen		
  LCD_SERDATA	; serial daten LCD	
  LCD_BITCNT    ; bitcounter LCD
  LCD_RS        ; RS flag  bit 0
;------------------------------------------------------------------------
; LCD pins
#define	  LCD_DATA   PORTB,1
#define	  LCD_CLK	 PORTB,2
#define	  LCD_ENABLE PORTB,3
;------------------------------------------------------------------------
;
; 8 bit to LCD plus ENABLE & RS
;
LCD_SER_SEND
        movwf LCD_SERDATA	
        bcf   LCD_ENABLE	
        bcf   LCD_DATA	
        movlw 0x08	
        movwf LCD_BITCNT
slcd1   btfsc LCD_SERDATA,7    ; highbit data
        bsf   LCD_DATA  
        bsf   LCD_CLK          ; clock pulse
        bcf   LCD_CLK
        bcf  	LCD_DATA
        rlf	  LCD_SERDATA,f    ; rotate left
        decfsz LCD_BITCNT,f    ; 8 bit ready ?
        goto  slcd
        btfsc LCD_RS,0
        bsf   LCD_DATA         ; rs high
        nop
        bs    LCD_ENABLE
        nop
        bcf   LCD_ENABLE
        return

Source code for Atmel AVR controller.


; AVR @ 4MHz
.equ	lcd_e		= 0
.equ	lcd_cl		= 1
.equ	lcd_da_rs	= 2
.equ	lcd_port	= PORTC
.equ	lcd_pddr	= DDRC
.def	loop_cnt_1	= r19		; loop counter
.def 	loop_cnt_2	= r20		; help
.def	lcd_data 	= r22		; daten fr lcddisplay

;***************************************************************************
;*
;*	func:	lcd_out_c
;*		    lcd_out_d
;*
;*	vars:	lcd_data
;*		    loop_cnt_1
;*		
;*	subs:	wait_x_100u
;*
;***************************************************************************
lcd_out_c:
        push	loop_cnt_1
        delay_x_100u 2
        rcall	lcd_out8
        cbi	lcd_port,lcd_da_rs
        rjmp	lcd_en
lcd_out_d:
        push	loop_cnt_1
        delay_x_100u 2
        rcall	lcd_out8
        sbi	lcd_port,lcd_da_rs
        rjmp	lcd_en
lcd_en:
        sbi	lcd_port,lcd_e
        pop	loop_cnt_1
        cbi	lcd_port,lcd_e
        ret

lcd_out8:
        ldi	loop_cnt_1,8
rorloop: rol	lcd_data
        brcs	eout
        cbi	lcd_port,lcd_da_rs		
        rjmp	edo
eout:   sbi	lcd_port,lcd_da_rs
edo:    sbi	lcd_port,lcd_cl
        cbi	lcd_port,lcd_cl
        dec	loop_cnt_1
        brne	rorloop
        ret

;***************************************************************************
;*
;*	func:	wait_x_100u
;*
;*	vars:	loop_cnt_1
;*		    loop_cnt_2
;*
;***************************************************************************
wait_x_100u:
        push	loop_cnt_2
        mov	loop_cnt_2,loop_cnt_1
l2loop: ldi 	loop_cnt_1,199			; 99
lcloop: dec	loop_cnt_1
        or	loop_cnt_1,loop_cnt_1
        brne	lcloop
        dec	loop_cnt_2
        or	loop_cnt_2,loop_cnt_2
        brne	l2loop
        pop	loop_cnt_2
        ret
        

  © Robert Rottmerhusen 2010  ♦  Update: 2010-01-17  ♦  feedback☺rottmerhusen.com up English Deutsch