LCD not displaying character in ATMega16

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

Hi all,

I'm newbie to AVR family. I'm trying to interface LCD with ATMega16. Following are information for reference.

1. LCD is connected in PORT A, LCD configured as 4 bit data mode.
2. LCD control signals connected to PORT A.
3. I'm using 16X2 character LCD.
4. IDE is AVR Studio 4 with WinAVR compiler.

The same code was working 1 months back, but now it is not working. I have been working on the same board trying different samples. Now when I try, LCD is not displaying expected character, instead entire pixels are glowing in full brightness for full VEE voltage.

I have attached code for LCD that I'm using for your reference.

#include 
#include
#include


#define LCD_PORT PORTA				// PortA as LCD command port	
#define LCD_DDR  DDRA



#define rs 0					// RS pin to PA0	
#define en 1					// EN pin to PA1
//RW pin to PA6		

void lcd_init(void);					// Function to init lcd ie to start display ,4 bit mode, cursor ON, etc
void write_command(unsigned char comm);		// Function to write command in lcd 
void write_data(unsigned char lcd_data);			// Fuction to write data in lcd
void lcd_clrscr(void);
void lcd_printc(char);


//LCD
void lcd_init(void)
{
	_delay_ms(300);
	
	LCD_DDR=0b11110011;					//Initialize the LCD port first
	
	write_command(0x80);					//initial address of DDRAM for first line
	write_command(0x28);					//To select 4 bit data
		
	write_command(0x0e);					//Command to on the display & cursor blink/blink off
	write_command(0x01);					//Command to clear LCD display
	
	write_command(0x06);					//Command for character entry mode
}


void write_command(unsigned char comm)
{
	
	_delay_ms(2);
	LCD_PORT=((comm & 0xF0)|(1<<en)); 	//Sending 4 MSB bits of command, & Enable=1,RW=0,RS=0;
	cbi(LCD_PORT,en);
	
	LCD_PORT=((comm<<4)|(1<<en)); 		//Sending 4 LSB bits of command
	cbi(LCD_PORT,en);
}


 void write_data(unsigned char lcd_data)
{
	_delay_ms(2);
	
	LCD_PORT=((lcd_data & 0xF0)|(1<<en)|(1<<rs)); 	//Sending 4 MSB bits of command, & Enable=1,RW=0,RS=1;
	cbi(LCD_PORT,en);
	
	LCD_PORT=((lcd_data<<4)|(1<<en)|(1<<rs)); 		//Sending 4 LSB bits of command
	cbi(LCD_PORT,en);
}

void lcd_printc(char data)
{
		write_data(data);
}

void lcd_clrscr(void)
{
	write_command(0x01);
	_delay_ms(3);
	write_command(0x80);
}

int main(void)
{
	char test[] = "AVR LCD";
	int i = 0;
	lcd_init();
	while(1)
	{
		for(i = 0; i < 8; i++)
		{
			lcd_printc(test[i]);
			_delay_ms(300);
		}
		lcd_clrscr();
		write_command(0X02);
	}
	
}

I hope ADC in PORT A will not affect LCD, whether is there any bit or register to disable ADC? Even if I connect to other PORTs, I'm facing same issue. I have even tried with 2 fresh new IC's too.
Please help Me to sort out the issue.

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

Why not use the LCD code that came with your compiler simply to verify the electronics?

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

Quote:
Now when I try, LCD is not displaying expected character, instead entire pixels are glowing in full brightness for full VEE voltage.
When you adjust the voltage on pin 3 you should get a blank display at full voltage and a very dark display at 0 volts. The correct setting is typically around 0.5 volts. With just pins 1, 2, and 3 (and the backlight, if you have one) connected you should then barely see blocks on the top row and the second row should be blank.

You should also consider using the initialization steps shown in the flowcharts rather than in the examples that precede them. Those examples rely on the internal initialization which is not reliable. For an explanation follow the LCD Initialization link at http://web.alfredstate.edu/weimandn.

Don

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

WrightFlyer wrote:
Why not use the LCD code that came with your compiler simply to verify the electronics?

Thank you WrightFlyer. Will try my compiler's sample LCD code and let you know.

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

floresta1212 wrote:
Quote:
Now when I try, LCD is not displaying expected character, instead entire pixels are glowing in full brightness for full VEE voltage.
When you adjust the voltage on pin 3 you should get a blank display at full voltage and a very dark display at 0 volts. The correct setting is typically around 0.5 volts. With just pins 1, 2, and 3 (and the backlight, if you have one) connected you should then barely see blocks on the top row and the second row should be blank.

Thank You floresta. The output of LCD display is working as you specified. Even I set VEE voltage to nominal value, but does not displays character. Will also try the LCD initialization steps specified in the link you gave.

Still I'm not able to find out how the same hex file worked like charm before and now sucks. Is there any steps to be taken care to disable ADC functionality of PORTA? If so, please let guide me.

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

Is pin AVCC connected to VCC ?