Managing LCD with pic

Thread Starter

JridiHamza

Joined Jul 22, 2014
18
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
 

shteii01

Joined Feb 19, 2010
4,644
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.
 

Thread Starter

JridiHamza

Joined Jul 22, 2014
18
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.
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"); }}
 

MaxHeadRoom

Joined Jul 18, 2013
28,696
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.
 

JohnInTX

Joined Jun 26, 2012
4,787
You use two separate Enable signals. That is what MrChips already told you.
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.
 

MrChips

Joined Oct 2, 2009
30,821
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.
 

Thread Starter

JridiHamza

Joined Jul 22, 2014
18
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.
how do I chose the target display that's my biggest problem???
 

JohnInTX

Joined Jun 26, 2012
4,787
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.
 

Attachments

shell.albert

Joined Jul 23, 2014
21
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.
 

THE_RB

Joined Feb 11, 2008
5,438
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. :)
 

Thread Starter

JridiHamza

Joined Jul 22, 2014
18
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.
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
}}
 

Attachments

MrChips

Joined Oct 2, 2009
30,821
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:

Rich (BB code):
void LCD_Select1(void)
{
   // output logic LOW to LCD_ENABLE2
   // configure LCD_ENABLE1 as input
}

void LCD_Select2(void)
{
   // output logic LOW to LCD_ENABLE1
   // configure LCD_ENABLE2 as input
}
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:

Rich (BB code):
void LCD_Select1(void)
{
   // output logic HIGH to LCD_ENABLE1
}

void LCD_Select2(void)
{
   // output logic LOW to LCD_ENABLE1
}
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
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.
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:
Rich (BB code):
#define LCD_SELECT PIN_B7  //name the selector pin 'SELECT'

void LCD_Select0(void)
{
   // output logic LOW to LCD_SELECT
 LCD_SELECT = 0;
}

void LCD_Select1(void)
{
   // output logic HIGH to LCD_SELECT
 LCD_SELECT = 1;
}
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.
Rich (BB code):
void init_Displays(void)
{
 LCD_Select0();
 lcd_init();
 lcd_putc("0 Initialized");

 LCD_Select1();
 lcd_init();
 lcd_putc("1 Initialized");
}
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:
Top