Connecting LCD to ATmega32 using STK500

Hello guys,

I am new user to the microcontroller world, can anyone please help me how to connect LCD to ATmega32 using the STK500 Hyperterminal to display strings on HITACHI model LCD. I have tested all the codes that I get online but it seems nothing is coming on the LCD.

Do I need anything to do after programming the microcontroller directly from the Simulator/Emulator of AVR Studio?

I am crazy for help, please!!!

I’ll start by saying that I know virtually nothing about the AVR series, but…

Are you sure that everything is okay with the display, electrically? Can you see the ‘ghost images’ of the pixels and/or character blocks when it is receiving power? Have you played with the contrast settings to see if it may not just be turned down too far? Many of the LCD modules I have used come with a factory setting on the contrast pot that is way too low for actual use, making me think that there was something wrong, when it was actually just too dim to see.

When I’m experimenting with LCDs, I usually run the contrast a bit high, so that I can at least make out the grid of characters when they aren’t active. That way, I can tell when the display is receiving power (especially important if your application switches power to the LCD separately), and it makes laying out the text a bit easier when you can actually count the spaces.

It is difficult to know how to help you here, with so little information. Things like how is it hooked up. Do you see anything when you power it on…

I have connected hitachi LCDs to ATMEGA32s before. This was done as part of the Seattle Robotics Society workshop robot in their Level 2 workshop. You can find more information about it at:
seattlerobotics.org/WorkshopRobot/level2/index.php

They show a couple ways of hooking them up. One which takes six I/O pins for it and another with 3. They also have source code that allows you to try it out. Note this code and hook ups are geared around a kit that developed by the members and now is sold through Maximum Robotics.
maximumrobotics.com/store/index.php?main_page=advanced_search_result&search_in_description=1&keyword=srs

I hope this helps. If not, you might want to provide some more detailed information, like what I/O pins it is hooked up to, samples of the code that you are using to try to interface to LCD and the like.

Good Luck

Hey,

I want to use PORTC to connect the LCD and display a string based on an anlog voltage I will be reading from PORTA. The LCD seems to work fine since it is blinking full during power up and the back light LEDs are also working fine. I have also tested the hyperterminal using the LEDs on board and it seems working fine too.

I am using codes I downloaded from various sites with LCD.H and LCD.C files (4-bit mode codes are what I am looking for)
I am using the one from Hey,

I want to use PORTC to connect the LCD and display a string based on an anlog voltage I will be reading from PORTA. The LCD seems to work fine since it is blinking full during power up and the back light LEDs are also working fine. I have also tested the hyperterminal using the LEDs on board and it seems working fine too.

I am using codes I downloaded from various sites with LCD.H and LCD.C files (4-bit mode codes are what I aml ooking for)
I tried some codes from 4bit_lcd.zip from www.spickles.org/projects/4-bit-lcd/4bit_lcd.zip

thanks

thanks

Again it would help to have additional information here. you say it is an Hitachi LCD, which probably just the command set it uses. You are also saying that you are using PortC and you talk about 4 bit code. So again I am assuming a parallell LCD.

So assuming your LCD-Controller is similar you have have DB4-DB7 (data lines) connected to some pins on Port C (maybe C4-C7?). You also have the Enable(E) line connected to another I/O port pin and Likewise for the Register Select (RS) pin connected to another I/O output pin. When you output a normal character character on this display the RS is high and when you output a command the RS is low. For each nibble you output you need to set the appropriate 4 data bits and toggle the E bit high and then low to toggle it out. There is also initialization code that you need to set this controller into 4 bit mode instead of 8 bit mode. I have include some excerpts of the SRS workshop C++ class below that shows some of this.

void LCD::Init() const
{
	m_fInit = true;

	/* make sure LCD has a chance to finish initializing after power-up */
	m_ptimer->WaitMs(20);

	/* send forced reset */
	WriteNibble(0, 0x03);	// (RS = 0, code = 0011)
	m_ptimer->WaitMs(5);
	WriteNibble(0, 0x03);
	m_ptimer->WaitMs(1);
	WriteNibble(0, 0x03);
	m_ptimer->WaitMs(1);

	/* default is 8-bit operation; we send the top half, it changes,
	   then we need to send the request again to set the rest of the
	   options for that command (e.g. 2 lines) (from that point on,
	   all instructions are sent in 2 parts, high and low) */
	WriteNibble(0, 0x02);	// set 4-bit operation (RS = 0, code = 0010 [4-bit])
	m_ptimer->WaitMs(1);
	WriteCommand(0, 0x28);	// 4-bit operation, 2 lines (5x8)

	/* other initialization */
	WriteCommand(0, 0x06);	// increment, no shift
	ClearAndReturn();		// clear screen and return cursor home
	HideCursor();			// (this also turns on display)
}

/* prints given string on the specified line (1 or 2);
   remainder of (visible) line will be padded with spaces by default */
void LCD::Print(const char *psz, char line, bool fPad) const
{
	const char *pch, *pchLim;

	SetMemAddr(line == 1 ? 0x80 : 0xC0);
	pch = psz;
	while (*pch != 0)
		WriteCh(*pch++);
	if (fPad)
	{
		/* blank rest of line */
		pchLim = psz + cchScreen;
		while (pch++ < pchLim)
			WriteCh(' ');
	}
}

/* writes a character at the current location, updates
   current location to next space (to right) */
void LCD::WriteCh(char ch) const
{
	WriteCommand(1, ch);
}

/* clears the display and resets the current location to the upper left */
void LCD::ClearAndReturn() const
{
	WriteCommand(0, 0x01);	// clear display
	m_ptimer->WaitMs(5);	// a guess...
	WriteCommand(0, 0x02);	// return home (can take 1.52ms)
	m_ptimer->WaitMs(2);
}


/* send an instruction to the LCD; we need to send a byte, which
   is done in two nibbles, high, then low */
void LCD::WriteCommand(bool fRS, unsigned char ch) const
{
	/* send high 4 bits, then low 4 bits */
	WriteNibble(fRS, ch >> 4);
	WriteNibble(fRS, ch & 0x0f);
}

/* set outputs for LCD control, then toggle Enable */
void LCD::WriteNibble(bool fRS, unsigned char ch) const
{
	int ipout;

	if (fRS)
		m_poutRS->High();
	else
		m_poutRS->Low();

	/* the nibble to send is in ch: xxxxDCBA
	   D goes to DB7, C to DB6, B to DB5, A to DB4;
	   the code sets outputs from low (A/DB4) to high (D/DB7) */
	for (ipout = 0; ipout < ipoutMax; ++ipout)
	{
		/* see if low bit is set */
		if (ch & 0x01)
			m_apout[ipout]->High();
		else
			m_apout[ipout]->Low();
		/* shift ch right 1 bit to get next bit in low spot */
		ch >>= 1;
	}

	/* all data is now waiting for LCD; needs to be stable
	   for >=40ns before E high */
	asm("nop");
	m_poutE->High();
	/* need to wait 230ns before E low
	   (nop = 1 cycle = 125ns at 8MHz; do enough for 16MHz)*/
	asm("nop");
	asm("nop");
	asm("nop");
	asm("nop");
	m_poutE->Low();
	
	/* we need to make sure LCD inputs don't change for 10ns after
	   E low, which would be taken care of by other instructions;
	   but, processing of request can take up to 37+4us, so
	   just to be safe, we'll delay for another ms here */
	m_ptimer->WaitMs(1);
}

The rest of the code as well as documention is up on the web site I mentioned previously.

Note: this code uses some other classes, such as an IN and OUT which properly initialize the atmel registers to set the IO pins for either Input or Output. In this case they are all output pins.

I tried your link but it pointed to somewhere strange…

Good Luck

Sure I am using parallel LCD and I am connecting DB4-DB7 to PORTC 4-7 and the RS, RW, E to PORTC 0-2.

I have tested the code from the site you recommend but I am not able to compile it as it is reporting error on declaring the classes. In fact, it is my first code to see written in OOP in the AVR Studio, and I am not quit sure if it is the problem with my AVR studio or something else.
The code I tested previously is downloaded from spickles.org/projects/4-bit-lcd

Thanx.

Ok, I downloaded the 4 bit code you mentioned and the first question is how did you update the stuff in LCD_4bit.h. In the file I downloaded I see:

// LCD Port Information (from microcontroller) #define LCD_OUT PORTA #define LCD_IN PINA #define LCD_DDR DDRA #define ENABLE 6 #define RW 5 #define RS 4 #define D7 3 #define D6 2 #define D5 1 #define D4 0
So I assume you changed the defines for LCD_OUT and the like to
PORTC instead of PORTA

Also as your pins you mention for RS,RW,E do not match the assigments in this file (in theirs 7 is NC and in yours 4 is NC). If I read your order correctly, you would have the pins defined: RS=7, RW=6, ENABLE=5?

As for the code on the SRS site, If you are getting the compiler error that I think you are getting, it is due to the changes that have been made to the WINAVR(GCC) header files. If the error is in timer.cpp, try changing the like from INTERRUPT(…) to SIGNAL(…)

Kurt

P.S. - This thread should be moved to general programming as it has nothing to do with the SSC-32…