Hello everyone, I'd like to interface a 4x20 character LCD. But I can not do it! Finally I arrive boot (the black line disappears) but I do not see the cursor blinking and the characters that I want to write. So I just see whether you already have an interface with LPC1768 and if you do not have a library to share?
So that's not where I am:
Lcd library
void init_LCD(void) { LCD_Light (1) LCD_EN(0) os_dly_wait (100); command (0x30); os_dly_wait (40); command (0x30); os_dly_wait (40); command (0x30); os_dly_wait (40); command (0x38); os_dly_wait (40); command (0x0F); os_dly_wait (40); command (0x01); os_dly_wait (40); command (0x06); os_dly_wait (40); } void command (char data) { LPC_GPIO0->FIOPIN |= (data<<15); /* place data */ LCD_RS(0) LCD_RW(0) LCD_EN(1) os_dly_wait (2); LCD_EN(0) } void write (char data) { LPC_GPIO0->FIOPIN |= (data<<15); /* place data */ LCD_RS(1) LCD_RW(0) LCD_EN(1) os_dly_wait (2); LCD_EN(0) } void write_char(char data) { command (0x38); os_dly_wait (40); command (0x0c); os_dly_wait (40); command (0x06); os_dly_wait (40); write (data); os_dly_wait (40); }
main code
__task void LCD (void) { init_LCD(); write_char (0x30); for (;;) {} }
Best regard
Bernard
with no knowledge of the LPC1768 (have, so far, only worked with ST) under the assumption that you are using a traditional character LCD.
LPC_GPIO0->FIOPIN |= (data<<15); /* place data */
1) does GPIO0 have >23 pins? 2) or'ing tha data without first and'ing to clear the field is not a good idea
Erik
Yes. Just on port 0, I 32-pin. I also try to place the different states of pins (RS, RW, E, DB0-7) directly in hex on the port. And no results. but today I found a logic analyzer. I test tomorrow to see if I am good on different pins at the right time
FIRST you need this
LPC_GPIO0->FIOPIN &= LCB_BITS_MASK; // clear old LCD data LPC_GPIO0->FIOPIN |= (data<<15); /* place data */
Yes, I agree. I think I found the problem. I use a 5V LCD and I communicate with him in 3.3V. But on the datasheet they say Vih = 2.2V. So I thought it was compatible 3.3V (for communication). My problem will not come from there?
P.S.: I tested the screen on a PIC in 5V (with a library that already exists) and everything works!
-> My display: www.newhavendisplay.com/.../NHD-0420H1Z-FSW-GBW.pdf
I use a 5V LCD and I communicate with him in 3.3V. But on the datasheet they say Vih = 2.2V. So I thought it was compatible 3.3V (for communication). My problem will not come from there? that is correct, "TTL compatible" is "3V3 compatible" I have no idea how long the os_dly_wait is, have you verified with the LCD datasheet? are the port pins driving the LCD configured as push-pull? since the amsk bits are beyond 16, did you remember the 'L' on the mash definition or both places will fail
for the timing normaly it's good. I have verified with an oscilloscope. I/O in push-pull? I suppose but i don't really know. But i have read the databus with an logic anliser and I have, normaly, the good level!
But tomorow I will place an Pull-up resistor on the LCD to pull the level on 5V. just to adapt the pin level.
But you think the LCD would work with 3.3V?
The LCD, if specified with Vih(min) at 2V7, will work just fine with a 3V3 port, however still must be powered by 5V.
You MUST configure the outputs as push-pull or you will have severe risetime problems (check with a scope). I have, forgot the brand, had problems with a LCD that was extremely "risetime sensitive".
When you configure as push-pull DO NOT install the resistors.
If you install the resistors and it start working all you have done is proving that your pins are not configured as push-pull
I/O in push-pull? I suppose but i don't really know
STOP, dig out the datsheet (or the NXP base software description) and find out about port configuration.
You can damage the uC and/or the LCD with misconfigured ports.
the black line disappears
that means the hardware connection is good, just that the lcd isn't properly initiated. so I would look into how your code initiates the lcd - make sure that the timing / commands are sent per the lcd datasheet.
that does not send a byte to the port.
you can use an io mask for that. or you can do it like this:
LPC_GPIO0->FIOPIN = (LPC_GPIO0->FIOPIN & ~(0xff<<15)) | (data << 15);
or
LPC_GPIO0->FIOPIN &= ~(0xff) << 15; //clear the bits LPC_GPIO0->FIOPIN |= (data) << 15; //set the bits
you can write a macro to make it easier to manage.
Yes now I understand my problem! I use this CPU for a short time. But with your help, I found the solution. Now my LCD works: D
thank you