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.
Mike & Burt

FINALLY! I got it.
I suppose because of the way I have MPLAB set up and how I have the breadboard wired for ICSP, I had to change the config bits to INTIO2 and the MCLE to off. I think I also played with OSCCON.
But it works.

Now on to that smart LCD interface which should be a lot easier.

Thanks for all the posts! I have learned much. Aaron
 
Congrats' Aaron. That's great. And thank you, Burt, for the independent verification.

Cheerful regards, Mike
 
Last edited:
Nice work Mike I love the style of code you do in ASM that delay is supper.

This is supper great
Code:
;==================================================================
;  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
 
;******************************************************************
 
...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.
...

It should work, running a separate LCD E line from the micro and 2 micro pins to drive the shift register has been a standard way for a long time. Mainly people use that system for 4bit versions but it has been done plenty of times for 8bit versions too;
**broken link removed**
 
Thanks for the link, Roman. It was very productive. While the author hints that there is a 3-wire 8-bit mode interface, I couldn't find any, other than my old 74HC164 interface, so I asked him about it and he came up with a real gem.

The interface from the Arduino guy is very nice. After re-wiring my prototype backpack and modifying the driver to eliminate the extra clock pulse, it fired right up. I've attached the circuit drawing and modified driver below.

I wonder if this could be turned into a 2 pin 8-bit interface by using an RC integrator between SER and SCK?

Cheerful regards, Mike

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


Code:
;******************************************************************
;  Example 74HC595 LCD 8-bit Interface Mode Backpack Driver       *
;******************************************************************

PutDat
        setc                    ;                                 |
        skpc                    ; skip unconditionally            |
PutCmd
        clrc                    ; rs = 0 (command)                |
        movwf   work            ; save data                       |
        movlw   8               ; use wreg as bit counter         |
putbit
        bcf     dat             ; dat = 0                         |
        btfsc   work,7          ; is it a 0? yes, skip, else      |
        bsf     dat             ; dat = 1                         |
        bsf     clk             ; clk = 1, pulse 'clk' pin        |
        bcf     clk             ; clk = 0                         |
        rlncf   work,F          ;                                 |
        decfsz  WREG,F          ; all 8 bits? yes, skip, else     |
        bra     putbit          ; clock out another bit           |
        bcf     dat             ; dat = 0 (rs = 0)                |
        skpnc                   ; rs = 0? yes, skip, else         |
        bsf     dat             ; dat = 1 (rs = 1)                |
        bsf     ena             ; ena = 1, 'rck' & 'e' pins       |
        bcf     ena             ; ena = 0                         |
        DelayCy(40*usecs)       ; lcd inter-write delay           |
        return                  ;                                 |
 

Attachments

  • 3-Pin 74HC595 LCD 8-Bit Mode Backpack.jpg
    3-Pin 74HC595 LCD 8-Bit Mode Backpack.jpg
    51.6 KB · Views: 743
Last edited:
Is there anyone who can post the complete code and Schematic?

I'm just beginning to learn c and wanted to study it. (So, any and all comments in the "Code" to help me would be great!) I'd like to build this someday too!

Thanks, kv:)

Good job!
 
It's in asm But Mike has the comments on a sample that is C style really neat in sowing the logic to the code.

The SCH is in post 46
 
The SCH is in post 46

Caveat, Burt. There are actually two versions of 3-pin 8-bit lcd interface schematics now. The one in post #46 is the one from the Arduino chaps. If that isn't confusing enough, I'm just getting ready to wire up and test this 2-pin circuit;

k8lh-2-pin-74hc595-8-bit-mode-concept-jpg.69955
 

Attachments

  • K8LH 2-Pin 74HC595 8-Bit Mode Concept.jpg
    K8LH 2-Pin 74HC595 8-Bit Mode Concept.jpg
    60.5 KB · Views: 723
Last edited:
Hey guys, the new 2-Pin 8-Bit design also came up "first try"... Here's a picture of it moments after firing it up for the first time;

**broken link removed**
k8lh-2-pin-74hc595-8-bit-mode-concept-jpg.69955


I'm geeked about this design. Like the K8LH 3-Pin 8-Bit design, only one byte is written to the 74HC595 for each byte going to the LCD. The driver is isochronous and reasonably fast (about 100 microseconds to send each byte to the LCD).

Code:
  /*                                                                *
   *  K8LH 2-Pin 8-Bit 74HC595 LCD low level driver (isochronous)   *
   *                                                                */
   void PutLCD(char work)       // write byte to 74HC595 & LCD
   { char bitctr = 8;           //
     do                         // start of bit clock cycle
     { if(!work.7)              // if b7 is a '0' bit
         clk = 0;               // start clock cycle for a '0'
       delay_us(9);             // charge or drain cap to 3τ
       clk = 0;                 // start clock cycle for a '1'
       clk = 1;                 // clock out the '0' or '1'
       work <<= 1;              // shift next bit into b7
     } while(--bitctr);         // loop until all 8 bits sent
     if(rs == 0) clk = 0;       // make clk pin = rs flag
     ena = 1; ena = 0;          // latch 595, pulse lcd 'e' pin
     clk = 1;                   // always leave clk pin high
   }

   void PutCMD(char pdata)      // lcd command (RS=0)
   { rs = 0; PutLCD(pdata);     // rs = 0, send command
   }                            //

   void PutDAT(char pdata)      // lcd data (RS=1)
   { rs = 1; PutLCD(pdata);     // rs = 1, send data
   }                            //

   void PutDAT(char *pdata)     // lcd data (RS=1) strings
   { while(*pdata)              //
       PutDAT(*pdata++);        //
   }                            //

  /*                                                                *
   *  inititialize lcd (8-bit interface mode)                       *
   *                                                                */
   void lcdinit()               //
   { delay_ms(100);             //
     PutCMD(0x38);              // 8-bit, 2-lines, 5x7 font
     PutCMD(0x0C);              // display on, currsor & blink off
     PutCMD(0x06);              // cursor inc, shift off
     PutCMD(0x01);              // clear display
     delay_ms(2);               // required delay
   }                            //

The RC time constant (τ) is 3.3 microseconds and the driver uses a 10 microsecond (3τ) interval to charge or drain the capacitor on the 74HC595 SER pin just before clocking each bit into the shift register. Here's a diagram showing the RC integrator input (pink line = SCK pin) and output (blue line = SER pin) when using a 4 MHz clock;

rc-timing-png.70091


I have C and assembly language demo programs (18F14K22) for this 2-pin backpack design, if anyone is interested.

Cheerful regards, Mike
 

Attachments

  • rc timing.png
    rc timing.png
    17.8 KB · Views: 451
Last edited:
...
I wonder if this could be turned into a 2 pin 8-bit interface by using an RC integrator between SER and SCK?
...

Sure, that would work. It all really comes down to how complex you want the circuit (and how slow the datarate is) compared to how valuable it is is to save 1 or 2 PIC pins.

Personally I think for hobby type use the "ultimate" serial LCD driver would be an extremely cheap uC with internal clock, that you just send a serial byte to. That allows the benefit of 1 wire control and the simplicity of just loading a byte into the PIC UART to send it to the LCD.

Something like your 8pin PIC serial LCD driver but with the cheapest possible PIC like a 10F, or MSP430 etc, any uC that can be sourced for under 50 cents.

Considering the high production volumes of LCDs I'm kind of surprised the LCD manufacturers don't include a tiny uC on board for UART serial control, they can probably add a uC to their product for 10 to 20 cents. I wouldn't mind paying 20 cents more for LCDs that can run from UART serial.
 
for hobby type use the "ultimate" serial LCD driver would be an extremely cheap uC with internal clock, that you just send a serial byte to. That allows the benefit of 1 wire control and the simplicity of just loading a byte into the PIC UART to send it to the LCD.

This is what I'm working on now. And for a single back pack or two that will last a long time and be used in many projects, CHEAP is under $3. A few more spare pins will allow a beeper to announce a new display and any number of additional features to be dreamed up in the future. Why limit your future creativity by saving $2.
Aaron
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top