16*2 LCD with ATmega8 ( characters not being displayed )

Status
Not open for further replies.

Simple Minimal

New Member
Hello, everybody

LCD display: RC1602B-BIW-ESX ( datasheet )

Microcontroller: ATmega8 ( datasheet )

Everything works as excepted but displaying a character - it simply stays blank and the initial position does not change.

Am I missing something here ?

Code:
// Author:		Simple Minimal
// Date:		17.01.2012
// Version:		1.0
// License:		GPL

#include <avr/io.h>
#include <avr/delay.h>

#define DATA_REGISTRY		DDRD
#define CONTROL_REGISTRY	DDRB

#define DATA_PORT			PORTD
#define CONTROL_PORT		PORTB

#define CONTROL_RS			1			
#define CONTROL_EN			2
#define CONTROL_RW			3

void send_command(char data);
void send_character(char data);
void flash_led();

int main(void)
{
	CONTROL_REGISTRY = 0xFF;
	DATA_REGISTRY = 0xFF;
	DDRC = 0xFF;

	_delay_ms(400);
	
	// Function set ( 0 0 1 DL N F * * )
	send_command(0b00111000);
	send_command(0b00111000);

	// Clear display
	send_command(0b00000001);
	
	// Entry mode set ( 0 0 0 0 1 D C B )
	send_command(0b00000110);
	
	// Display control ( 0 0 0 0 1 D C B )
	send_command(0b00001110);
	
	send_character(0b01110100);
	send_character(0b01000001);

	while (1) {}
	
	return 0;
}

void send_command(char data)
{
	// EN to LOW
	CONTROL_PORT &= ~(1 << CONTROL_EN);
	_delay_ms(10);

	// RS to LOW ( command )
	CONTROL_PORT &= ~(1 << CONTROL_RS);
	_delay_ms(10);
	
	// EN to HIGH
	CONTROL_PORT |= 1 << CONTROL_EN;
	_delay_ms(10);
	
	// Put data on to the DB0-7 pins
	DATA_PORT = data;
	_delay_ms(10);
	
	// EN to LOW
	CONTROL_PORT &= ~(1 << CONTROL_EN);
	_delay_ms(40);
}

void send_character(char data)
{
	// EN to LOW
	CONTROL_PORT &= ~(1 << CONTROL_EN);
	_delay_ms(10);

	// RS to HIGH ( character )
	CONTROL_PORT |= 1 << CONTROL_RS;
	_delay_ms(10);
	
	// EN to HIGH
	CONTROL_PORT |= 1 << CONTROL_EN;
	_delay_ms(10);
	
	// Put data on to the DB0-7 pins
	DATA_PORT = data;
	_delay_ms(10);
	
	// EN to LOW
	CONTROL_PORT &= ~(1 << CONTROL_EN);
	_delay_ms(40);
}

void flash_led()
{
	/* LED to HIGH */
	PORTC |= 1 << 5;

	_delay_ms(250);

	/* LED to LOW */
	PORTC &= ~(1 << 5);

	_delay_ms(250);
}
 
Power Up display without ATMEGA. Then must be shown a Black Line on the Top and a Blank Line on the Bottom of the Display.
When that doesn't work it could be, there is something wrong with your contrast adjust ( Potentiometer ?! ).

When that works it is possible this pot must be re- adjustet when display is initialized.
Most of that displays must be initialized twice with a quite exact timing sequence.
Check that with your display datasheet.
 
Why would I power it up without the microcontroller ?
I'll repeat - everything works as expected ( the display gets initialized, I see the cursor, I can move it around, etc. ) except displaying a character ( send_character() function ).
 
here is the link for AVR sample codes...


scroll down... you will find codes for various interfacing modules...
 
Last edited by a moderator:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…