problem lcd for atmega128rfa1

Go To Last Post
18 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi i want to connect character lcd to my atmega128rfa1 board in wsndemo...
i use this file for HD44780.c:

//-------------------------------------------------------------------------------------------------
// Wyœwietlacz alfanumeryczny ze sterownikiem HD44780
// Sterowanie w trybie 4-bitowym bez odczytu flagi zajêtoœci
// z dowolnym przypisaniem sygna³ów steruj¹cych
// Plik : HD44780.c	
// Mikrokontroler : Atmel AVR
// Kompilator : avr-gcc
// Autor : Rados³aw Kwiecieñ
// ród³o : http://radzio.dxp.pl/hd44780/
// Data : 24.03.2007
//-------------------------------------------------------------------------------------------------

#include "HD44780.h"
//-------------------------------------------------------------------------------------------------
//
// Funkcja wystawiaj¹ca pó³bajt na magistralê danych
//
//-------------------------------------------------------------------------------------------------
void _LCD_OutNibble(unsigned char nibbleToWrite)
{

if(nibbleToWrite & 0x01)
	LCD_DB4_PORT |= LCD_DB4;
else
	LCD_DB4_PORT  &= ~LCD_DB4;

if(nibbleToWrite & 0x02)
	LCD_DB5_PORT |= LCD_DB5;
else
	LCD_DB5_PORT  &= ~LCD_DB5;

if(nibbleToWrite & 0x04)
	LCD_DB6_PORT |= LCD_DB6;
else
	LCD_DB6_PORT  &= ~LCD_DB6;

if(nibbleToWrite & 0x08)
	LCD_DB7_PORT |= LCD_DB7;
else
	LCD_DB7_PORT  &= ~LCD_DB7;
}
//-------------------------------------------------------------------------------------------------
//
// Funkcja wystawiaj¹ca pó³bajt na magistralê danych
//
//-------------------------------------------------------------------------------------------------
unsigned char _LCD_InNibble(void)
{
unsigned char tmp = 0;

if(LCD_DB4_PIN & LCD_DB4)
	tmp |= (1 << 0);
if(LCD_DB5_PIN & LCD_DB5)
	tmp |= (1 << 1);
if(LCD_DB6_PIN & LCD_DB6)
	tmp |= (1 << 2);
if(LCD_DB7_PIN & LCD_DB7)
	tmp |= (1 << 3);
return tmp;
}
//-------------------------------------------------------------------------------------------------
//
// Funkcja zapisu bajtu do wyœwietacza (bez rozró¿nienia instrukcja/dane).
//
//-------------------------------------------------------------------------------------------------
void _LCD_Write(unsigned char dataToWrite)
{
LCD_DB4_DIR |= LCD_DB4;
LCD_DB5_DIR |= LCD_DB5;
LCD_DB6_DIR |= LCD_DB6;
LCD_DB7_DIR |= LCD_DB7;

LCD_RW_PORT &= ~LCD_RW;
LCD_E_PORT |= LCD_E;
_LCD_OutNibble(dataToWrite >> 4);
LCD_E_PORT &= ~LCD_E;
LCD_E_PORT |= LCD_E;
_LCD_OutNibble(dataToWrite);
LCD_E_PORT &= ~LCD_E;
while(LCD_ReadStatus()&0x80);
}
//-------------------------------------------------------------------------------------------------
//
// Funkcja odczytu bajtu z wyœwietacza (bez rozró¿nienia instrukcja/dane).
//
//-------------------------------------------------------------------------------------------------

unsigned char _LCD_Read(void)
{
unsigned char tmp = 0;
LCD_DB4_DIR &= ~LCD_DB4;
LCD_DB5_DIR &= ~LCD_DB5;
LCD_DB6_DIR &= ~LCD_DB6;
LCD_DB7_DIR &= ~LCD_DB7;

LCD_RW_PORT |= LCD_RW;
LCD_E_PORT |= LCD_E;
tmp |= (_LCD_InNibble() << 4);
LCD_E_PORT &= ~LCD_E;
LCD_E_PORT |= LCD_E;
tmp |= _LCD_InNibble();
LCD_E_PORT &= ~LCD_E;
return tmp;
}

//-------------------------------------------------------------------------------------------------
//
// Funkcja zapisu rozkazu do wyœwietlacza
//
//-------------------------------------------------------------------------------------------------
void LCD_WriteCommand(unsigned char commandToWrite)
{
LCD_RS_PORT &= ~LCD_RS;
_LCD_Write(commandToWrite);
}

//-------------------------------------------------------------------------------------------------
//
// Funkcja odczytu bajtu statusowego
//
//-------------------------------------------------------------------------------------------------
unsigned char LCD_ReadStatus(void)
{
LCD_RS_PORT &= ~LCD_RS;
return _LCD_Read();
}
//-------------------------------------------------------------------------------------------------
//
// Funkcja zapisu danych do pamiêci wyœwietlacza
//
//-------------------------------------------------------------------------------------------------
void LCD_WriteData(unsigned char dataToWrite)
{
LCD_RS_PORT |= LCD_RS;
_LCD_Write(dataToWrite);
}
//-------------------------------------------------------------------------------------------------
//
// Funkcja odczytu danych z pamiêci wyœwietlacza
//
//-------------------------------------------------------------------------------------------------
unsigned char LCD_ReadData(void)
{
LCD_RS_PORT |= LCD_RS;
return _LCD_Read();
}
//-------------------------------------------------------------------------------------------------
//
// Funkcja wyœwietlenia napisu na wyswietlaczu.
//
//-------------------------------------------------------------------------------------------------
void LCD_WriteText(char * text)
{
while(*text)
  LCD_WriteData(*text++);
}
//-------------------------------------------------------------------------------------------------
//
// Funkcja ustawienia wspó³rzêdnych ekranowych
//
//-------------------------------------------------------------------------------------------------
void LCD_GoTo(unsigned char x, unsigned char y)
{
LCD_WriteCommand(HD44780_DDRAM_SET | (x + (0x40 * y)));
}
//-------------------------------------------------------------------------------------------------
//
// Funkcja czyszczenia ekranu wyœwietlacza.
//
//-------------------------------------------------------------------------------------------------
void LCD_Clear(void)
{
LCD_WriteCommand(HD44780_CLEAR);
_delay_ms(2);
}
//-------------------------------------------------------------------------------------------------
//
// Funkcja przywrócenia pocz¹tkowych wspó³rzêdnych wyœwietlacza.
//
//-------------------------------------------------------------------------------------------------
void LCD_Home(void)
{
LCD_WriteCommand(HD44780_HOME);
_delay_ms(2);
}
//-------------------------------------------------------------------------------------------------
//
// Procedura inicjalizacji kontrolera HD44780.
//
//-------------------------------------------------------------------------------------------------
void LCD_Initalize(void)
{
unsigned char i;
LCD_DB4_DIR |= LCD_DB4; // Konfiguracja kierunku pracy wyprowadzeñ
LCD_DB5_DIR |= LCD_DB5; //
LCD_DB6_DIR |= LCD_DB6; //
LCD_DB7_DIR |= LCD_DB7; //
LCD_E_DIR 	|= LCD_E;   //
LCD_RS_DIR 	|= LCD_RS;  //
LCD_RW_DIR 	|= LCD_RW;  //
_delay_ms(15); // oczekiwanie na ustalibizowanie siê napiecia zasilajacego
LCD_RS_PORT &= ~LCD_RS; // wyzerowanie linii RS
LCD_E_PORT &= ~LCD_E;  // wyzerowanie linii E
LCD_RW_PORT &= ~LCD_RW;
for(i = 0; i < 3; i++) // trzykrotne powtórzenie bloku instrukcji
  {
  LCD_E_PORT |= LCD_E; //  E = 1
  _LCD_OutNibble(0x03); // tryb 8-bitowy
  LCD_E_PORT &= ~LCD_E; // E = 0
  _delay_ms(5); // czekaj 5ms
  }

LCD_E_PORT |= LCD_E; // E = 1
_LCD_OutNibble(0x02); // tryb 4-bitowy
LCD_E_PORT &= ~LCD_E; // E = 0

_delay_ms(1); // czekaj 1ms 
LCD_WriteCommand(HD44780_FUNCTION_SET | HD44780_FONT5x7 | HD44780_TWO_LINE | HD44780_4_BIT); // interfejs 4-bity, 2-linie, znak 5x7
LCD_WriteCommand(HD44780_DISPLAY_ONOFF | HD44780_DISPLAY_OFF); // wy³¹czenie wyswietlacza
LCD_WriteCommand(HD44780_CLEAR); // czyszczenie zawartosæi pamieci DDRAM
LCD_WriteCommand(HD44780_ENTRY_MODE | HD44780_EM_SHIFT_CURSOR | HD44780_EM_INCREMENT);// inkrementaja adresu i przesuwanie kursora
LCD_WriteCommand(HD44780_DISPLAY_ONOFF | HD44780_DISPLAY_ON | HD44780_CURSOR_OFF | HD44780_CURSOR_NOBLINK); // w³¹cz LCD, bez kursora i mrugania
}

// funkcja s³u¿¹ca do wpisywania w³asnych znaków
// nr - zmienna okreœlaj¹ca numer znaku (dostêpnych jest 8)  od 0 - 7. 
// znak[] - okreœla kszta³t znaku.. przyk³adowo uint8_t serduszko[] = {4, 10, 17, 23, 23, 17, 31, 0}; definiuje wygl¹d serca. 
void LCD_ProgrammChar(unsigned char nr, unsigned char znak[]) 
{	
	unsigned char i;
	LCD_WriteCommand(HD44780_CGRAM_SET|(nr*8));
	for (i=0; i<=7; i++)
	{
		LCD_WriteData(znak[i]);
	}
	LCD_WriteCommand(HD44780_DDRAM_SET);
}

//-------------------------------------------------------------------------------------------------
//
// Koniec pliku HD44780.c
//
//-------------------------------------------------------------------------------------------------

and use HD44780.h
:
//-------------------------------------------------------------------------------------------------
// Wyœwietlacz alfanumeryczny ze sterownikiem HD44780
// Sterowanie w trybie 4-bitowym bez odczytu flagi zajêtoœci
// z dowolnym przypisaniem sygna³َw steruj¹cych
// Plik : HD44780.h	
// Mikrokontroler : Atmel AVR
// Kompilator : avr-gcc
// Autor : Rados³aw Kwiecieٌ
// ڈrَd³o : http://radzio.dxp.pl/hd44780/
// Data : 24.03.2007
//-------------------------------------------------------------------------------------------------

#include 
#include 

//-------------------------------------------------------------------------------------------------
//
// Konfiguracja sygna³َw steruj¹cych wyœwietlaczem.
// MoØŸna zmieniÙˆ stosownie do potrzeb.
//
//-------------------------------------------------------------------------------------------------
#define LCD_RS_DIR		DDRF
#define LCD_RS_PORT 	PORTF
#define LCD_RS_PIN		PINF
#define LCD_RS			(1 << PF4)

#define LCD_RW_DIR		DDRF
#define LCD_RW_PORT		PORTF
#define LCD_RW_PIN		PINF
#define LCD_RW			(1 << PF5)

#define LCD_E_DIR		DDRF
#define LCD_E_PORT		PORTF
#define LCD_E_PIN		PINF
#define LCD_E			(1 << PF6)

#define LCD_DB4_DIR		DDRF
#define LCD_DB4_PORT	PORTF
#define LCD_DB4_PIN		PINF
#define LCD_DB4			(1 << PF0)

#define LCD_DB5_DIR		DDRF
#define LCD_DB5_PORT	PORTF
#define LCD_DB5_PIN		PINF
#define LCD_DB5			(1 << PF1)

#define LCD_DB6_DIR		DDRF
#define LCD_DB6_PORT	PORTF
#define LCD_DB6_PIN		PINF
#define LCD_DB6			(1 << PF2)

#define LCD_DB7_DIR		DDRF
#define LCD_DB7_PORT	PORTF
#define LCD_DB7_PIN		PINF
#define LCD_DB7			(1 << PF3)

//-------------------------------------------------------------------------------------------------
//
// Instrukcje kontrolera Hitachi HD44780
//
//-------------------------------------------------------------------------------------------------

#define HD44780_CLEAR					0x01

#define HD44780_HOME					0x02

#define HD44780_ENTRY_MODE				0x04
	#define HD44780_EM_SHIFT_CURSOR		0
	#define HD44780_EM_SHIFT_DISPLAY	1
	#define HD44780_EM_DECREMENT		0
	#define HD44780_EM_INCREMENT		2

#define HD44780_DISPLAY_ONOFF			0x08
	#define HD44780_DISPLAY_OFF			0
	#define HD44780_DISPLAY_ON			4
	#define HD44780_CURSOR_OFF			0
	#define HD44780_CURSOR_ON			2
	#define HD44780_CURSOR_NOBLINK		0
	#define HD44780_CURSOR_BLINK		1

#define HD44780_DISPLAY_CURSOR_SHIFT	0x10
	#define HD44780_SHIFT_CURSOR		0
	#define HD44780_SHIFT_DISPLAY		8
	#define HD44780_SHIFT_LEFT			0
	#define HD44780_SHIFT_RIGHT			4

#define HD44780_FUNCTION_SET			0x20
	#define HD44780_FONT5x7				0
	#define HD44780_FONT5x10			4
	#define HD44780_ONE_LINE			0
	#define HD44780_TWO_LINE			8
	#define HD44780_4_BIT				0
	#define HD44780_8_BIT				16

#define HD44780_CGRAM_SET				0x40

#define HD44780_DDRAM_SET				0x80

//-------------------------------------------------------------------------------------------------
//
// Deklaracje funkcji
//
//-------------------------------------------------------------------------------------------------

void LCD_WriteCommand(unsigned char);
unsigned char LCD_ReadStatus(void);
void LCD_WriteData(unsigned char);
unsigned char LCD_ReadData(void);
void LCD_WriteText(char *);
void LCD_GoTo(unsigned char, unsigned char);
void LCD_Clear(void);
void LCD_Home(void);
void LCD_Initalize(void);
void LCD_ProgrammChar(unsigned char nr, unsigned char znak[]);

//-------------------------------------------------------------------------------------------------
//
// Koniec pliku HD44780.h
//
//-------------------------------------------------------------------------------------------------

i want to connect it to portF but when i program board with those files but program hold on while(LCD_ReadStatus()&0x80); please help me:(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You should start your LCD programming with an 8-bit data interface that uses software time delays. Do not initially attempt a 4-bit interface and certainly not one that entails reading the busy flag.

I see that you found the 'Code' button.

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As your code appears to be written for avr-gcc is there some reason you are rewriting LCD support for the ten gazillionth time when so many people previously have got it written, tried and tested to save you the bother?

There's evern working HD44780 code (4 bit) that comes with your C compiler (as it tells you in the manual that no one ever reads).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

floresta1212 wrote:
You should start your LCD programming with an 8-bit data interface that uses software time delays. Do not initially attempt a 4-bit interface and certainly not one that entails reading the busy flag.

I see that you found the 'Code' button.

Don


thanks for your answer:)
but i have to use 4 bit for my lcd please guide me how i can fix this!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
As your code appears to be written for avr-gcc is there some reason you are rewriting LCD support for the ten gazillionth time when so many people previously have got it written, tried and tested to save you the bother?

There's evern working HD44780 code (4 bit) that comes with your C compiler (as it tells you in the manual that no one ever reads).


what can i do to use 4bit for my lcd?please guide me thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
what can i do to use 4bit for my lcd?please guide me thanks

You can read the documentation, like Cliff told you. Or you can search this site for the hundreds (yes, literally hundreds) of different threads discussing AVRs and LCD modules (and find several implementations for 4-bit interface, spanning from a minimal demo program by "yours truly" over more generally usable implementations (given both in discussion threads and in the project area here at AVRfreaks) over to the full-function libraries by e.g. Peter Fleury or Pascal Stang)).

I'll spoil you with the link to the documentation that Cliff mentioned: http://www.nongnu.org/avr-libc/u...

My minimal demo is here: https://www.avrfreaks.net/index.p...

We had a thread here just the other day where there was a link presented to Peter Daneggers (user 'danni') LCD code. You should be able to search it out easily given recentness and that you now know the name of the author.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
what can i do to use 4bit for my lcd?please guide me thanks
You start by getting the 8-bit interface code working, then you modify a very small percentage of this working code to use the 4-bit interface.

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
Quote:
what can i do to use 4bit for my lcd?please guide me thanks

You can read the documentation, like Cliff told you. Or you can search this site for the hundreds (yes, literally hundreds) of different threads discussing AVRs and LCD modules (and find several implementations for 4-bit interface, spanning from a minimal demo program by "yours truly" over more generally usable implementations (given both in discussion threads and in the project area here at AVRfreaks) over to the full-function libraries by e.g. Peter Fleury or Pascal Stang)).

I'll spoil you with the link to the documentation that Cliff mentioned: http://www.nongnu.org/avr-libc/u...

My minimal demo is here: https://www.avrfreaks.net/index.p...

We had a thread here just the other day where there was a link presented to Peter Daneggers (user 'danni') LCD code. You should be able to search it out easily given recentness and that you now know the name of the author.

thankksss
i use this but i can see my lcd initial well but nothing write on lcd:(
/* Simple LCD character display module demonstrator using
* the 4-bit interface. No handling of the busy flag is
* done - all timing contraints are handled by delay loops.
* This code should be good to run at up to 8 MHz.
* Above that you might have to tweak the timing of things
* including, but not restricted to, the existing delays.
*/

#include
#include

/* Here are some defines for the data connections,
* DB4..7 on the LCD display module. These should be wired
* up to the four high pins of any port A..D. You need to alter
* these to fit your wire up of your display.
*/
#define LCD_DATA_PORT PORTF
#define LCD_DATA_DDR DDRF

/* Here are some defines for the control connections
* (RS, R/W and E on the LCD display module). These can be wired
* to any pins on any port A..D (all to the same port though).
* You need to alter these to fit your wire up of your display.
*/
#define LCD_CTRL_PORT PORTF
#define LCD_CTRL_DDR DDRF
#define LCD_RS 0
#define LCD_RW 1
#define LCD_E 2

/*
* YOU SHOULD NOT NEED TO ALTER ANYTHING BEYOND THIS POINT!
*
* This holds as long as you have the four data signals
* connected to the upper 4-bit nibble of the AVR port,
* and you run at a maximum frequency of 8 MHz.
*/

/* Here are some defines for the LCD instructions we'll use.
*/
#define LCD_FUNCTION_SET 0x38 // 0b00110000
#define LCD_FUNCTION_SET_4BIT 0x28 // 0b00101000
#define LCD_DISPLAY_OFF 0x08 // 0b00001000
#define LCD_DISPLAY_ON 0x0F // 0b00001111
#define LCD_DISPLAY_CLEAR 0x01 // 0b00000001
#define LCD_ENTRY_MODE_SET 0x06 // 0b00000110
#define LCD_CURSOR_HOME 0x02 // 0b00000010

/* LcdSendNibble
*
* Sends a 4-bit nibble to the display.
*
* Parameters:
* uint8_t nibble The high nibble of of this byte
* is sent to the display.
* Returns:
* nothing
*/
void LcdSendNibble( uint8_t nibble )
{
_delay_ms(5);

// Output upper nibble on the data ports upper bits
LCD_DATA_PORT = (nibble & 0xF0) | (LCD_DATA_PORT & 0x0F);

// Toggle the E line
LCD_CTRL_PORT |= (1<<LCD_E); // Going up..
LCD_CTRL_PORT &= ~(1<<LCD_E); // ..and down.
}

/* LcdSendByte
*
* Sends a 8-bit byte to the display.
*
* Parameters:
* uint8_t theByte The byte to send to the display
*
* Returns:
* nothing
*/
void LcdSendByte(uint8_t theByte)
{
// Send the high nibble
LcdSendNibble(theByte);

// Shift theByte to get lower nibble in upper part...
theByte = theByte << 4;
// ...and send it
LcdSendNibble(theByte);
}

/* LcdSendInstruction
*
* Sends an instruction to the display.
*
* Parameters:
* uint8_t command This byte is sent to the display as
* an instruction (RS low).
* Returns:
* nothing
*/
void LcdSendInstruction( uint8_t theInstruction )
{
// RS low for instructions
LCD_CTRL_PORT &= ~(1<<LCD_RS);

// Send the instruction
LcdSendByte(theInstruction);
}

/* LcdSendCharacter
*
* Sends a character to the display.
*
* Parameters:
* uint8_t nibble This byte is sent to the display as
* a character (RS high).
* Returns:
* nothing
*/
void LcdSendCharacter(uint8_t theChar)
{
// RS high for characters to display
LCD_CTRL_PORT |= (1<<LCD_RS);

// Send the command
LcdSendByte(theChar);
}

/* LcdInitialize
*
* Initialize the display.
*
* Parameters:
* none
*
* Returns:
* nothing
*/
void LcdInitialize(void)
{
// initialize LCD control lines
LCD_CTRL_PORT &= ~(1<<LCD_RS); // RS low
LCD_CTRL_PORT &= ~(1<<LCD_RW); // R/W low
LCD_CTRL_PORT &= ~(1<<LCD_E); // E low

// initialize LCD control lines to output
LCD_CTRL_DDR |= (1<<LCD_RS);
LCD_CTRL_DDR |= (1<<LCD_RW);
LCD_CTRL_DDR |= (1<<LCD_E);

// initialize LCD data port to input
LCD_DATA_DDR |= 0xF0; // Data on high four bits of port for now...

// First part of init sequence is 3 x Function Set with
// stipulated waits. Note that the display is in 8-bit mode
// initially, but although the four low data lines are not connected
// this does not matter as the instructions low nibble is zero anyway.
_delay_ms(15);
LcdSendNibble( LCD_FUNCTION_SET );
_delay_ms(5);
LcdSendNibble( LCD_FUNCTION_SET );
_delay_us(100);
LcdSendNibble( LCD_FUNCTION_SET );

// Now, still in 8-bit mode, set the display to 4-bit mode
LcdSendNibble( LCD_FUNCTION_SET_4BIT );

// We are now in 4-bit mode.
// Do the rest of the init sequence.
LcdSendInstruction( LCD_FUNCTION_SET_4BIT );
LcdSendInstruction( LCD_DISPLAY_OFF );
LcdSendInstruction( LCD_DISPLAY_CLEAR );
LcdSendInstruction( LCD_ENTRY_MODE_SET );
LcdSendInstruction( LCD_DISPLAY_ON );
}

char message[] = "4-bit avr-gcc";

int main(void)
{
LcdInitialize();
LcdSendInstruction( LCD_DISPLAY_CLEAR );

volatile int i = 0;
while (message[i] != 0)
{
LcdSendCharacter(message[i]);
i++;
}

while(1)
{
LcdSendCharacter('N');
_delay_ms(500);
}
return 0;
}
i just chande PORTD to PORTF and connect pin 0-3 rs-rw-e
and 4-7 d4,d5,d6,d7 :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
i just chande PORTD to PORTF and connect pin 0-3 rs-rw-e
and 4-7 d4,d5,d6,d7
The underlined part mentions 4 pins and 3 signals. Are you sure you are using 0, 1, and 2 as called for in the defines?

* This code should be good to run at up to 8 MHz.
* Above that you might have to tweak the timing of things
* including, but not restricted to, the existing delays. 

How did you deal with this part?

There are two important delays missing from the LCD initialization routine. I discussed them with danni here: https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=102296, but I think this is Johan's code and I probably missed the omission when I looked at his code a long time ago.

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don wrote:
I think this is Johan's code

It is, more or less, with some changes. And my code of-course had some indention.. :evil:
Don wrote:
There are two important delays missing from the LCD initialization routine.

I've re-read the thread you linked to, and I think I see what delays you are talking about. AFAIK my init sequence follows the data sheet "to the letter".

The first delay you miss is right before the instruction for going into 4-bit mode, right? I can see how it makes sense that this might be an omission in the data sheet.

The second delay you are missing is the one right after going into 4-bit mode. Please note that at that point the LcdSendInstruction() is use, and that starts with a delay (which could be replaced with a call to a wait for the busy flag to clear). I'll have to go through the data sheet to see if this delay is enough. (In this particlular instance it should give ample time for the instruction to go into 4-bit mode to finish, and I don't have the timing for that in my head. Generally it would need to be long enough for the instruction taking the longest time, which is "Clear Display" IIRC.)

Thank you for the heads-up.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Johan:

I found the second 'missing' delay at the beginning of LcdSendNibble. Five mS should be long enough for any of the instructions even if the LCD controller clock is running at the low end of it's specification. You should look into the possibility of moving that delay up one level into LcdSendByte since there is no need for any delay between the two nibbles.

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

floresta1212 wrote:
Johan:

I found the second 'missing' delay at the beginning of LcdSendNibble. Five mS should be long enough for any of the instructions even if the LCD controller clock is running at the low end of it's specification. You should look into the possibility of moving that delay up one level into LcdSendByte since there is no need for any delay between the two nibbles.

Don

thanks my friend......please give me the true file:)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I pointed out three separate problems in my previous post but I haven't seen any response from you. As far as the third problem goes, there's only one missing delay.

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sorry im from iran and i can not speak english very well and maybe i could not give you my meaning to you..!!
thanks for your help and sorry again....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your English is a lot better than my Farsi. Let's try the three problems again:

(1)

Quote:
i just chande PORTD to PORTF and connect pin 0-3 rs-rw-e
and 4-7 d4,d5,d6,d7
Are you sure that you have RS, RW, and E connected to the correct pins. You mention four pins (0, 1, 2, and 3) but there are only three signals.

(2)

Quote:
* YOU SHOULD NOT NEED TO ALTER ANYTHING BEYOND THIS POINT!
*
* This holds as long as you have the four data signals
* connected to the upper 4-bit nibble of the AVR port,
* and you run at a maximum frequency of 8 MHz.
Your processor is running at 16 MHz but the time delays were written for a processor that is running at 8 MHz. You have to account for this difference somehow. I believe it is a function of your compiler but I am not familiar with any of them as I program in assembly language.

(3)

Quote:
LcdSendNibble( LCD_FUNCTION_SET );

// Now, still in 8-bit mode, set the display to 4-bit mode
LcdSendNibble( LCD_FUNCTION_SET_4BIT );

There must be a delay between these two instructions even though the datasheet doesn't show one.

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks Don:)

(1) yes i write here wrong but i connect this to my lcd correctlly
(2)i read this in datasheet of atmega128rfa1:
It is not required to change the prescaler setting of an existing software package written
for an 8MHz internal RC oscillator. The change of the prescaler (additional 1:2 divider)
is compensated by doubling the RC oscillator frequency of the ATmega128RFA1.
is there problem yet?!
(3)how much delay need to work fine?

thanks Don for answer to me:)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
(3)how much delay need to work fine?
In my reply to you above where I first mentioned the missing delay I wrote:If you follow that link and look at my reply to danni you will find the answer.

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

floresta1212 wrote:
Johan:

I found the second 'missing' delay at the beginning of LcdSendNibble. Five mS should be long enough for any of the instructions even if the LCD controller clock is running at the low end of it's specification. You should look into the possibility of moving that delay up one level into LcdSendByte since there is no need for any delay between the two nibbles.

Don

I can sort of see how the same delay was there in the 8-bit version of this test/demo program, and when the 8-bit LcdSendByte got mangled into the 4-bit LcdSendNibble the delay got stuck there, instead of moving to the 4-bit implementation of LcdSendByte.

The other reason for having the delay there could be when LcdSendNibble is used for sending 8-bit instructions to a display still in 8-bit mode. But this happens only in the first stages of initialization, and at that point explicit/separate delays are coded for each of the early steps (well, you've pointed out the missing one that we think is a data sheet mistake, but you get what I mean...) so it seems you're correct in that the delay is not needed in LcdSendNibble.

nta_xyz!
I will have no time to get the AVR+LCD stuff out for at least a week, probably longer. Your best bet is to sit down, read the tutorials here, read a good 44780 data sheet and understand what they say. Then you should be good to go.

Have we asked you about what you did about contrast adjustment?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]