Society of Robots - Robot Forum
Software => Software => Topic started by: GWER57 on March 03, 2010, 07:53:26 AM
-
Hi, i wrote a function to initialize an lcd. But in vmlab it doesn't seem to be working?
I just want to know if this code seems right to you or if i messed up somewhere.
//Function headers / macros
#define set(port, bit) port |= (1<<bit)
#define clear(port, bit) port &= ~(1<<bit)
#define pulse_ms(port, bit, length) (set(port,bit), _delay_ms(length), clear(port,bit))
//Defenitions
#define LCDdatap PORTA
#define LCDdatadr DDRA
#define LCDctrlp PORTG
#define LCDctrldr DDRG
#define LCDen 2
#define LCDrs 0
#define LCDrw 1
void LCDinit()
{
//Set data direction registers
LCDdatadr = 0xFF;
LCDctrldr |= 0x07;
//Initialization
clear(LCDctrlp, LCDen);
clear(LCDctrlp, LCDrs);
clear(LCDctrlp, LCDrw);
_delay_ms(20);
for(int a = 0; a < 3; a++)
{
LCDchar(0x30);
_delay_ms(20);
}
LCDchar(0x30);
_delay_ms(20);
LCDchar(0x08);
_delay_ms(20);
LCDchar(0x01);
_delay_ms(20);
LCDchar(0x06);
_delay_ms(20);
}
void LCDclear()
{
LCDchar(0x01);
_delay_ms(5);
}
void LCDhome()
{
LCDchar(0x10);
_delay_ms(5);
}
void LCDchar(char c)
{
LCDdatap = c;
pulse_ms(LCDctrlp, LCDen, 5);
}
Thanks so much in advance for taking a look ;D.
-
Hi,
Do you use 4 or 8 bits to drive your LCD ?
could you send the .prj from VMLAB ?
-
Hi,
Do you use 4 or 8 bits to drive your LCD ?
could you send the .prj from VMLAB ?
for(int a = 0; a < 3; a++)
{
LCDchar(0x30);
_delay_ms(20);
}
Looks like 8 is expected.
This is an init sequence, but you don't try to display any data. Flip LCDrs and write out some text.
I use 0x33 0x33 0x38 0x0C 0x01 as an init sequence for a common display that I use - HD-44780 compatible.
Some other displays have different sequences.
-
This is an init sequence, but you don't try to display any data. Flip LCDrs and write out some text.
So to write text to the lcd rs has to be high? That might be why it is not working because rs has been low when ive tried to write text to the lcd.
-
Yes. With the LCD RS pin low the things that you write are commands. With it high then the things that you write are characters.
-
You might want something like this:
void LCDcommand(char c)
{
// Talk to the control register
clear(LCDctrlp, LCDrs);
LCDdatap = c;
pulse_ms(LCDctrlp, LCDen, 5);
}
void LCDchar(char c)
{
// Send character to display
set(LCDctrlp, LCDrs);
LCDdatap = c;
pulse_ms(LCDctrlp, LCDen, 5);
}
Change your init stuff to use LCDcommand, then write to the display using LCDchar.
-
The initialization sequence you use, will it work for a 2x16 8-bit controlled lcd? more specifically, the one from futurlec (HD-44780 compatable).
Thanks for your help!
-
0x33 - 8 bit interface
0x33 - 8 bit interface again to be sure
0x38 - 8 bit interface, 2 lines
0x0C - Display on, blink off, cursor off
0x01 - Clear and set to 'home'
That should work OK.
-
Thank you so much! It finally works! I can't wait to get this going on the real deal.
-
Thank you so much! It finally works! I can't wait to get this going on the real deal.
I'm glad that worked for you!
I remember the elation when I first got a character LCD to work. Sometime back in the 80s. I had very sketchy documentation and had to resort to using DIP switches on a solderless board and clocking in everything by hand.
LCDs are cool once they work. But since so many look like they are doing NOTHING if you don't get the initialization right, it can be frustrating.