Hi everyone, first post so first of all i've got to say that i really enjoyed this forum since i know it and i learned a lot here. Thanks to everyone that has been contributing to this!
Today i've almost wasted a whole day trying to get a lcd-module working and i'm out of ideas so here i am. I've read that datasheets for lcd-module tend to be a bit crappy and this one seems no exception (attachment). I'm using a PIC16F1788 and i'm pretty sure i got the code right as everything works fine with another LCD module. Actually there are two things that confuse me most at the moment,
A) with my other module, when i lower Vo (contrast) down to GND the whole display goes black, but with the problematic one, changing Vo to anything between Vdd (5V) and Vss doenst do anything on the display. Does this mean the module is dead or is that behaviour just different for each module?
B) there is some example code for initializing the module in 8-bit mode, but not in 4-bit mode in the datasheet. And i need the 4-bit mode as i cant spare any more pins. As there is no example code for 4-bit initialization in the datasheet i looked up the datasheet of the lcd-controller used in the module (attachment) but this confused me even more. There is a nice flowchart in that datasheet for 4-bit mode initialization (page 25) but some bits just seem wrong and contradictory to the instruction set table (page 15). (the "display ON/OFF" as well as the "Entry Mode Set" instruction seems wrong as there is no leading 1 before D C B and I/D S bits)
Of course i tried what is written is the datasheet, as well as what i think it should be, with no success. I also tried writing to the LCD memory and reading it back to check if it was maybe just a contrast-problem and maybe the controller was working fine but it didn't work. Then i did the same thing on the other LCD module to see if my code was allright and it was! ugh! I checked the pin connections again and again, checked for shorts, measured the voltages at the module pins... what can i do more?
anyone has an idea? or should i ditch these modules and go for other ones? did i do something
stuuupiiiidd? (i have a nasty feeling i did) Anyway i'll add some pictures and some code in a minute as you'll ask for it anyway, and rightly so...
heres some relevant code used to initialize the thing, i used a lot of #defines, should make it readable
void lcd_sendInstr(uint8_t instr){
uint8_t hi = instr>>4;
uint8_t lo = instr & 0x0F;
LAT_lcdRS = 0;
LAT_lcdRW = 0;
LAT_lcdData &= 0xF0;
LAT_lcdData |= hi;
LAT_lcdE = 1;
__delay_us(1);
LAT_lcdE = 0;
NOP();
LAT_lcdData &= 0xF0;
LAT_lcdData |= lo;
LAT_lcdE = 1;
__delay_us(1);
LAT_lcdE = 0;
NOP();
}
void lcd_sendData(uint8_t data){
uint8_t hi = data>>4;
uint8_t lo = data & 0x0F;
LAT_lcdRS = 1;
LAT_lcdRW = 0;
LAT_lcdData &= 0xF0;
LAT_lcdData |= hi;
LAT_lcdE = 1;
__delay_us(1);
LAT_lcdE = 0;
NOP();
LAT_lcdData &= 0xF0;
LAT_lcdData |= lo;
LAT_lcdE = 1;
__delay_us(1);
LAT_lcdE = 0;
NOP();
}
void lcd_init(void){
__delay_ms(100);
LAT_lcdRS = 0;
LAT_lcdRW = 0;
LAT_lcdData &= 0xF0;
LAT_lcdData |= 0b0011;
LAT_lcdE = 1;
__delay_us(1);
LAT_lcdE = 0;
__delay_ms(100);
LAT_lcdE = 1;
__delay_us(1);
LAT_lcdE = 0;
__delay_ms(10);
LAT_lcdE = 1;
__delay_us(1);
LAT_lcdE = 0;
__delay_ms(10);
LAT_lcdData &= 0xF0;
LAT_lcdData |= 0b0010;
LAT_lcdE = 1;
__delay_us(1);
LAT_lcdE = 0;
__delay_ms(10);
lcd_sendInstr(0b00101000);
__delay_ms(1);
lcd_sendInstr(0b00001111);
__delay_ms(1);
lcd_sendInstr(0b00000001);
__delay_ms(5);
lcd_sendInstr(0b00000110);
__delay_ms(1);
}