Author Topic: LCD module, 4-bit interface hi/lo lo/hi nibble quirk?  (Read 2571 times)

0 Members and 1 Guest are viewing this topic.

Offline SasjaTopic starter

  • Contributor
  • Posts: 49
  • Country: 00
LCD module, 4-bit interface hi/lo lo/hi nibble quirk?
« on: October 16, 2013, 08:32:21 am »
Hi everyone,
i'm doing some routines for interfacing with this 16x2 LCD character display from newhaven display (datasheet attached, controller chip datasheet also attached) in 4-bit mode and i found something weird. It seems that all datatransfer is hi-nibble first EXCEPT when doing the "read busy-flag/address counter (BFAC)"  instruction, then it is lo nibble first followed by hi nibble. I found out because the the read busy-thing didnt work at all and my lcd-routine stopped working after writing exactly 8 characters to the screen (so the BF/AC byte would become 0b0000/1000 therfore when nibble-swapped the first (busy flag)bit would seem 1 forever. I checked it and when i swapped it in the code everything suddenly worked fine! I also double checked by printing out the read BFAC-byte on the display. Now, i couldnt find anything about this behaviour on the datasheet or anywhere else, the LCD controller chip actually even suggests the nibble order for this command is in the right order like all other transfers.

Does anyone have any experience with these kind of things and should i be :o surprised/ >:( mad at this lcd-producer/ >:( mad at the controllerchip producer/just cautious in the future/ :-\ paranoid/...? Any advice would be nice!

I'll attach some code below, its two functions, one for a DataRead instruction, and one for a BFACRead instruction to the LCDmodule, they are almost identical EXCEPT i had to swap lo and hi at the end (and do a bit of cursing) to make it work for the BFACRead...
Code: [Select]
uint8_t lcd_readBFAC(){
    uint8_t hi,lo;
    TRIS_lcdData |= 0x0F;
    LAT_lcdRS = 0;
    LAT_lcdRW = 1;
    __delay_us(1);
    LAT_lcdE = 1;
    __delay_us(1);
    hi = PORT_lcdData & 0x0F;
    LAT_lcdE = 0;
    __delay_us(1);
    LAT_lcdE = 1;
    __delay_us(1);
    lo = PORT_lcdData & 0x0F;
    LAT_lcdE = 0;
    LAT_lcdData &= 0xF0;
    TRIS_lcdData &= 0xF0;
    //return ((uint8_t)(hi<<4)|lo);
    return((uint8_t)(lo<<4)|hi);                     //WTF!!!! its backwards!!!!
}

uint8_t lcd_readData(){
    uint8_t hi,lo;
    TRIS_lcdData |= 0x0F;
    LAT_lcdRS = 1;
    LAT_lcdRW = 1;
    __delay_us(1);
    LAT_lcdE = 1;
    __delay_us(1);
    hi = PORT_lcdData & 0x0F;
    LAT_lcdE = 0;
    __delay_us(1);
    LAT_lcdE = 1;
    __delay_us(1);
    lo = PORT_lcdData & 0x0F;
    LAT_lcdE = 0;
    LAT_lcdData &= 0xF0;
    TRIS_lcdData &= 0xF0;
    return ((uint8_t)(hi<<4)|lo);
}
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8401
Re: LCD module, 4-bit interface hi/lo lo/hi nibble quirk?
« Reply #1 on: October 16, 2013, 11:14:59 am »
Does it work as expected in 8-bit mode (or do you not have enough I/O for that)?

Maybe you could try asking Novatek... I'd be very interested if they did give a response. It could also be a timing problem - the datasheet gives slower timings for 4-bit vs 8-bit mode.

And apparently you're NOT the only one with this issue: http://www.ccsinfo.com/forum/viewtopic.php?t=29768&postdays=0&postorder=asc&start=30

Edit: your datasheet is outdated (v0.4 - preliminary!); diagram in this new datasheet (page 23) clearly shows DB7 reading AC3 first, then the busy flag. And from the revision history:
Quote
2.2
Modify 4-bits Interface check busy sequence (page 23)
(Document mistake corrected)
 

Offline SasjaTopic starter

  • Contributor
  • Posts: 49
  • Country: 00
Re: LCD module, 4-bit interface hi/lo lo/hi nibble quirk?
« Reply #2 on: October 16, 2013, 02:25:25 pm »
thanks amyk for pointing that out!
i kind of assumed that newhaven display would host the latest datasheet on their webpage.
I guess i should let them know it is outdated.
and i promise to check for the latest datasheet first next time i ask for help here! ^-^
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf