LCD display

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

i'm having trouble with the display:
i'm using KS0066U dased lcd(PC1602F from POWERTIP company)

my code:

main.h

#ifndef MAIN_H 

#define MAIN_H 

#include 
#include 
#include 



#define LCD_DATA_PORT PORTD
#define LCD_DATA_DDR DDRD

//define lcd control port
#define LCD_CTRL_PORT PORTB
#define LCD_CTRL_DDR DDRB
#define LCD_rs 0
#define LCD_rw 1
#define LCD_en 2




// LCD instructions
#define LCD_origin() LCD_command(0x2)	/* Set to origin LCD */
#define LCD_function_set() LCD_command(0x28) /* LCD function set */
#define LCD_display_off() LCD_command(0x08) /* LCD display off*/
#define LCD_display_on() LCD_command(0x0F) /* LCD display on*/
#define LCD_display_clear() LCD_command(0x01)/* Clear display LCD */
#define LCD_mode_set() LCD_command(0x06) /* LCD mode set */



//functions declarations
void LCD_enable();
void LCD_command(unsigned char command);
void LCD_putc(unsigned char ascii);
void LCD_puts(unsigned char *lcd_string);
void LCD_init();
#endif

main.c

#include "main.h"




unsigned char *ptr = "AVR Project";

 

 

int main()
{
	
	
	LCD_init();

	
	LCD_puts(ptr);
	
	
}	


void LCD_enable()
{
    LCD_CTRL_PORT &= ~(1<<LCD_en); 
    _delay_ms(1);
    LCD_CTRL_PORT |= (1<<LCD_en); 
}

void LCD_command(unsigned char command)
{
    LCD_CTRL_PORT &= ~(1<<LCD_rs); 
    LCD_DATA_PORT = (command & 0xF0)|(LCD_DATA_PORT & 0x0F);
    LCD_enable();
    LCD_DATA_PORT = (command << 4 & 0xF0)|(LCD_DATA_PORT & 0x0F);
    LCD_enable();
    _delay_ms(1);
}

void LCD_putc(unsigned char ascii)
{
    LCD_CTRL_PORT |= (1<<LCD_rs); 
    LCD_DATA_PORT = (ascii & 0xF0)|(LCD_DATA_PORT & 0x0F);
    LCD_enable();
    LCD_DATA_PORT = (ascii << 4 & 0xF0)|(LCD_DATA_PORT & 0x0F);
    LCD_enable();
    _delay_ms(1);
}

void LCD_puts(unsigned char *lcd_string)
{
	while (*lcd_string) 
	{
		LCD_putc(*lcd_string++);
	}
}

void LCD_init()
{

   //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_en);	// 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_en);

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


	_delay_ms(30);
	LCD_function_set();
	LCD_function_set();
    _delay_us(40);
	LCD_display_off();
	_delay_us(40);
	LCD_display_clear();
	_delay_ms(2);
	LCD_mode_set();
	LCD_display_on();

}

i'm using it in 4-bit mode, when i apply power it only shows that the power is available but nothing is displayed.

i'll appreciate any help, from circuit connections to software

regards

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

Your enable routine is backwards. You should be sending it high, then low.

In looking at the datasheet for the KS0066U, the beginning of the initialization in 4 bit mode looks a little different than the typical HD44780 clone. Try sending a single 4 bit value of 3, then the full function set.

Regards,
Steve A.

The Board helps those that help themselves.

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

Koshchi wrote:
Your enable routine is backwards. You should be sending it high, then low.

In looking at the datasheet for the KS0066U, the beginning of the initialization in 4 bit mode looks a little different than the typical HD44780 clone. Try sending a single 4 bit value of 3, then the full function set.

Things could not work out.

my hardware configurations:

LCD------------MCU(ATmega8)

Vss-------------------------->POWER SUPPLY(GND)
Vdd-------------------------->POWER SUPPLY(+5v)
Vo(Contrast Adjust)---------->(120 ohm to GND)

DB7-------------PD7
DB6-------------PD6
DB5-------------PD5
DB4-------------PD4

(DB3-DB0) not connected

(PIN 15 & 16 ) not connected

any help!

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

Have you tied the unused data lines to ground?

Nigel Batten
www.batsocks.co.uk

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

condemned wrote:
Have you tied the unused data lines to ground?

yes, DB3 - DB0 are all tied to GND!

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

I think that koschi's correct.
a) It looks like the enable routine is inversed
b) look at the init routines.

According to the KS0066U doc I've got open, the 4-bit initialise routine should be:

wait 30ms
send 0x2(0) (toggle e)
send 0x2(0) (toggle e)
send 0x8(0) (toggle e)
wait
[other codes]
...

Your initialise routine appears to just do:
wait 30ms
send 0x2(0) (toggle e)
send 0x8(0) (toggle e)
send 0x2(0) (toggle e)
send 0x8(0) (toggle e)
wait
[other codes]
...

[edit: corrected summary of your current init routine]

Nigel Batten
www.batsocks.co.uk

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

this can't work either

void LCD_init() 
{ 

   //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_en);   // 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_en); 

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

   _delay_ms(30);
   LCD_command(0x20); 
   LCD_command(0x28); //function sset
    _delay_us(40); 
   LCD_command(0x08); //display off
   _delay_us(40); 
   LCD_command(0x01); //clear diaplay
   _delay_ms(2); 
   LCD_command(0x06);//entry mode 
   LCD_command(0x0F);// display on 
}

what else might be wrong.

do unconnected LED backlight power suply pins on LCD has effect. if yes, how do i connect them.

any other help will be appreciated

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

Your initialise routine now does:

wait 30ms
send 0x2(0) (toggle e)
send 0x0(0) (toggle e)
send 0x2(0) (toggle e)
send 0x8(0) (toggle e)
wait
[other codes]

I think it needs to do:

wait 30ms
send 0x2(0) (toggle e)
send 0x2(0) (toggle e)
send 0x8(0) (toggle e)
wait
[other codes]

You can't simply use the existing LCD_command routine, since it always sends a pair of commands and you need to send three.

Nigel Batten
www.batsocks.co.uk

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

condemned wrote:
Your initialise routine now does:

wait 30ms
send 0x2(0) (toggle e)
send 0x0(0) (toggle e)
send 0x2(0) (toggle e)
send 0x8(0) (toggle e)
wait
[other codes]

I think it needs to do:

wait 30ms
send 0x2(0) (toggle e)
send 0x2(0) (toggle e)
send 0x8(0) (toggle e)
wait
[other codes]

You can't simply use the existing LCD_command routine, since it always sends a pair of commands and you need to send three.

thanks for clarifying that! it works now!

i have this!

void LCD_nibble(unsigned char nibble){
    LCD_CTRL_PORT &= ~(1<<LCD_rs); 
    LCD_DATA_PORT = (nibble & 0xF0)|(LCD_DATA_PORT & 0x0F); 
    LCD_enable(); 
}

void LCD_init() 
{ 

   //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_en);   // 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_en); 

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

    _delay_ms(15);		
    LCD_nibble(0x30);
    _delay_ms(5); 
    LCD_nibble(0x30);
    _delay_ms(1); 
    LCD_nibble(0x30);	
    _delay_ms(1); 
    LCD_nibble(0x20);		//switch to 4 bit mode

   LCD_function_set(); 
    _delay_us(40); 
   LCD_display_off(); 
   _delay_us(40); 
   LCD_display_clear(); 
   _delay_ms(2); 
   LCD_entry_mode_set(); 
   LCD_display_on(); 
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, this code works like magic.
Modified the code slightly

LCD_entry_mode_set(); 

compiles if changed to

LCD_command(0x06);//entry mode 

And I used PORTD on account of using external 16Mhz clock (have to adjust delay). :D
==edit==
Will also play with setting+controlling the cursor-mode this weekend and paste up my changes if anyone is interrested instead of having to do scrolling manually.

Conrad Braam - www.softcircuitry.blogspot.com - www.plcsimulator.org
Always start off poorly, that way when you finally figure it out, you can get a few surprise hits in.