Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

8 bits LCD Problem

Status
Not open for further replies.

joe_1

Member
Hi:

I am trying to print few words on an 8 bits 2x16 LCD with Hitachi controller,
but I am not able to print anything, I just see a thin line blinking few times. I am using PIC18, but the pic choice does not matter since this is my first LCD code, and I think it must be code problem, and I would guess it must be in the init method, because I am not very sure about it.
Here is the code:

#define LCD_EN 1 // Port A bit 0 ( Enables LCD )
#define LCD_WR 2 // Port A bit 1 ( Logic 0 = Write )
#define LCD_RS 4 // Port A bit 2 ( Register select 1=Data transfer)
// PortD is D0-D7

void lcd_clear(void)
{
setInstructionBit_Lo(LCD_RS);
PORTA &= 0xf0;
//PORTD = 0x01;
lcd_write(0x01);
delay(4000);
setInstructionBit_Hi(LCD_RS);
}

void LCD_Toggle_EN(void)
{
setInstructionBit_Hi(LCD_EN);
delay(4000);
setInstructionBit_Lo(LCD_EN);
delay(4000);
}

void LCD_init(void)
{
delay (8000); //30ms Power ON delay
setInstructionBit_Lo(LCD_RS);

lcd_write(0x0c); // // Display is ON
lcd_write(0x0e); // cursor active and no blink
//lcd_write(0x0f); // cursor active and blink


LCD_Toggle_EN();
lcd_write(1); // clear display

LCD_Toggle_EN();
lcd_write(0x38); // 8 bit data mode 2 line ( 5x7 font )

LCD_Toggle_EN();

setInstructionBit_Hi(LCD_RS);
}

void main (void)
{


TRISD = 0;
TRISA = 0;

PORTA = 0x00;
PORTD = 0x00;

LCD_init();


while (1)
{
lcd_clear();
lcd_write('T');
lcd_write('e');
lcd_write('s');
lcd_write('t');
lcd_write('!');
}
}

PS: This LCD has 16 pins, and supposedly has a LED backlight, I am not sure how to turn this LED ON, I tried to connect pin15 to GND, and pin16 to +5V, but it did not work.

If you could help, please do.
Thanks a lot folks.
 
hi joe,
I expect you have got a copy of the HD44780 datasheet.

From power ON, wait for at least 40mSec before you start to initialise.
Write 0x38, the BUSY cannot be tested yet.
Wait 5mSec
Write 0x38 again, still no BUSY test.
Wait 100uSec
Write 0x38 again

Write the Init instruction set, after each Instr you can now test the BUSY bit[D7]

Whats you PIC clock rate, the controller 'Enb' strobe must be at least 1uSec duration, you may need to pad out the Control line signals with NOP's.
 
Hey Joe,

Check this one: https://www.electro-tech-online.com/threads/89c4051-4-bit-controlled-lcd-sporadic-screwup.29350/

If you wait long enough, more than the datasheet recommend, it should be ok. For me it is anyway. I always send the commands only once with no problem at all :)


Regarding the backlight, you sure it's LED and not EL foil (require driver), you know very thin foil that fits between LCD and PCB.
I have here several LCD's from different suppliers Hitachi, Hyundai, Sharp, Optrex some with LED some with EL BL, 14 pins and 16 pins, all are different. The Hyundai ones are marked A and K for the backlight so no confusion possible.
Google brand and type for datasheet or post a good picture of yours here, then, maybe we can help you further...
 
Thanks guys for the hints, it is working now.
I was not sending the 0x38 three times and I did not have long enough delay.

As for the back light LED, I had it connected backward and it is also working now.
I actually was using spec for different LCD. Apparently it is not standard.

Thanks again.
 
Status
Not open for further replies.

Latest threads

Back
Top