LCD

Thread Starter

KansaiRobot

Joined Jan 15, 2010
324
Hello and thanks always

I apologize becuase this must be the stupidest question ever but I would appreciate if someone help me.
Tired of 7segs I bought a LCD. This one over here

now you see the connections to the right....? How do I connect this? Ultimately I want to connect this to a board but in the meantime I also want to connect it to a breadboard.
Now I think the most elegant solution would be something like


However I dont have that kind of connector :confused:
Another option is the "Pin headers" but you see these 2 rows of pins? they are so close to each other it is not possible to connect it to a breadboard:arghh:

Any suggestions...?

P.S. Also do you know any tutorial or resource where I can learn about these basic things: ergo connectors and stuff
 

JohnInTX

Joined Jun 26, 2012
4,787
I think the TS's problem is that the row spacing on the display header is .100" and the breadboard spacing between rows is .300". If you buy them with long tails, you can put a Z bend in the long ends of the headers @nsaspook shows to make the spacing fit the breadboard. You also could use a piece of .100" perfboard to mount one row directly and the other spaced 2 rows over and add jumpers as required (some perfboards have several holes connected together, that would help).

These and these headers have longer (.318") tails to give you something to work with.

To init the LCD and actually display something, see this thread.
 

nerdegutta

Joined Dec 15, 2009
2,684
Or you can do it like this:
lcd1.JPG
lcd2.JPG
I've soldered a 10 pin header on a strip board, and used short wires from the board to the LCD.
PIN OUT
1 -> GND
2 ->VDD
3 -> POT
4 -> RS
5 -> RW
6 -> E
7 -> D4
8 -> D5
9 -> D6
10 -> D7

This fits perfectly on a bread board.
 

ErnieM

Joined Apr 24, 2011
8,377
Given a solderless breadboard... one could always solder on insulated solid bus wires and dress each one into the correct breadboard row. Something to mechanically hold things in place would be a blessing.

As far as the code to drive these, look over the multiple threads on this very forum for other people driving these. I've yet to see one of these that doesn't use the extremely common HD44780 chip (or clone) to drive them. Google "HD44780 code" or "LCD code" will bring up lots of hits.
 

Thread Starter

KansaiRobot

Joined Jan 15, 2010
324
Me thinks you chose the wrong thing to buy.
Can you tell me why?

Well, I did my first try and it didnt work :oops:. The LCD does not even turn on. I am using only 4 wires (so 4-bit nibble mode) so I am suspecting something in the very first initialization (when it is still 8-bit) is not correct. Guess it is time go go back and study...
 

JohnInTX

Joined Jun 26, 2012
4,787
The link in post 3 above has a schematic and working code for XC8. It inits the LCD and does some messages. If you read the thread, you'll get an idea of what we did to implement an lcd. Lots of other threads here as well.
 

Thread Starter

KansaiRobot

Joined Jan 15, 2010
324
The link in post 3 above has a schematic and working code for XC8. It inits the LCD and does some messages. If you read the thread, you'll get an idea of what we did to implement an lcd. Lots of other threads here as well.

Thank you . I read the code and it is similar to what I did but I am sure I am making a mistake somewhere.
The code is for P1459 right? I am implementing it on a PIC18F4553 so I will have to change some ports (from C to D), so I will edit the code try it and let you know...:)

Also, I have to report that the LCD is working, it lights up and so far prints some strange lines in the incorrect position, so I guess that is just an improvement lol.
 

Thread Starter

KansaiRobot

Joined Jan 15, 2010
324
@KansaiRobot post your code if you want help with the initialisation.
I ve tried two codes
one is
Code:
void lcd_ini ( void )
{
TRISB &= 0xE3;  //Initialize B2, B3 and B4 as output
lcd_port_dir &= 0x0F; //Initialize D4,D5,D6 and D7 as output
dis_cmd ( 0x02 ); //  Clears the display and initialize LCD in 4-bit mode.
//dis_cmd(0x33);
//dis_cmd(0x32);

dis_cmd ( 0x28 ); // 0010 1000 to initialize LCD in 2 lines, 5X7 dots and 4bit mode.  //FUNCTION SET DL= 4 bits 5x7 dots(only option for 2 lines)
dis_cmd ( 0x0C );    //0000 1100    //Display ON/OFF cursor not displayed  not blinking
dis_cmd ( 0x06 );    //0000 0110    //Entry Mode Set  increment Address counter no display shift
dis_cmd ( 0x80 );    //1000 0000   //Set DDRAM Address
dis_cmd ( 0x01 );    //0000 0001   // Clear Display
delay_ms ( 500 );
}
and the other one is one I found here in the forum (although I added the delay functions)

Code:
/* initialise the LCD - put into 4 bit mode */
void
lcd_init()
{
    char init_value;

    ADCON1 = 0x06;  // Disable analog pins on PORTA

    init_value = 0x3;
    TRISA=0;
    TRISD=0;
    LCD_RS = 0;
    LCD_EN = 0;
    LCD_RW = 0;

//    DelayMs(15);    // wait 15mSec after power applied,
    Delay10TCYx(375);
    LCD_DATA     = init_value;
    LCD_STROBE();
//    DelayMs(5);
    Delay10TCYx(125);

    LCD_STROBE();
//    DelayUs(200);
    Delay10TCYx(5);
    LCD_STROBE();
//    DelayUs(200);
    Delay10TCYx(5);
    LCD_DATA = 2;   // Four bit mode
    LCD_STROBE();

    lcd_write(0x28); // Set interface length
    lcd_write(0xF); // Display On, Cursor On, Cursor Blink
    lcd_clear();    // Clear screen
    lcd_write(0x6); // Set entry Mode
}
 

Thread Starter

KansaiRobot

Joined Jan 15, 2010
324
Oh sorry.

First the first one

Code:
/*
* File:   main.c
*  In this program  we are going to program
* how to show messages on a LCD connected to the microprocessor 18F4553
*
* The Pins are going to be the following:
*
*   PIC 18F4553                       LCD
*   RB2                               En
*   RB3                               RW
*   RB4                               RS
*
*   RD4                               D4
*   RD5                               D5
*   RD6                               D6
*   RD7                               D7
*
*
* Created on 2015/08/05, 11:05
*/

#include <stdio.h>
#include <stdlib.h>
#include <p18f4553.h>

//Configuration Bits
#pragma config PLLDIV = 5  //(20MHz crystal div by 5 preescale
#pragma config CPUDIV = OSC4_PLL6  //we get 16 MHz
#pragma config FOSC = INTOSC_HS   //Internal oscillator, HS oscillator used by USB (INTHS)
#pragma config USBDIV = 2  //Usb from PLL
#pragma config FCMEN    = OFF   //fail safe clock disabled
#pragma config IESO = OFF  //oscillator switch over mode disable
#pragma config PWRT = OFF
#pragma config BOR = ON  //
#pragma config BORV=3 //
#pragma config VREGEN = ON //
#pragma config WDT = OFF
#pragma config WDTPS = 32768


#pragma config CCP2MX = ON
#pragma config PBADEN = OFF
#pragma config LPT1OSC = OFF

#pragma config MCLRE = ON

#pragma config STVREN = ON
#pragma config LVP = OFF
#pragma config ICPRT = OFF
#pragma config XINST = OFF
#pragma config DEBUG = OFF
#pragma config WRTD = OFF

//LCD Control pins
#define rs PORTBbits.RB4
#define rw PORTBbits.RB3
#define en PORTBbits.RB2

//LCD Data pins
#define lcdport PORTD
#define lcd_port_dir TRISD

#define LEDPin LATEbits.LATE2 //Define LEDPin as PORT E Pin 2
#define LEDTris TRISEbits.TRISE2 //Define LEDTris as TRISE Pin 2



void lcd_clear ( void );
void lcd_2nd_line ( void );
void lcd_1st_line ( void );
void lcd_ini ( void );
void dis_cmd ( unsigned char cmd_value );
void dis_data ( unsigned char data_value );
void lcdcmd ( unsigned char cmdout );
void lcddata ( unsigned char dataout );
void delay_ms ( int delay );

int main(int argc, char** argv)
{

unsigned int i = 0, a = 3, b = 3;
unsigned char data1 [] = "Kansai Robot";
unsigned char data2 [] = "    LCD demo   ";

OSCCON = 0x72; // 0111 0010 set CPU Frequency as 8 MHz

LEDTris = 0; // Set LED Pin data direction to OUTPUT
LEDPin = 1; // Set LED Pin

lcd_ini (); // LCD initialization

//Start up display on LCD

// Display the first line in the display
while ( data1 [i] != '\0' )
   {
    dis_data ( data1 [i] );
    delay_ms ( 200 );
    i++;
    }
i = 0;

//Change line
lcd_2nd_line ();

//Display the second line in the display
while ( data2 [i] != '\0' )
   {
    dis_data ( data2 [i] );
    delay_ms ( 200 );
    i++;
   }
i = 0;

delay_ms ( 3000 );


//Some other operations






while(1)
{
     LEDPin = ~LEDPin ;// Togle LED Pin
     delay_ms(1000);
// ;  //nothin
}

    return (EXIT_SUCCESS);
}// end of main


//======================== LCD routines definitions ========================//

void delay_ms ( int delay )
{int ms, i;
for ( ms = 0; ms < delay; ms ++ )
    for ( i = 0; i < 50; i ++ );
}

void lcd_ini ( void )
{
TRISB &= 0xE3;  //Initialize B2, B3 and B4 as output
lcd_port_dir &= 0x0F; //Initialize D4,D5,D6 and D7 as output


/* dis_cmd ( 0x02 ); //  Clears the display and initialize LCD in 4-bit mode.
//dis_cmd(0x33);
//dis_cmd(0x32);


*/

lcdport &= 0x0F;
lcdport |= 0x30;
rs=0;
rw=0;
//Strobe
en = 1;   //go!
delay_ms ( 50 );
en = 0;  //Ok it is enough
delay_ms ( 50 );

//Strobe
en = 1;   //go!
delay_ms ( 50 );
en = 0;  //Ok it is enough
delay_ms ( 50 );

//Strobe
en = 1;   //go!
delay_ms ( 50 );
en = 0;  //Ok it is enough
delay_ms ( 50 );

lcdport &= 0x0F;
lcdport |= 0x20;

//Strobe
en = 1;   //go!
delay_ms ( 50 );
en = 0;  //Ok it is enough
delay_ms ( 50 );


dis_cmd ( 0x28 ); // 0010 1000 to initialize LCD in 2 lines, 5X7 dots and 4bit mode.  //FUNCTION SET DL= 4 bits 5x7 dots(only option for 2 lines)
dis_cmd ( 0x0E );    //0000 1100    //Display ON/OFF cursor not displayed  not blinking
dis_cmd ( 0x06 );    //0000 0110    //Entry Mode Set  increment Address counter no display shift
dis_cmd ( 0x80 );    //1000 0000   //Set DDRAM Address
dis_cmd ( 0x01 );    //0000 0001   // Clear Display


/*
dis_cmd ( 0x28 ); // 0010 1000 to initialize LCD in 2 lines, 5X7 dots and 4bit mode.  //FUNCTION SET DL= 4 bits 5x7 dots(only option for 2 lines)
dis_cmd ( 0x0C );    //0000 1100    //Display ON/OFF cursor not displayed  not blinking
dis_cmd ( 0x06 );    //0000 0110    //Entry Mode Set  increment Address counter no display shift
dis_cmd ( 0x80 );    //1000 0000   //Set DDRAM Address
dis_cmd ( 0x01 );    //0000 0001   // Clear Display
*/
delay_ms( 500 );
}

void dis_cmd ( unsigned char cmd_value )
{  //We send a command in two nibbles
unsigned char cmd_value1;
cmd_value1 = cmd_value & 0xF0; //mask lower nibble because PD4-PD7 pins are used.
lcdcmd ( cmd_value1 );         // send to LCD
cmd_value1 = ( ( cmd_value << 4 ) & 0xF0 ); //shift 4-bit and mask
lcdcmd ( cmd_value1 ); // send to LCD
}

void dis_data ( unsigned char data_value )
{
unsigned char data_value1;
data_value1 = data_value & 0xF0;
lcddata ( data_value1 );
data_value1 = ( ( data_value << 4 ) & 0xF0 );
lcddata ( data_value1 );
}

void lcdcmd ( unsigned char cmdout )
{
lcdport &= 0x0F;  //set the pins to 0
lcdport |= cmdout; // then set those pins to the command
rs = 0;   //Command
rw = 0;   //write
en = 1;   //go!
delay_ms ( 50 );
en = 0;  //Ok it is enough
delay_ms ( 50 );
}

void lcddata ( unsigned char dataout )
{
lcdport &= 0x0F;  // set the pins to 0
lcdport |= dataout;  // then set those to the data
rs = 1;  //Data
rw = 0;  //Write
en = 1;  //go!
delay_ms ( 50 );
en = 0;  //ok it is enough
delay_ms ( 50 );
}

void lcd_clear(void)
{
dis_cmd(0x01); //0000 0001  //Clear Display
delay_ms(10);
}
void lcd_2nd_line(void)
{
dis_cmd(0xC0); //1100 0000  (DDRAM address 40)
delay_ms(1);
}

void lcd_1st_line(void)
{
dis_cmd(0x80); //1000 0000  (DDRAM address 00)
delay_ms(1);
}
I ve changed a little the initialization function according to this thread indications but still all I see is garbage
 

Thread Starter

KansaiRobot

Joined Jan 15, 2010
324
RB2, RB3, RB4 are also analog inputs. Do you have to take that into consideration?

Have you a schematic to show?
I added
Code:
ADCON1=0x0F; // All Digital Inputs
but the result is still the same.


I have the schematic in a format only readable to a program in the intranet here, and the network seems broken sorry. I ll post it when I can

EDIT: Also I ve checked and the PBADEN configuration bit is off so they are digital inputs on reset
 
Last edited:

nerdegutta

Joined Dec 15, 2009
2,684
Should it be digital inputs? I was thinking more in the line of disabling them...

You could perhaps take a screenshot?

Network problems sucks!
 

Thread Starter

KansaiRobot

Joined Jan 15, 2010
324
Should it be digital inputs? I was thinking more in the line of disabling them...

You could perhaps take a screenshot?

Network problems sucks!
Actually they are outputs since they control the RS,RW and EN of the LCD
their TRIS are made 0

the pic
Cap1.jpg
As you see , just garbage lines
 

Thread Starter

KansaiRobot

Joined Jan 15, 2010
324
Trying to rewrite JohnInTX code for 18F4553 but compilation fails on the delay function
it says
Code:
main.c:176: error: (1355) in-line delay argument too large
therefore since _delay_ms(300) is not possible I replaced it by three times __delay_ms(100)

Anyway, results. It does not work :(
Cap2.jpg

I ll post the code next
 
Last edited:

nerdegutta

Joined Dec 15, 2009
2,684
Trying to rewrite JohnInTX code for 18F4553 but compilation fails on the delay function
it says
Code:
main.c:176: error: (1355) in-line delay argument too large
therefore _delay_ms(300) is not possible???
Try to make a for-loop
C:
for(i=0;i<10;i++){
__delay_ms(30);
}
or something. It should do the same.
 

Jswale

Joined Jun 30, 2015
121
To make sure initialization is correct you need to eliminate all data write functions from your code and see if you are still getting those lines or if the LCD just gives blocks (hinting that it is ready for operation). If it still gives those lines then something is wrong.
 
Top