This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LCD initialization problem

Other Parts Discussed in Thread: TM4C123GH6PGE

hi,

I want to interface JHD204A LCD to my controller(TM4C123GH6PGE). LCD is of 5x8 dots. I configured this LCD with my controller using parallel communication with 8-bit data. After i given power i'm getting block boxes in fisrt and third lines. Sometimes i got cursor at first line. could plese tell me what was the problem with my code. I posted code below.

int
main(void)
{

ROM_FPULazyStackingEnable();

//
// Set the system clock to run at 50MHz from the PLL
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);

////////////////////////////////////////////////////// DATA PINS ///////////////////////////////////////////////////////////////////////

ROM_GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, GPIO_PIN_0);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, GPIO_PIN_1);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, GPIO_PIN_2);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, GPIO_PIN_3);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, GPIO_PIN_4);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, GPIO_PIN_5);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, GPIO_PIN_6);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, GPIO_PIN_7);

////////////////////////////////////////////////////OTHER PINS /////////////////////////////////////////////////////////////////////////////////

ROM_GPIOPinTypeGPIOOutput(GPIO_PORTL_BASE, GPIO_PIN_0); //RS
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTL_BASE, GPIO_PIN_1); //R/W
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTL_BASE, GPIO_PIN_2); //En

lcdinit();

commandsend(0x01);
commandsend(0x80);
datastring("hello");
commandsend(0xC0);
 datastring(" world");
commandsend(0x80);

while(1)
{

}

}

void lcdinit()
{

commandsend(0x38);
commandsend(0x38);
commandsend(0x38);
commandsend(0x06);
commandsend(0x0F);
//commandsend(0x0E);
commandsend(0x01);
commandsend(0x80); //80

}

void commandsend(unsigned char a)
{
char temp;

//higher nibble
ch=a;
temp=a;


GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_2,0X00);

GPIOPinWrite(GPIO_PORTJ_BASE,GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 , a);


GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_0,0X00); //rs=0;


GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_1,0X00); //r/w


GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_2,0X04); //en=1


SysCtlDelay(100000);

GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_2,0X00); //en=0


SysCtlDelay(100000);

}

void datasend(unsigned char a)
{
GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_2,0X00);


GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 , a);


GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_0,0X01); //rs=1;
GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_1,0X00); //r/w
GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_2,0X04); //en=1
SysCtlDelay(100000);
GPIOPinWrite(GPIO_PORTL_BASE, GPIO_PIN_2,0X00); //en=0
SysCtlDelay(100000);

}

void datastring(unsigned char *str)
{
while(*str)
{
datasend(*(str++));
commandsend(0x0C);
}
}

  • Hi,

    Two little things to be taken into consideration:

    a) read carefully the lcd data sheet - this display having four rows, has four different addresses for each display line.

    b) again, your data sheet has an code example, written in C - although is for the old 8051 micro, still can be used as template for your code; only the lowest level functions need to be written with Tiva in mind, the rest can be used "as is" for your case.

    Petrei

  • Radhika Anabathula said:
    After giving power...getting block boxes...first and third lines. Sometimes i get cursor at first line.

    Such is the result of power being applied, contrast set "reasonably" and initialization from one row to two rows having failed!  (or the display was mistakenly used in 1 row/line mode)

    Although 4 lines - the display must be initialized into 2 rows.  Rows 2 & 4 will only (ever) appear when the display is initialized as 2 rows.  (rows 1, 3 are default - for single row - row 3 is the "overflow" from row 1)

    To my mind - as Petrei notes - your (8051-based, past code) violates the required set-up time of RS & RW (both) to E.  That timing is clearly denoted w/in HD44780/clone data sheets - your TM4C - being far faster than 8051 - is surely violating, "E's set-up timing."  I note this code defect in both your character & command listings.

    Initialization code is required - I've posted here multiple times - yet your review of the HD44780 data sheet is necessary and it's "there" that you'll find "known good" (i.e. horse's mouth) init code.

     

  • Thanks,

    Ireffered HD44780 command set. for first line 0x80, second line 0xC0, third line 0x94 and fourth line 0xD4. I used upto second line in my code. but I not even getting cursor also. And please tell me what is the function set value i need to set, in that list they given only for single line and 2-line. But I'm using 4-line each withmode 20 characters and in 8-bit mode please give some suggetions where i need to do modifications in my code.

    thanks&regars

    radhika

  • Hi, 

    In the data sheet, page 12, Command "D" shows you how to make display ON, how to show cursor, if needed and how to blink the character at cursor, so read it carefully, it is not difficult.

    You need to modify the display_on command to show the cursor, again, if needed. (I never used it,...)

    Petrei

  • Ya i used 0x0F command to on display and cursor blinking. but not yet all showing cursor as well as data.

  • Hi,

    Two more things: 

    a) did you noticed also the command "E" on the same page 12? (Cursor shift = cursor movement)

    b) did you initialized the display as related on page 10? All ( most of) the commands related there must be used in that order, and more important, the delays must be respected, as accurate as possible. Do not insert for instance, delays of milliseconds when showing characters, only 40 microseconds will be enough, because the display time will become big and may interfere in a wrong way with the rest of your application.

    Petrei

  • hi,

    Yes i used 0x0E also. for delay purpose i used  SysCtlDelay(100000); function is this correct way to produce 10ms delay.

  • Hi,

    The function used is correct, but for the count (parameter to be passed): one count is equivalent of three machine cycles, aka 60ns for your setting at 50MHz, so for a delay of 40 microseconds the count should be 40/0.06=666.Count yourself for the other delays. Verify it: make a repetitive loop and set a GPIO pin high before entering the function and set it low after the function is finished. ( hint: add the delay again inside the loop, after setting the pin low, to have a good display on oscilloscope).

    Petrei

  • Thanks,

    here my processor is 80 MHz operation. i'm using 16MHz as PLL. then how to calculate 10ms delay manually. before i used SysCtldelay(100000), this is producing 10 ms delay i verified this in Oscilloscope. 

  • Hi,

    I gave you all elements needed to perform all settings. I will not continue. Good luck.

    Petrei

  • Petrei said:
    I will not continue. Good luck.

    I agree - and your "self-verification" (2x!) of, "Not working" defies all logic!  (and will likely "suck-in" hopeful/needy others - who will then become muddied in this deep/twisting swamp)

    Should you have, "Optimizations" on or too high - your "hoped for" delays may be "swallowed" - thus your code will have no chance to run.

  • cb1_mobile said:

    I will not continue. Good luck.

    I agree - and your "self-verification" (2x!) of, "Not working" defies all logic!  (and will likely "suck-in" others - who will then become muddied in this deep/twisting swamp)

    [/quote]

     And again verified himself other than who provided help...

     I propose a black listing in parallel to the first request of forum level splitting...

     Courtesy in first to take thank to who provided help!!!!

     CB1, Petrej, I am just discouraged from follow these forum, I think is better help someone with real problem and I suppose we like to have similar help when we are so unfortunate to encounter one.

  • Roberto Romano said:
    have similar help when we are so unfortunate to encounter one.

    In our small group's case - that's (almost) every other day!  (Ratz)  (and where is that damn, "Self-Verify" button?)