| Author |
Message |
|
|
Posted: Dec 26, 2006 - 06:52 PM |
|


Joined: May 30, 2004
Posts: 8118
Location: Cincinnati, Ohio
|
|
|
bobgardner wrote:
I thought you said you had a 16 x 2 display. That code is for a 4 line display. Which do you have?
He probably won't see the 2nd and 4th lines as, they will be hidden untill the display is scrolled left or right. |
_________________ Carl W. Livingston, KC5OTL
microcarl@roadrunner.com
"There are only two ways to sleep well at night... be ignorant or be prepared."
The original Dragon Slayer !
Long live the AVR!!!
|
| |
|
|
|
|
|
Posted: Dec 26, 2006 - 07:17 PM |
|

Joined: Apr 07, 2006
Posts: 407
Location: Braga, Portugal
|
|
No, your code does nothing in my circuit and lcd module.
I have a 16x2 display.
I have all the 8 pins of PORTD connected to lcd module.
The other includes are not necessary but i know that they arent doing nothing. They were just taken from my other project.
Cheers,
Nuno |
|
|
| |
|
|
|
|
|
Posted: Dec 27, 2006 - 10:19 AM |
|

Joined: Sep 16, 2006
Posts: 94
|
|
@Microcarl
What wiring you need for your code?
PORTb 1 - 3 to RS, RW and E?
PORTA 0 -> DB0
PORTA 1 -> DB1
..
PORTA 7 -> DB7
That is all(and the power supply offcourse)? |
|
|
| |
|
|
|
|
|
Posted: Dec 27, 2006 - 01:25 PM |
|


Joined: May 30, 2004
Posts: 8118
Location: Cincinnati, Ohio
|
|
|
naffets wrote:
@Microcarl
What wiring you need for your code?
PORTb 1 - 3 to RS, RW and E?
PORTA 0 -> DB0
PORTA 1 -> DB1
..
PORTA 7 -> DB7
That is all(and the power supply offcourse)?
Code:
PIN 1 = GND = 5 V COMON
PIN 2 = Vcc = +5 VDC
PIN 3 = Vee = CONTRAST POT SLIDER
PIN 4 = PORTB:0 = RS
PIN 5 = PORTB:1 = R/W
PIN 6 = PORTB:2 = E
PIN 7 = PORTA:0 = DB0
.
.
.
PIN 14 = PORTA:7 = DB7
This is what is currently working on my proto-board. |
_________________ Carl W. Livingston, KC5OTL
microcarl@roadrunner.com
"There are only two ways to sleep well at night... be ignorant or be prepared."
The original Dragon Slayer !
Long live the AVR!!!
|
| |
|
|
|
|
|
Posted: Dec 31, 2006 - 10:51 PM |
|

Joined: Apr 07, 2006
Posts: 407
Location: Braga, Portugal
|
|
Hi again,
I've been out of this since i have a lot of work by now.
Although, today i was trying again to put it working.
I've looked to several codes around.
But they all give me nothing.
I decided to give a new closer look to your code carl.
I needed to change some stuff as i only have 2 lines and my avr mega 88 doesnt have a port A
So i replaced all the PORTA and DDRA occurences by PORTD and DDRD.
I also replaced all the occurences of PORTB and DDRB to PORTC and DDRC.
About my LCD, it is not driven by hitachi. It is controlled by ks0066.
I choose the following addresses for the 2 lines:
#define LINE1 0x00
#define LINE2 0x40
Based on the "how to use inteligent LCD modules tutorial". I assume it's the same.
I have his datasheet:
http://www.datasheets.org.uk/datasheet. ... le=1914264
I'm trying to make the initialization using the information on page 26:
The first thing i dont understand its fosc condition: 270khz.
Do i need to have that frequency in my chip? (i assume not)
In your code carl, there is no delay between these initialization operations. Is this a problem?
I also had to change two commands you have:
// TURN ON POWER TO THE DISPLAY, NO CURSOR
#define PWR_CMD 0x3F // now corresponds to function set
// SET 2 LINE, 8 DATA BIT MODE
#define DL_CMD 0x0F // now correspondes to display on/off control
Well, i tried to gather all the information i remembered.
And thanks for all the support give until now.
Many thx and happy new year
Nuno |
|
|
| |
|
|
|
|
|
Posted: Dec 31, 2006 - 11:50 PM |
|


Joined: May 30, 2004
Posts: 8118
Location: Cincinnati, Ohio
|
|
|
sinosoidal wrote:
Hi again,
I decided to give a new closer look to your code carl.
Nuno
Let me refer you to this latest post.
http://www.avrfreaks.net/index.php?name ... p;start=80
I don't have a Mega88 so I couldn't test the code for that controller. I did test the code on a Mega168 and it worked fine so, the code should work for the Mega88 as, the Mega88 is the little brother to the Mega168.
I've been working on this for the past two days and have added quite a bit to it.
Let me know how it works out... |
_________________ Carl W. Livingston, KC5OTL
microcarl@roadrunner.com
"There are only two ways to sleep well at night... be ignorant or be prepared."
The original Dragon Slayer !
Long live the AVR!!!
|
| |
|
|
|
|
|
Posted: Jan 01, 2007 - 12:47 AM |
|


Joined: Mar 27, 2002
Posts: 18599
Location: Lund, Sweden
|
|
|
Quote:
The first thing i dont understand its fosc condition: 270khz.
Do i need to have that frequency in my chip? (i assume not)
No, your assumption is correct. What the data sheet is talking about is the frequency of the oscillator for the LCD controller (HD44780, KS0066, whatever...). Assume its 270 KHz and move on.
Bob wrote:
You say your mega48 is running at 1mhz, but the winavr example you posted shows 10mhz. That one little extra zero puts the timing off by a factor of 10. Your init problem seems to be timing related. Perhaps I have found your problem?
No, Bob. If the compiler generates delays based on a stated frequency of 10 MHz but the chip is actually running at 1 MHz then the delays will be 10 times longer than expected, not the other way around.
This is in fact a good thing. My first advice to avoid breaking timing constraints for a LCD module is to slow down the clock to "a ridicolously low value". The above manouvre will accomplish the same thing (although it might not have been intended).
Happy new year, everyone! |
|
|
| |
|
|
|
|
|
Posted: Jan 02, 2007 - 10:04 AM |
|

Joined: Apr 12, 2006
Posts: 50
Location: UK
|
|
|
sinosoidal wrote:
I choose the following addresses for the 2 lines:
#define LINE1 0x00
#define LINE2 0x40
Based on the "how to use inteligent LCD modules tutorial". I assume it's the same.
That's where you have gone wrong. According to the LCD datasheet, the MSB should be set for the LCD to accept the command as DDRAM address. This is done correctly by using #define LINE1 0x80 in Microcarl's code.
I have tried Microcarl's LCD code on Tiny2313 and it works just fine. |
|
|
| |
|
|
|
|
|
Posted: Jan 02, 2007 - 01:22 PM |
|


Joined: May 30, 2004
Posts: 8118
Location: Cincinnati, Ohio
|
|
|
eblc1388 wrote:
sinosoidal wrote:
I choose the following addresses for the 2 lines:
#define LINE1 0x00
#define LINE2 0x40
Based on the "how to use inteligent LCD modules tutorial". I assume it's the same.
That's where you have gone wrong. According to the LCD datasheet, the MSB should be set for the LCD to accept the command as DDRAM address. This is done correctly by using #define LINE1 0x80 in Microcarl's code.
I have tried Microcarl's LCD code on Tiny2313 and it works just fine.
Thank you very much!
I was beginning to think I was missing something very important.
Thank you for the confirmation that my program works correctly in another environment!!! |
_________________ Carl W. Livingston, KC5OTL
microcarl@roadrunner.com
"There are only two ways to sleep well at night... be ignorant or be prepared."
The original Dragon Slayer !
Long live the AVR!!!
|
| |
|
|
|
|
|
Posted: Jan 04, 2007 - 09:03 PM |
|

Joined: Apr 07, 2006
Posts: 407
Location: Braga, Portugal
|
|
Hi again folks,
I'm getting crazy with this LCD module.
It is harder to work with it than learn to work with a AVR.
I'm posting all the code i'm using right now.
Basicly it's carls code with some modifications because my hardware is atmega 88 and doesnt have PORTA. I also changed PORTB to PORTC.
In my hardware i use R/W always down to 0.
I also messed with the following defines:
// TURN ON POWER TO THE DISPLAY, NO CURSOR
#define PWR_CMD 0x3F
// SET 2 LINE, 8 DATA BIT MODE
#define DL_CMD 0x0F
// CLEAR DISPLAY COMMAND
#define CLR_DSP 0x01
Which based on what i understand from my datasheet they were not right... Well.. at this point i know nothing.... Grrr!!
Code:
#define F_CPU 80000000
// Data: PORTD
// Control: PORTC
// RS = PORTC, bit 0, 0x01
// RW = PORTC, bit 1, 0x02
// E = PORTC, bit 2, 0x04
#include <avr/io.h>
#include <util/delay.h>
// Define LCD Register Select as PORTC, 0x01;
#define LCD_RS 0
// Define LCD Read/Write as PORTC, 0x02;
#define LCD_RW 1
// Define LCD Enable as PORTC, 0x04;
#define LCD_E 2
// TURN ON POWER TO THE DISPLAY, NO CURSOR
#define PWR_CMD 0x3F
// SET 2 LINE, 8 DATA BIT MODE
#define DL_CMD 0x0F
// CLEAR DISPLAY COMMAND
#define CLR_DSP 0x01
#define LINE1 0x80
#define LINE2 0x80
#define NULL 0x00
const char BANNER_1[] = {"Having Fun"};
const char BANNER_2[] = {"With LCD's"};
void LCD_Delay (unsigned long int d);
void LCD_IO_INIT (void);
void LCD_INIT (void);
void LCD_PutCmd (char);
void LCD_PutChar (char);
void LCD_PutString (const char *);
void main (void) {
LCD_IO_INIT ();
LCD_INIT ();
while(1)
{
// Add other LCD related program operations here...
}
}
void LCD_Delay (unsigned long int d)
{
unsigned long int n;
for (n = 0; n < d; n++);
}
void LCD_IO_INIT (void)
{
DDRD = 0xFF; // PORTD is the LCD DATA LINES
PORTD = 0x00;
DDRC |= 0x07; // PORTC is the LCD CONTROL LINES
PORTC |= 0x05; // LCD_E = HIGH, LCD_RW = LOW, LCD_RS = HIGH
LCD_Delay (500); // Wait for the up LCD to power up
}
void LCD_INIT (void)
{
LCD_PutCmd (PWR_CMD); // Power up the display
LCD_PutCmd (DL_CMD); // Set to 2 lines, 8 bit, no cursor
LCD_PutCmd (CLR_DSP); // Clear the display
LCD_Delay (500); // Wait for the LCD to boot up
LCD_PutCmd (LINE1+5);
LCD_PutString (BANNER_1);
LCD_PutCmd (LINE2+5);
LCD_PutString (BANNER_2);
}
void LCD_PutCmd (char c)
{
PORTC &= ~(1<<LCD_RS);
LCD_Delay (5); // Wait for the proper setup time to respond to the RS control line
LCD_PutChar(c);
LCD_Delay (5); // Wait for the proper setup time to respond to the command being applied
PORTC |= (1<<LCD_RS);
}
void LCD_PutChar (char c)
{
PORTC |= (1<<LCD_E);
LCD_Delay (5); // Wait for the proper setup time to respond to the E pulse
PORTD = c;
LCD_Delay (5); // Wait for the proper setup time to respond to the character being applied
PORTC &= ~(1<<LCD_E);
}
void LCD_PutString (const char *p)
{
char n = NULL; // Pointer position counter.
while (p[n] != NULL) // Keep sending data until the NULL character is found.
LCD_PutChar(p[n++]);
}
I'm using again 8 Mhz.
This is a screenshot of the bread board just for you guys check that i'm making the right connections or even discover something that is wrong.
http://www.imaginando.net/goodies/shot.jpg
I hope this helps you guys finding me the problem i have! ....
Best regards,
Nuno |
|
|
| |
|
|
|
|
|
Posted: Jan 04, 2007 - 10:20 PM |
|


Joined: Sep 04, 2002
Posts: 21276
Location: Orlando Florida
|
|
| 80 Mhz is a real fast AVR |
|
|
| |
|
|
|
|
|
Posted: Jan 04, 2007 - 10:27 PM |
|

Joined: Apr 07, 2006
Posts: 407
Location: Braga, Portugal
|
|
|
bobgardner wrote:
80 Mhz is a real fast AVR
Yes, you were right. That was completly wrong, but i still dont have good news!
Thx
Nuno |
|
|
| |
|
|
|
|
|
Posted: Jan 04, 2007 - 10:38 PM |
|


Joined: Mar 27, 2002
Posts: 18599
Location: Lund, Sweden
|
|
| The first thing I'd like to rule out is that this is not a timing problem. So: At what clock speed is your mega88 actually running? |
|
|
| |
|
|
|
|
|
Posted: Jan 05, 2007 - 12:55 AM |
|


Joined: Sep 04, 2002
Posts: 21276
Location: Orlando Florida
|
|
| Your program has gcc style include paths. I thought you were using the imagecraft compiler? If you have both compilers installed, maybe your problem has something to do with trying to compile the gcc includes with imagecraft? There should be an #include <iom88v.h> up there for imagecraft, and no avr/io and no util/delay etc. |
|
|
| |
|
|
|
|
|
Posted: Jan 05, 2007 - 01:42 AM |
|

Joined: Apr 07, 2006
Posts: 407
Location: Braga, Portugal
|
|
|
bobgardner wrote:
Your program has gcc style include paths. I thought you were using the imagecraft compiler? If you have both compilers installed, maybe your problem has something to do with trying to compile the gcc includes with imagecraft? There should be an #include <iom88v.h> up there for imagecraft, and no avr/io and no util/delay etc.
No. I'm actually using WinAVR, only! |
|
|
| |
|
|
|
|
|
Posted: Jan 05, 2007 - 01:45 AM |
|


Joined: May 30, 2004
Posts: 8118
Location: Cincinnati, Ohio
|
|
|
sinosoidal wrote:
Basicly it's carls code with some modifications because my hardware is atmega 88 and doesnt have PORTA. I also changed PORTB to PORTC.
In my hardware i use R/W always down to 0.
I also messed with the following defines:
Code:
// TURN ON POWER TO THE DISPLAY, NO CURSOR
#define PWR_CMD 0x3F
// SET 2 LINE, 8 DATA BIT MODE
#define DL_CMD 0x0F
// CLEAR DISPLAY COMMAND
#define CLR_DSP 0x01
Which based on what i understand from my datasheet they were not right... Well.. at this point i know nothing.... Grrr!!Nuno
Well, the code that I posted has been verified as to be working code by two independant sources.
Either:
1. You are doing something wrong in the translation from one compiler to another.
2. You have a wiring error.
3. You have a deffective display.
I guess, like Bob, I am confused about exactly which compiler you are using.
Also, I think you need to re-visit the PWR_CMD, DL_CMD & CLR_DSP assignments as, I have been using these assignments for years and have never had the problems you are having, getting a text based LCD to work.
Also, I think a lengthy read of the datasheet of the LCD and a good understanding of the timing required, and a good understanding of the initialization process, will shed some light on some possable issues.
Over a three or four day span, I have re-written my original code at least three times, using different timing, initialization and bit lengths. All of the different code versions worked with several LCDs by several manufacturers. I have about 50 to 60 hours testing the compatability between these different LCD manufacturers. The only display that has given any issues at all was the Hyundi, which seemed slightly more sensitive to critically tight timing settings. But it still worked and only mis-placed a character occasionally.
What I can say, is that this whole thing has caused me to look at getting seriuos about a project that I have been wanting to do for a long, long time. |
_________________ Carl W. Livingston, KC5OTL
microcarl@roadrunner.com
"There are only two ways to sleep well at night... be ignorant or be prepared."
The original Dragon Slayer !
Long live the AVR!!!
|
| |
|
|
|
|
|
Posted: Jan 05, 2007 - 02:11 AM |
|

Joined: Apr 07, 2006
Posts: 407
Location: Braga, Portugal
|
|
|
microcarl wrote:
sinosoidal wrote:
Basicly it's carls code with some modifications because my hardware is atmega 88 and doesnt have PORTA. I also changed PORTB to PORTC.
In my hardware i use R/W always down to 0.
I also messed with the following defines:
Code:
// TURN ON POWER TO THE DISPLAY, NO CURSOR
#define PWR_CMD 0x3F
// SET 2 LINE, 8 DATA BIT MODE
#define DL_CMD 0x0F
// CLEAR DISPLAY COMMAND
#define CLR_DSP 0x01
Which based on what i understand from my datasheet they were not right... Well.. at this point i know nothing.... Grrr!!Nuno
Well, the code that I posted has been verified as to be working code by two independant sources.
Either:
1. You are doing something wrong in the translation from one compiler to another.
2. You have a wiring error.
3. You have a deffective display.
I guess, like Bob, I am confused about exactly which compiler you are using.
Also, I think you need to re-visit the PWR_CMD, DL_CMD & CLR_DSP assignments as, I have been using these assignments for years and have never had the problems you are having, getting a text based LCD to work.
Also, I think a lengthy read of the datasheet of the LCD and a good understanding of the timing required, and a good understanding of the initialization process, will shed some light on some possable issues.
Over a three or four day span, I have re-written my original code at least three times, using different timing, initialization and bit lengths. All of the different code versions worked with several LCDs by several manufacturers. I have about 50 to 60 hours testing the compatability between these different LCD manufacturers. The only display that has given any issues at all was the Hyundi, which seemed slightly more sensitive to critically tight timing settings. But it still worked and only mis-placed a character occasionally.
What I can say, is that this whole thing has caused me to look at getting seriuos about a project that I have been wanting to do for a long, long time.
And i belive your code!
Something must be wrong...
I guess i will take everything how and do the wiring again. Just from the scratch.
I'll give some feedback later
Cheers,
Nuno |
|
|
| |
|
|
|
|
|
Posted: Jan 05, 2007 - 03:00 AM |
|


Joined: May 30, 2004
Posts: 8118
Location: Cincinnati, Ohio
|
|
|
sinosoidal wrote:
Basicly it's carls code with some modifications because my hardware is atmega 88 and doesnt have PORTA. I also changed PORTB to PORTC.
In my hardware i use R/W always down to 0.
I also messed with the following defines:
Code:
// TURN ON POWER TO THE DISPLAY, NO CURSOR
#define PWR_CMD 0x3F
// SET 2 LINE, 8 DATA BIT MODE
#define DL_CMD 0x0F
// CLEAR DISPLAY COMMAND
#define CLR_DSP 0x01
Which based on what i understand from my datasheet they were not right... Well.. at this point i know nothing.... Grrr!!Nuno
DL_CMD should be set according to the number of lines on the display but, PWR_CMD is incorrect.
Code:
// TURN ON POWER TO THE DISPLAY, NO CURSOR
#define PWR_CMD 0x0C
// SET 8 DATA BIT MODE
#define DL_CMD 0x30
// CLEAR DISPLAY COMMAND
#define CLR_DSP 0x01
sinosoidal wrote:
Code:
#define F_CPU 80000000
Shouldn't this be:
Code:
#define F_CPU 8000000
sinosoidal wrote:
Code:
#define LINE1 0x80
#define LINE2 0x80
Line 2 starting address is incorrect.
Code:
#define LINE1 0x80
#define LINE2 0xC0
Code:
void LCD_PutCmd (char c)
{
PORTC &= ~(1<<LCD_RS);
LCD_Delay (5); // Wait for the proper setup time to respond to the RS control line
LCD_PutChar(c);
LCD_Delay (5); // Wait for the proper setup time to respond to the command being applied
PORTC |= (1<<LCD_RS);
}
Try the following, as an experiment
Code:
void LCD_PutCmd (char c)
{
PORTC &= ~(1<<LCD_RS);
LCD_Delay (200); // Wait for the proper setup time to respond to the RS control line
LCD_PutChar(c);
LCD_Delay (200); // Wait for the proper setup time to respond to the command being applied
PORTC |= (1<<LCD_RS);
LCD_Delay (200);
}
Also try the following...
Code:
void LCD_PutChar (char c)
{
PORTC |= (1<<LCD_E);
LCD_Delay (5); // Wait for the proper setup time to respond to the E pulse
PORTD = c;
LCD_Delay (5); // Wait for the proper setup time to respond to the character being applied
PORTC &= ~(1<<LCD_E);
LCD_Delay (5); // Wait for the proper setup time
}
|
_________________ Carl W. Livingston, KC5OTL
microcarl@roadrunner.com
"There are only two ways to sleep well at night... be ignorant or be prepared."
The original Dragon Slayer !
Long live the AVR!!!
|
| |
|
|
|
|
|
Posted: Jan 05, 2007 - 10:01 AM |
|

Joined: Apr 07, 2006
Posts: 407
Location: Braga, Portugal
|
|
Nope... It didnt work!
I still have to unwire everything and make it again.
Explain me just one thing.
In my datasheet (ks0066 datasheet), in the initialization part (page 26) i have the following sequence:
1 - Power On
2 - Wait for more than 30 ms after rises to 4.5. (i'm using 5 volts directly on this pin, since 4.5 doesnt even light up the display)
3 - Function set (which define 1 ou 2 line mode and sets display on) is like this
000011NFXX where N can be 0 for 1 line mode and 1 for 2 line mode. And F=0 makes display off and 1 display one.
This is related with your PWR_CMD?
Thx,
Nuno |
|
|
| |
|
|
|
|
|
Posted: Jan 05, 2007 - 02:55 PM |
|


Joined: Sep 04, 2002
Posts: 21276
Location: Orlando Florida
|
|
| 000011NFXX has 10 bit positions. You have 2 extra 00s in the front by accident? |
|
|
| |
|
|
|
|
|