Managing LCD with pic

Discussion in 'Embedded Systems and Microcontrollers' started by JridiHamza, Jul 22, 2014.

  1. JridiHamza

    Thread Starter New Member

    Jul 22, 2014
    18
    0
    Hi everyone
    I want to manage 2 LCD displays with 1 pic microcontroller
    I want to know how to write in each one a different message,anyone can help me on this plz
    note: I use CCS c compiler
     
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,388
    497
    Connect one lcd to one port, connect second lcd to another port. Copy the lcd program from one of the tutorials, modify it to send messages to either one of the lcd.
     
  3. JridiHamza

    Thread Starter New Member

    Jul 22, 2014
    18
    0
    I did that but I didn't know how chose the lcd that I want to display on it the message
    that's my program for one lcd

    #include <lcd.h>
    #use delay(clock=20000000)
    #fuses HS,NOWDT,NOPROTECT,NOPUT, NOBROWNOUT,NOLVP
    #define LCD_ENABLE_PIN PIN_A0
    #define LCD_RS_PIN PIN_A2
    #define LCD_RW_PIN PIN_A1
    #define LCD_DATA4 PIN_C4
    #define LCD_DATA5 PIN_C5
    #define LCD_DATA6 PIN_C6
    #define LCD_DATA7 PIN_C7
    #include <lcd.c>
    #define use_portc_lcd TRUE

    void display_ES(void)
    {
    while(true)
    {
    lcd_init();
    lcd_putc("message1"); }}
     
  4. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,526
    2,369
    The input impedance is usually fairly high, you may be able to parallel the data buses to one port and use separate control , E, RS, RW signals.
    Max.
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,360
    Parallel the DATA pins, RS and R/W.
    Use separate controls for E.
    Hence you only need 1 additional output line.
     
    ErnieM likes this.
  6. JridiHamza

    Thread Starter New Member

    Jul 22, 2014
    18
    0
    is there a method that I can deactivate one LCD and display on the other then I do the opposite??
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Yes, and that is even before you specify just what "deactivate" means to you.
     
  8. JridiHamza

    Thread Starter New Member

    Jul 22, 2014
    18
    0
    I mean to make a message displays into one lcd not into the other one
     
  9. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,388
    497
    You use two separate Enable signals. That is what MrChips already told you.
     
  10. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,025
    Except that if you use the compiler's libraries, you don't have that option. It's designed to support one enable only.

    You could write your own LCD routines or use some external logic to route the ENABLE signal to one of the two displays according to an additional output that you manually select before using any library routine. If you go this route, you'll have to select one display, run lcd_init() then select the other and run lcd_init() again. Any subsequent writes would be preceded by selecting the target display. Other than that, what the others have indicated is perfectly workable.
     
  11. JridiHamza

    Thread Starter New Member

    Jul 22, 2014
    18
    0
    sorry I'm a little newbie on this you mean per exemple that I should add a line in the program like this
    #define LCD_ENABLE_PIN PIN_B0
     
  12. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,360
    No, that wouldn't work. You cannot use the lcd_putc() library function.
    That is what you get for using library functions.
    Learn to write your own functions. It's not difficult.
     
    JridiHamza likes this.
  13. JridiHamza

    Thread Starter New Member

    Jul 22, 2014
    18
    0
    how do I chose the target display that's my biggest problem???
     
  14. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,360
    JridiHamza likes this.
  15. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,025
    Like the others, I'd write my own routines but if you want to try the libraries, this external selector should work.

    Set the new output port to route ENABLE to the desired display, then write away.

    Have fun.

    EDIT Don't forget to pull the ENABLE down at the PIC with a 10K-68K resistor to avoid spurious enables during RESET.
     
    JridiHamza likes this.
  16. shell.albert

    New Member

    Jul 23, 2014
    8
    0
    To driver two LCDs with one PIC controller is not difficult. From above mentioned,I can see the LCDs that you are using are serial interface with data ports,E,R/W,etc,just like a LCD1602 module. Share data ports can reduce pin numbers.share R/W and other common signals.
    The only different is to control CS(chip select) signal alone.
     
  17. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Did you read the other posts in this thread? :)

    As another method (expanding on JohnTX's idea), it can be done with the library code, if you don't mind sacrificing two more port pins.

    Connect the PIC E output pin to each LCD E input through a 2k2 resistor. Then connect two more PIC pins, one to each LCD E pin;
    * If one of those PIC pins is grounded and an output pin that E signal will not work.
    * If the PIC pin is switched to high impedance (an input) then that E pin will work.

    That will allow you to set those two pins as needed, then use the library LCD functions. Total cost 2 pins and two resistors. :)
     
    JohnInTX, MrChips and JridiHamza like this.
  18. JridiHamza

    Thread Starter New Member

    Jul 22, 2014
    18
    0
    this is the shemas bloc and my code but it doesn't work
    can you tell me what's rong plz??


    #include <lcd.h>
    #define LCD_ENABLE_PIN PIN_A2
    #define LCD_ENABLE_PIN PIN_B7
    #define LCD_RS_PIN PIN_A0
    #define LCD_RW_PIN PIN_A1
    #define LCD_DATA4 PIN_C4
    #define LCD_DATA5 PIN_C5
    #define LCD_DATA6 PIN_C6
    #define LCD_DATA7 PIN_C7
    #include <lcd.c>
    void main()
    {
    lcd_init();
    while(TRUE)
    {
    output_low(pin_b7);
    lcd_putc("message 1");
    output_high(pin_b7);
    lcd_putc("message 2");//TODO: User Code
    }}
     
  19. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,360
    You now have three suggestions for interfacing two LCD modules:

    1) MrChips - Write your own LCD functions, requires one additional pin.
    2) JohnInTX - Use library functions, requires one additional pin and external gates.
    3) THE_RB - Use library functions, requires two additional pins and two resistors.

    The solution provided by THE_RB requires the least amount of effort.

    You cannot use two defines such as:

    #define LCD_ENABLE_PIN PIN_A2
    #define LCD_ENABLE_PIN PIN_B7

    Learn how the #define preprocessor directive works.

    Leave LCD_ENABLE_PIN as

    #define LCD_ENABLE_PIN PIN_A0

    Now you have to create two new constants:

    #define LCD_ENABLE1 PIN_A2
    #define LCD_ENABLE2 PIN_B7

    Before you call any LCD library functions, call a LCD select function such as:

    LCD_Select1();

    or

    LCD_Select2();

    Here is the pseudo code for the two functions:

    Code ( (Unknown Language)):
    1.  
    2. void LCD_Select1(void)
    3. {
    4.    // output logic LOW to LCD_ENABLE2
    5.    // configure LCD_ENABLE1 as input
    6. }
    7.  
    8. void LCD_Select2(void)
    9. {
    10.    // output logic LOW to LCD_ENABLE1
    11.    // configure LCD_ENABLE2 as input
    12. }
    13.  
    If you have wired your circuit using the solution provided by JohnInTX, you can still use the scheme outlined above. Modify the functions to control the selection of the E signal to the desired LCD module.

    Here is the pseudo code for this:

    Code ( (Unknown Language)):
    1.  
    2. void LCD_Select1(void)
    3. {
    4.    // output logic HIGH to LCD_ENABLE1
    5. }
    6.  
    7. void LCD_Select2(void)
    8. {
    9.    // output logic LOW to LCD_ENABLE1
    10. }
    11.  
     
    Last edited: Jul 23, 2014
    JridiHamza likes this.
  20. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,025
    Per the OP's PM, some clarifications for the external gate method. In this case the new pin is a selector so name it that way. The display designations match my original sketch.
    On the schematic, the single pull-down resistor should be on the PIC pin (RB7), not the output of the gates. Its purpose is to hold E at '0' when the PIC is coming out of reset before initializing the PIC's I/O ports. You don't need/want the push buttons on the gate outputs.

    Don't forget to complete the hardware connections to the display (Vdd, Vss, VEE etc.)

    Your code does not show any initialization of PIC IO i.e. setting up TRIS, ADCONx, etc. You have to do that in any case.

    As MrChips says, for either of the LCD_Selectx() hardware methods you'll have to select the desired display before ANY write to the LCD, including init.
    Code ( (Unknown Language)):
    1.  
    2. void init_Displays(void)
    3. {
    4.  LCD_Select0();
    5.  lcd_init();
    6.  lcd_putc("0 Initialized");
    7.  
    8.  LCD_Select1();
    9.  lcd_init();
    10.  lcd_putc("1 Initialized");
    11. }
    12.  
    Note that if you use RB's clever solution, the logic selecting then writing the LCD is the same, just the LCD_Select routines are different. MrChips shows how its done.
     
    Last edited: Jul 23, 2014
    JridiHamza likes this.
Loading...