Help~~!! Could anyone help me debug the code for LPC1769 & 4-bit 2*16 LCD

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help~~!! Could anyone help me debug the code for LPC1769 & 4-bit 2*16 LCD

939 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by a0105540 on Mon Sep 15 03:00:30 MST 2014
I am trying to attach a 2*16 LCD to my LPC1769 using 4_bit configuration. I found some useful code online and took them as my references to write my own code. However, my friends and i spent three whole days to debug the simple code but nothing happened. I sincerely call for your guys help.

The LCD i use is a rt1602c. I want to display "hello" and "world!" on two separate rows of the screen. But every time i compile, the screen showed "Vellogorld!" or "ello"(row1)&gworld!(row2) or "ello! ello", etc.

[u]The display results are quite random[/u] but i can roughly see "hello world!" there. The position is not stable, which shifts with time.

I attached the lcd.c lcd.h and main.c file below. And i also attached a datasheet for the rt1602c. A website is provided as well if you want to know more about the lcd.(http://www.8051projects.net/lcd-interfacing/lcd-4-bit.php)
0 Kudos
Reply
3 Replies

920 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Pacman on Mon Sep 15 19:01:36 MST 2014
void delay(int count)
{
    int j = 0, i = 0;
    for(j = 0; j < count; j++)
    {
        /* At 60Mhz, the below loop introduces delay of 10 us */
        for(i = 0; i < 35; i++)
        {
            asm volatile("nop");
        }
    }
}


-You need some kind of volatile in there. I've used 'nop', so your loop won't be optimized.
After my changes, please re-calibrate your loop. New value might be something between 26 and 28 (wild guess).
For short delays, I would recommend that you assume the MCU is running at 120MHz. The 1602 displays won't mind if you're waiting a few microseconds longer. The only thing that matters is that your delay should not be too short.
For large delays, it might be a good idea to use a timer.
0 Kudos
Reply

920 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by a0105540 on Mon Sep 15 18:06:22 MST 2014
Thank you so much for your instant response.
I read your suggestions carefully and I do some adjustment. However, the LCD still doesn't perform well. Besides, my LCD sometimes has one line sometimes has two line for the same code. I don't think this causality  is normal either. Does this has anything to do with my code,too?
0 Kudos
Reply

920 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Mon Sep 15 03:39:21 MST 2014
1. Don't rely on software loops in delay();

2.wait_lcd() is incorrect - it doesn't read the second half of status register and testing the state of BUSY while keping E high may be problematic.

3. wait_lcd should be used BEFORE writing new command/data, not after.

4. Do not use |= while writing to port set and clear registers.

5. There is no delay between setting the data and clearing E in lcd_data_write - this seems to be the main problem.
0 Kudos
Reply