Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help with serial LCD project

Status
Not open for further replies.
Good luck on the '595 interface, Aaron. If you're interested... here's something I just came up with that borrows from Raj Bhatt's adapter where he uses the SCK and RCK pins tied together on the '595 to form a 3-pin microcontroller interface.

This LCD interface concept uses the HD44780 LCD "8 bit interface mode" which means you only need to fill the 74HC595 shift register one time to send a single byte to the LCD. Of course since SCK and RCK are tied together on the '595 you actually have to clock out nine bits of data in order to get eight bits of data onto the '595 outputs. However, if our driver sends the RS bit as the ninth bit and leaves RS on the SER pin when it strobes the LCD E line, we should be in business.

Let me know if you'd like to see an assembly language driver?

Cheerful regards, Mike


k8lh-3-pin-74hc595-lcd-8-bit-mode-backpack-jpg.69752
 
Last edited:
Let me know if you'd like to see an assembly language driver?

Please. I've been writing but not succeeding. Comparing mine to one that's working, should show me where I'm wrong.

Thanks Mike
 
Does that design require filling the shift register six times to send a single byte to the LCD? How long would that take, 4-5 milliseconds?

No, you only have to send the 7 data bits followed by the final "latch" bit, to send 1 byte.

But you made a good point it is not that fast, for worst case with the RC values I used in the kit it takes 45uS*7 for 7 zero bits, followed by 500uS for the latch bit. Total time 815uS to send the byte. Fast enough to update the LCD multiple times a second.
 
Mike said:
Does that design require filling the shift register six times to send a single byte to the LCD? How long would that take, 4-5 milliseconds?
No, you only have to send the 7 data bits followed by the final "latch" bit, to send 1 byte.
You misunderstood but I looked at your shift-1 software and it clearly shows that you send four bytes to the 74HC595 in order to get one byte to the LCD... (1) send upper nibble with E high, (2) send upper nibble with E low, (3) send lower nibble with E high, and (4) send lower nibble with E low.

Code:
//=============================================================================
//  SH1_LCD_BYTE    	   sends a command or char byte to LCD
//=============================================================================
void SH1_Lcd_Byte(unsigned char SH1_byte, unsigned char SH1_cmd)
{
	//-----------------------------------------------------
	// this sends 2 4bit nibbles to the LCD, and each
	// nibble is clocked by a \ edge of the LCD E pin.
	// the 6 LCD pins are controlled by a 74HC595 shift
	// register using RomanBlack's Shift1 timed protocol.
	//-----------------------------------------------------
	// send top nibble first
	SH1_trashdata = (SH1_byte & 0xF0); // get top 4 bits
	SH1_trashdata.F3 = 1;				       // set E pin hi
        if(SH1_cmd) SH1_trashdata.F2 = 1;  // set RS (command=0/char=1)
	SH1_Send_Byte(SH1_trashdata);		   // send data and E hi
	SH1_trashdata.F3 = 0;				       // set E pin lo
	SH1_Send_Byte(SH1_trashdata);		   // send data and E \ clock pulse

	// now send bottom nibble
	SH1_trashdata = (SH1_byte << 4);   // get bottom 4 bits
	SH1_trashdata.F3 = 1;				
        if(SH1_cmd) Sh1_trashdata.F2 = 1;  // set RS (command=0/char=1)
	SH1_Send_Byte(SH1_trashdata);		
	SH1_trashdata.F3 = 0;			
	SH1_Send_Byte(SH1_trashdata);	
}
But you made a good point it is not that fast, for worst case with the RC values I used in the kit it takes 45uS*7 for 7 zero bits, followed by 500uS for the latch bit. Total time 815uS to send the byte. Fast enough to update the LCD multiple times a second.
Ok, so multiply that 815uS by four to get a complete command or data byte to the LCD and it can take several thousand microseconds worst case. As long as you know about that ahead of time, you should be able to work around it for all but the most demanding applications.
 
Last edited:
Mike said:
Let me know if you'd like to see an assembly language driver?
Please. I've been writing but not succeeding. Comparing mine to one that's working, should show me where I'm wrong.

Well, I don't have a way to test the driver at the moment so I can't claim it as "working" but maybe I can breadboard it sometime soon. The driver (below) uses 16-bit core (18F') instructions so it would need to be modified for use on 14-bit core (16F') devices.

I'd love to see someone get this interface running...

Cheerful regards, Mike

Code:
#define dat LATA,0              ; 595 'ser' pin
#define clk LATA,1              ; 595 'sck' and 'rck' pins
#define ena LATA,2              ; lcd 'e' pin
Code:
;****************************************************************** 
;  K8LH 74HC595 "LCD 8-bit Interface Mode" Low Level Driver       *
;******************************************************************

putDat
        bsf     STATUS,C        ; flag rs = 1 (data)
        btfss   STATUS,C        ; skip unconditionally
putCmd
        bcf     STATUS,C        ; flag rs = 0 (command)
        movwf   work            ; save byte in 'work' var
        movlw   8               ; use wreg as bit counter
bitlp
        bcf     dat             ; dat = 0
        btfsc   work,7          ; is it '0'? yes, skip, else
        bsf     dat             ; dat = 1
        bsf     clk             ; clk = 1, clock out a bit
        bcf     clk             ; clk = 0
        rlncf   work,F          ; shift 'work' byte
        decfsz  WREG,F          ; all 8 bits? yes, skip, else
        bra     bitlp           ; branch (send another bit)
        bcf     dat             ; dat = 0
        btfsc   STATUS,C        ; rs = 0? yes, skip, else
        bsf     dat             ; dat = 1
        bsf     clk             ; clk = 1, clock out 'RS' bit
        bcf     clk             ; clk = 0 (leave dat = RS)
        bsf     ena             ; ena = 1, strobe LCD 'E' pin
        bcf     ena             ; ena = 0
        return                  ;
k8lh-3-pin-74hc595-lcd-8-bit-mode-backpack-jpg.69752
 
Last edited:
I let you no today some time I don't feel to hot right now. going back to bed.
 
I let you no today some time I don't feel to hot right now. going back to bed.

Thanks, Burt. That's very kind of you. Hope you're feeling better soon.

If it helps, here's an untested program for an 18F14K22 (that's what I have here). It simulates ok but it will be awhile before I can breadboard the interface to test it. I wonder if I need to preload the 74HC595 with '0' bits when the program starts up?

Cheerful regards, Mike

Code:
;******************************************************************
;                                                                 *
;   Filename: 18F14K22 595 8 Bit LCD Test.asm                     *
;     Author: Mike McLaren, K8LH                                  *
;    (C)2012: Micro Application Consultants                       *
;           : All Rights Reserved                                 *
;       Date: 11-Jan-2013                                         *
;                                                                 *
;  18F14K22 + 74HC595 - K8LH LCD 8-Bit Interface Adapter Test     *
;                                                                 *
;                                                                 *
;                                                                 *
;      MPLab: 8.84    (tabs=8)                                    *
;      MPAsm: 5.44                                                *
;                                                                 *
;******************************************************************

        #include <P18F14K22.inc>

        list st=off             ; no symbol table in LST file
        radix dec
;
;  setup configuration fuses
;
        CONFIG  FOSC = IRC      ; Internal RC oscillator
        CONFIG  PLLEN = OFF     ; PLL is under software control
        CONFIG  PCLKEN = ON     ; Primary clock enabled
        CONFIG  FCMEN = OFF     ; Fail-Safe Clock Monitor disabled
        CONFIG  IESO = OFF      ; Oscillator Switchover mode disabled
        CONFIG  PWRTEN = ON     ; PWRT enabled
        CONFIG  BOREN = SBORDIS ; Brown-out Reset enabled in hardware
                                ; only (SBOREN is disabled)
        CONFIG  BORV = 22       ; VBOR set to 2.2 V nominal
        CONFIG  WDTEN = OFF     ; WDT control via WDTCON SWDTEN bit
        CONFIG  WDTPS = 256     ; 1:256
        CONFIG  HFOFST = OFF    ; clock held until HFINTOSC stable
        CONFIG  MCLRE = ON      ; MCLR enabled, RA3 I/O unavailable
        CONFIG  STVREN = ON     ; reset on Stack full or underflow
        CONFIG  LVP = OFF       ; Single-Supply ICSP disabled
        CONFIG  XINST = OFF     ; extended instruction set disabled
        CONFIG  DEBUG = OFF     ; debugger off, RA0 + RA1 available

;--< variables >---------------------------------------------------

temp    equ     0x000           ; lcd subroutines
delayhi equ     0x001           ; DelayCy() subsystem var
count   equ     0x002           ;
work    equ     0x003           ; lcd driver work var


;--< constants >---------------------------------------------------

#define MASK(X)	(1<<(X))

brgval	equ	(16000000/19200/4)-1	; 19200, BRGH=1, BRG16=1

#define line1   128+0           ; lcd line 1 address
#define line2   128+64          ; lcd line 2 address

;--< defines >-----------------------------------------------------

#define dat LATA,0              ; RA0 -> 595 'ser' pin
#define clk LATA,1              ; RA1 -> 595 'sck' and 'rck' pins
#define ena LATA,2              ; RA2 -> lcd 'e' pin
;
;  assembly language helpers
;
#define clrc    bcf   STATUS,C
#define setc    bsf   STATUS,C
#define skpc    btfss STATUS,C
#define skpnc   btfsc STATUS,C

;==================================================================
;  K8LH DelayCy() subsystem macro generates four instructions	  =
;==================================================================
        radix   dec
clock   equ     16              ; 4, 8, 12, 16, 20 (MHz), etc.
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     clock/4*1000    ; cycles/millisecond multiplier

DelayCy macro   delay           ; 11..327690 cycle range
        movlw   high((delay-11)/5)+1
        movwf   delayhi
        movlw   low ((delay-11)/5)
        call    uDelay-(((delay-11)%5)*2)
        endm

;******************************************************************
;  reset vector                                                   *
;******************************************************************
        org     0x0000
vreset
        goto    init            ;                                 |

;******************************************************************
;  interrupt vector hi                                            *
;******************************************************************
        org     0x0008
vinthi

;******************************************************************
;  interrupt vector lo                                            *
;******************************************************************
        org     0x0018
vintlo

;******************************************************************
;  main init                                                      *
;******************************************************************

init
        clrf    ANSEL           ;                                 |
        clrf    ANSELH          ;                                 |
        clrf    TRISA           ;                                 |
        clrf    TRISB           ;                                 |
        clrf    TRISC           ;                                 |
        clrf    PORTA           ;                                 |
        clrf    PORTB           ;                                 |
        clrf    PORTC           ;                                 |
;
;  setup INTOSC for 16 MHz
;
;       movlw   1<<PLLEN        ; 4xPLL 'on' for 64 MHz           |
;       movwf   OSCTUNE         ;                                 |
        movlw   b'01110010'     ; 16 MHz                          |
        movwf   OSCCON          ;                                 |
;
;  configure EUSART for 19200 baud operation (16 MHz clock)
;
        movlw   low(brgval)     ;                                 |
        movwf   SPBRG           ;                                 |
        movlw   high(brgval)    ;                                 |
        movwf   SPBRGH          ;                                 |
        movlw   1<<BRG16        ;                                 |
        movwf   BAUDCON         ; BRG16=1                         |
        movlw   1<<TXEN|1<<BRGH ;                                 |
        movwf   TXSTA           ; TXEN=1, BRGH=1, SYNC=0          |
        movlw   1<<SPEN|1<<CREN ;                                 |
        movwf   RCSTA           ; SPEN=1, CREN=1                  |
;
;  initialize LCD (8-bit interface mode).  please note this is 
;  not the Hitachi "initialize by instruction" procedure.
;
        DelayCy(50*msecs)       ; lcd 50 msec 'power up' reset    |
        movlw   0x38            ; 8-bit, 2-lines, 5x7 font        |
        call    PutCmd          ; send "function set" command     |
        movlw   0x01            ; clear display (1.53-msecs)      |
        call    PutCmd          ; send "entry mode set" command   |
        DelayCy(1530*usecs)     ; 1.53 msec delay for "clear"     |
        movlw   0x06            ; cursor inc, shift off           |
        call    PutCmd          ; send "entry mode set" command   |
        movlw   0x0C            ; display on, cursor & blink off  |
        call    PutCmd          ; send "display on/off" command   |
;
;  display "hello" starting at fifth column on line 2
;
        movlw   line2+4         ; line 2, tab 4                   |
        call    PutCmd          ; move lcd cursor to x,y = 4,1    |
        movlw   'h'             ;                                 |
        call    PutDat          ;                                 |
        movlw   'e'             ;                                 |
        call    PutDat          ;                                 |
        movlw   'l'             ;                                 |
        call    PutDat          ;                                 |
        movlw   'l'             ;                                 |
        call    PutDat          ;                                 |
        movlw   'o'             ;                                 |
        call    PutDat          ;                                 |

;******************************************************************
;  main loop                                                      *
;******************************************************************

loop
        bra     loop            ; loop forever                    |

;******************************************************************
;  K8LH "74HC595 LCD 8-bit Interface Mode" Low Level Driver       *
;******************************************************************

PutDat
        setc                    ; flag rs = 1 (data)              |
        skpc                    ; skip unconditionally            |
PutCmd
        clrc                    ; flag rs = 0 (command)           |
        movwf   work            ; save byte in 'work' var         |
        movlw   8               ; use wreg as bit counter         |
bitlp
        bcf     dat             ; dat = 0                         |
        btfsc   work,7          ; is it '0'? yes, skip, else      |
        bsf     dat             ; dat = 1                         |
        bsf     clk             ; clk = 1, clock out a bit        |
        bcf     clk             ; clk = 0                         |
        rlncf   work,F          ; shift 'work' byte               |
        decfsz  WREG,F          ; all 8 bits? yes, skip, else     |
        bra     bitlp           ; branch (send another bit)       |
        bcf     dat             ; dat = 0                         |
        skpnc                   ; rs = 0? yes, skip, else         |
        bsf     dat             ; dat = 1                         |
        bsf     clk             ; clk = 1, clock out 'RS' bit     |
        bcf     clk             ; clk = 0 (leave dat = RS)        |
        bsf     ena             ; ena = 1, strobe LCD 'E' pin     |
        bcf     ena             ; ena = 0                         |
        DelayCy(50*usecs)       ; required lcd inter-write delay  |
        return                  ;                                 |

;******************************************************************
;  serial subroutines                                             *
;******************************************************************

put232
        btfss   PIR1,TXIF       ; Tx buff empty? yes, skip, else  |
        bra     put232          ; loop                            |
        movwf   TXREG           ;                                 |
        return                  ;                                 |
get232
        btfss   PIR1,RCIF       ; Rx char avail? yes, skip, else  |
        bra     get232          ; loop                            |
        movf    RCREG,W         ;                                 |
        return                  ;                                 |

;******************************************************************
;  K8LH DelayCy() 16-bit uDelay (11..327690 cycle) subroutine     *
;******************************************************************
        nop                     ; entry for (delay-11)%5 == 4     |
        nop                     ; entry for (delay-11)%5 == 3     |
        nop                     ; entry for (delay-11)%5 == 2     |
        nop                     ; entry for (delay-11)%5 == 1     |
uDelay  addlw   -1              ; subtract 5 cycle loop time      |
        skpc                    ; borrow? no, skip, else          |
        decfsz  delayhi,F       ; done?  yes, skip, else          |
        bra     uDelay          ; do another loop                 |
        return                  ; return with C = Z = 0           |

;******************************************************************
        end

BTW, the 74HC595 based design is really just a derivation of an old design that used a 74HC164 shift register (see drawing below). If you're not locked into using a 74HC595, there may be a couple advantages using the 74HC164 version of the interface. Software for the 74HC164 version is exactly the same as software for the 74HC595 version except that the 74HC164 version doesn't require the ninth clock pulse. Also, the 74HC164 comes in a smaller 14 pin package.

74hc595-8-bit-interface-png.58547
 
Last edited:
Aaron,

Not sure if this will help but I just found this old post during a search and it contains an example assembly language program for 12F683 using Raj Bhatt's 74HC595 interface.

Regards, Mike
 
Mike I don't have a 18f14K22 I need a little help setting this right for a 18f1220 at 16 mhz crystal
Code:
        movlw   low(brgval)     ;                                 |
        movwf   SPBRG           ;                                 |
        movlw   high(brgval)    ;                                 |
        movwf   SPBRGH          ;                                 |
        movlw   1<<BRG16        ;                                 |
        movwf   BAUDCTL         ; BRG16=1                         |
        movlw   1<<TXEN|1<<BRGH ;                                 |
        movwf   TXSTA           ; TXEN=1, BRGH=1, SYNC=0          |
        movlw   1<<SPEN|1<<CREN ;                                 |
        movwf   RCSTA           ; SPEN=1, CREN=1                  |
;

I think i have it maybe not going to try but if you can look over my changes for the 18F1220
Code:
;******************************************************************
;                                                                 *
;   Filename: 18F14K22 595 8 Bit LCD Test.asm                     *
;     Author: Mike McLaren, K8LH                                  *
;    (C)2012: Micro Application Consultants                       *
;           : All Rights Reserved                                 *
;       Date: 11-Jan-2013                                         *
;                                                                 *
;  18F14K22 + 74HC595 - K8LH LCD 8-Bit Interface Adapter Test     *
;                                                                 *
;                                                                 *
;                                                                 *
;      MPLab: 8.84    (tabs=8)                                    *
;      MPAsm: 5.44                                                *
;                                                                 *
;******************************************************************
 
        #include <P18F1220.inc>
 
        list st=off             ; no symbol table in LST file
        radix dec
;
;  setup configuration fuses
;
        CONFIG  OSC = HS    ; Internal RC oscillator
        CONFIG  FSCM = OFF      
        CONFIG  IESO = OFF           
        CONFIG  PWRT = OFF           
        CONFIG  BOR = OFF            
        CONFIG  BORV = 27            
        CONFIG  WDT = OFF            
                                
        CONFIG  MCLRE = ON           
        CONFIG  STVR = OFF           
        CONFIG  LVP = OFF            
        CONFIG  DEBUG = OFF          
        CONFIG  CP0 = OFF            
        CONFIG  CP1 = OFF            
        CONFIG  CPB = OFF            
        CONFIG  CPD = OFF             
        CONFIG  WRT0 = OFF  
        CONFIG  WRT1 = OFF           
        CONFIG  WRTC = OFF           
        CONFIG  WRTB = OFF           
        CONFIG  WRTD = OFF           
		CONFIG  EBTR0 = OFF         
        CONFIG  EBTR1 = OFF          
		CONFIG  EBTRB = OFF           
 
;--< variables >---------------------------------------------------
 
temp    equ     0x000           ; lcd subroutines
delayhi equ     0x001           ; DelayCy() subsystem var
count   equ     0x002           ;
work    equ     0x003           ; lcd driver work var
 
 
;--< constants >---------------------------------------------------
 
#define MASK(X)	(1<<(X))
 
brgval	equ	(16000000/19200/4)-1	; 19200, BRGH=1, BRG16=1
 
#define line1   128+0           ; lcd line 1 address
#define line2   128+64          ; lcd line 2 address
 
;--< defines >-----------------------------------------------------
 
#define dat LATA,0              ; RA0 -> 595 'ser' pin
#define clk LATA,1              ; RA1 -> 595 'sck' and 'rck' pins
#define ena LATA,2              ; RA2 -> lcd 'e' pin
;
;  assembly language helpers
;
#define clrc    bcf   STATUS,C
#define setc    bsf   STATUS,C
#define skpc    btfss STATUS,C
#define skpnc   btfsc STATUS,C
 
;==================================================================
;  K8LH DelayCy() subsystem macro generates four instructions	  =
;==================================================================
        radix   dec
clock   equ     16              ; 4, 8, 12, 16, 20 (MHz), etc.
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     clock/4*1000    ; cycles/millisecond multiplier
 
DelayCy macro   delay           ; 11..327690 cycle range
        movlw   high((delay-11)/5)+1
        movwf   delayhi
        movlw   low ((delay-11)/5)
        call    uDelay-(((delay-11)%5)*2)
        endm
 
;******************************************************************
;  reset vector                                                   *
;******************************************************************
        org     0x0000
vreset
        goto    init            ;                                 |
 
;******************************************************************
;  interrupt vector hi                                            *
;******************************************************************
        org     0x0008
vinthi
 
;******************************************************************
;  interrupt vector lo                                            *
;******************************************************************
        org     0x0018
vintlo
 
;******************************************************************
;  main init                                                      *
;******************************************************************
 
init
		movlw   0xFF ; Configure A/D
        movwf   ADCON1 ; for digital inputs
        clrf    TRISA           ;                                 |
        clrf    TRISB           ;                                 |
        clrf    PORTA           ;                                 |
        clrf    PORTB           ;                                 |
;
;  setup INTOSC for 16 MHz
;
;       movlw   1<<PLLEN        ; 4xPLL 'on' for 64 MHz           |
;       movwf   OSCTUNE         ;                                 |
;        movlw   0x73            ; 8 MHz                          |
;        movwf   OSCCON          ;                                 |
;
;  configure EUSART for 19200 baud operation (16 MHz clock)
;
        movlw   low(brgval)     ;                                 |
        movwf   SPBRG           ;                                 |
        movlw   high(brgval)    ;                                 |
        movwf   SPBRGH          ;                                 |
        movlw   1<<BRG16        ;                                 |
        movwf   BAUDCTL         ; BRG16=1                         |
        movlw   1<<TXEN|1<<BRGH ;                                 |
        movwf   TXSTA           ; TXEN=1, BRGH=1, SYNC=0          |
        movlw   1<<SPEN|1<<CREN ;                                 |
        movwf   RCSTA           ; SPEN=1, CREN=1                  |
;
;  initialize LCD (8-bit interface mode).  please note this is 
;  not the Hitachi "initialize by instruction" procedure.
;
        DelayCy(50*msecs)       ; lcd 50 msec 'power up' reset    |
        movlw   0x38            ; 8-bit, 2-lines, 5x7 font        |
        call    PutCmd          ; send "function set" command     |
        movlw   0x01            ; clear display (1.53-msecs)      |
        call    PutCmd          ; send "entry mode set" command   |
        DelayCy(1530*usecs)     ; 1.53 msec delay for "clear"     |
        movlw   0x06            ; cursor inc, shift off           |
        call    PutCmd          ; send "entry mode set" command   |
        movlw   0x0C            ; display on, cursor & blink off  |
        call    PutCmd          ; send "display on/off" command   |
;
;  display "hello" starting at fifth column on line 2
;
        movlw   line2+4         ; line 2, tab 4                   |
        call    PutCmd          ; move lcd cursor to x,y = 4,1    |
        movlw   'h'             ;                                 |
        call    PutDat          ;                                 |
        movlw   'e'             ;                                 |
        call    PutDat          ;                                 |
        movlw   'l'             ;                                 |
        call    PutDat          ;                                 |
        movlw   'l'             ;                                 |
        call    PutDat          ;                                 |
        movlw   'o'             ;                                 |
        call    PutDat          ;                                 |
 
;******************************************************************
;  main loop                                                      *
;******************************************************************
 
loop
        bra     loop            ; loop forever                    |
 
;******************************************************************
;  K8LH "74HC595 LCD 8-bit Interface Mode" Low Level Driver       *
;******************************************************************
 
PutDat
        setc                    ; flag rs = 1 (data)              |
        skpc                    ; skip unconditionally            |
PutCmd
        clrc                    ; flag rs = 0 (command)           |
        movwf   work            ; save byte in 'work' var         |
        movlw   8               ; use wreg as bit counter         |
bitlp
        bcf     dat             ; dat = 0                         |
        btfsc   work,7          ; is it '0'? yes, skip, else      |
        bsf     dat             ; dat = 1                         |
        bsf     clk             ; clk = 1, clock out a bit        |
        bcf     clk             ; clk = 0                         |
        rlncf   work,F          ; shift 'work' byte               |
        decfsz  WREG,F          ; all 8 bits? yes, skip, else     |
        bra     bitlp           ; branch (send another bit)       |
        bcf     dat             ; dat = 0                         |
        skpnc                   ; rs = 0? yes, skip, else         |
        bsf     dat             ; dat = 1                         |
        bsf     clk             ; clk = 1, clock out 'RS' bit     |
        bcf     clk             ; clk = 0 (leave dat = RS)        |
        bsf     ena             ; ena = 1, strobe LCD 'E' pin     |
        bcf     ena             ; ena = 0                         |
        DelayCy(50*usecs)       ; required lcd inter-write delay  |
        return                  ;                                 |
 
;******************************************************************
;  serial subroutines                                             *
;******************************************************************
 
put232
        btfss   PIR1,TXIF       ; Tx buff empty? yes, skip, else  |
        bra     put232          ; loop                            |
        movwf   TXREG           ;                                 |
        return                  ;                                 |
get232
        btfss   PIR1,RCIF       ; Rx char avail? yes, skip, else  |
        bra     get232          ; loop                            |
        movf    RCREG,W         ;                                 |
        return                  ;                                 |
 
;******************************************************************
;  K8LH DelayCy() 16-bit uDelay (11..327690 cycle) subroutine     *
;******************************************************************
        nop                     ; entry for (delay-11)%5 == 4     |
        nop                     ; entry for (delay-11)%5 == 3     |
        nop                     ; entry for (delay-11)%5 == 2     |
        nop                     ; entry for (delay-11)%5 == 1     |
uDelay  addlw   -1              ; subtract 5 cycle loop time      |
        skpc                    ; borrow? no, skip, else          |
        decfsz  delayhi,F       ; done?  yes, skip, else          |
        bra     uDelay          ; do another loop                 |
        return                  ; return with C = Z = 0           |
 
;******************************************************************
        end

Mike the RCLK SRCLK pins are what you have as LAT CLK right ? In post 25 I'm using that SCH
 
Last edited:
Hi Burt. Sorry so late.

In post 25 I'm using that SCH

The program and logic diagram in post #25 go together. I updated the drawing with pin numbers.

Mike the RCLK SRCLK pins are what you have as LAT CLK right ?
Yes, LAT = RCLK = ST_CP and CLK = SRCLK = SCK = SH_CP, etc. Modified drawing below...

I'll take a look at your program listing momentarily...

74hc595-8-bit-backpack-png.69715
 

Attachments

  • 74HC595 8-bit Backpack.png
    74HC595 8-bit Backpack.png
    23.3 KB · Views: 724
It's not working the code looks right in mpsim but on hardware it's showing boxes
I wish I had a logic tool that could read all 8 pins on the lcd but I don't but give me a week or two and I will.

I can't see any thing missing the 595 is working I can watch 4 pins. My sugar messed up make's it hard to sit and read code.
 
Well Im sure i found the problem I have a bad pin on my 18f1220 I guess i wore it out lol.
 
You misunderstood but I looked at your shift-1 software and it clearly shows that you send four bytes to the 74HC595 in order to get one byte to the LCD... (1) send upper nibble with E high, (2) send upper nibble with E low, (3) send lower nibble with E high, and (4) send lower nibble with E low.
...

Ah, I understand what you are saying now. :)

That will be common to any driver that uses 4bit interface, (as you know) it requires two nibbles to be sent as two separate events. So any 8bit (74HC595 etc) shift register implementation will require sending two nibbles, and two e-clock events.

My point was that my one-wire shift-1 implementation sends 7 bits of data to the LCD pins for every shifted byte, which is the same data functionality as a 3-wire implementation of a shift register.

If you can drive the LCD in 8bit mode (which requires the shift register to drive 10 LCD pins), with e-clock pulse, and do it from sending one byte to a shift register IC I would like to see that. ;)
 
Burt,

Thanks for trying. I really appreciate it.

Aaron,

I built a prototype this morning and it came up first try (I love it when that happens). Anyway, here is picture proof that the K8LH 3-Pin 74HC595 LCD 8-Bit Interface Mode Backpack is a "working" design. I'm using the 18F14K22 program and schematic from my earlier post. The circuit includes an LCD contrast pot and a 100nf bypass cap which are not shown on the schematic.

To recap... The backpack uses three I/O pins from the uC and drives the LCD in 8-bit interface mode. It's pretty darned fast, too, since you only have to write one byte to the 74HC595 to get one byte into the LCD.

Please let us know how it's going.

Cheerful regards, Mike

k8lh-595-8-bit-working-jpg.69722

k8lh-595-8-bit-proto-front-jpg.69721

k8lh-595-8-bit-proto-back-jpg.69720

74hc595-8-bit-backpack-png.69723
 

Attachments

  • K8LH 595 8-Bit Proto Back.JPG
    K8LH 595 8-Bit Proto Back.JPG
    172.1 KB · Views: 662
  • K8LH 595 8-Bit Proto Front.JPG
    K8LH 595 8-Bit Proto Front.JPG
    138.2 KB · Views: 633
  • K8LH 595 8-Bit Working.JPG
    K8LH 595 8-Bit Working.JPG
    170.4 KB · Views: 732
  • 74HC595 8-bit Backpack.png
    74HC595 8-bit Backpack.png
    23.3 KB · Views: 746
Last edited:
It worked for me to in sim I check the pic I was using and I'm not getting any output on AN2 it's blown. I should of used a new chip this one had tested God only knows how much code I've programmed in it.

That was driving me crazy I couldn't see any thing wrong with the code it looked great it sim great.

I had it wire as you showed the dang AN2 pin is dead on my test PIC 5 years of changing code killed it LOL
 
OK Mike
Now I have to be dumb. In your '8 bit LCD Interface' schematic, I thought I figured out what the section in the lower right corner was(that shows up in blue). But I don't see anything like that on your board. So, 1st of all what is it? and
2nd is it in your board or is it not needed?
Aaron

Burt
I'm going to try your code modified for 1220 on one of mine. Thanks
 
Hi Aaron,

Sorry for the confusion. The schematic you're referring to shows how to add push button switches to the backpack. My prototype does not have any switches (they're not needed). Here's another version of the schematic without the switch option (bypass capacitor not shown);

Regards...

k8lh-3-pin-74hc595-lcd-8-bit-mode-backpack-jpg.69752
 

Attachments

  • K8LH Serial LCD Backpack 2.jpg
    K8LH Serial LCD Backpack 2.jpg
    36.8 KB · Views: 321
  • K8LH 3-Pin 74HC595 LCD 8-Bit Mode Backpack.jpg
    K8LH 3-Pin 74HC595 LCD 8-Bit Mode Backpack.jpg
    57.1 KB · Views: 1,377
Last edited:
It's your Code, I just changed the code for a 18f2550 and set Hello on the first line.
It would of worked on the dang 18f1220 but it had A bad pin on porta.2 it cant putout power.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top