Need code for interface with lcd hitachi

Status
Not open for further replies.

vinodjprakash

Newbie level 2
Joined
Mar 17, 2006
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,298
avr and ke*il

hi

Added after 1 minutes:

i need source code interface 8515 atmel with lcd hitachi
 

Do you need source in Assembler or in C?
 

seach for avrlib on google it is a nice one. but it use with winavr
 

Hi,
in my opinion, u should write yoursefl in C, use CodevisionAVR compiler(compiler help u alots). it is easier and u can get much experiencies. if u dont want to do that, next time i will post LCD source code.
And if u did not have compiler, so it is here


Added after 17 minutes:

Here is code for textLCD,
//**************************************
// LCD function
// Version 1.0 Sept 2000
// Sylvain Bissonnette
//
//**************************************

//**************************************
// I N C L U D E
//**************************************
#include <io2313.h>

//**************************************
// D E F I N E
//**************************************
// User dependent BEGIN
#define D7 0x01
#define D6 0x02
#define D5 0x04
#define D4 0x08
#define E 0x10
#define RW 0x20
#define RS 0x40

#define LCDPIN (*(volatile unsigned char *)0x36) // PIN register
#define LCDDDR (*(volatile unsigned char *)0x37) // Data Direction Register
#define LCDPORT (*(volatile unsigned char *)0x38) // PORT
// User dependent END

//**************************************
// P R O T O T Y P E
//**************************************
void InitLCD(void);
void ClrLCD();
void GotoXY(unsigned char,unsigned char);
void WriteStrLCD(char *);
void WriteStrLCDConst(const char *);
void WriteByteLCD(char);
void WriteLCD(unsigned char,unsigned char);
void Delay_50us(int Delay);

//**************************************
// M A I N
//**************************************
void main(void)
{
InitLCD();
ClrLCD();
GotoXY(5,1);
WriteStrLCD("Test\0");
while(1);
}

//*********************************************************
// LCD Code
//*********************************************************
/**********************************************************

Name: void ClrLCD(void)

Description: Clear the LCD

Input: none

Output: none

Misc:

**********************************************************/
void ClrLCD()
{
WriteLCD(0,0x01); // Clear display
Delay_50us(50);
}

/**********************************************************

Name: GotoXY(unsigned char x, unsigned char y)

Description: Position cursor on the LCD at X & Y location

Input: X -> X position on the LCD
Y -> Y position on the LCD

Output: none

Misc:

**********************************************************/
void GotoXY(unsigned char x,unsigned char y)
{
unsigned char address;

x--;
if (y > 1) address = 64 + x;
else address = x;
WriteLCD(0,address | 0x80);
}

/**********************************************************

Name: WtireByteLCD(char byte)

Description: Write a byte on the LCD at cursor position

Input: byte

Output: none

Misc:

**********************************************************/
void WriteByteLCD(char byte)
{
char tmp;

tmp = byte & 0xf0;
tmp = tmp >> 4;
tmp += 0x30;
if (tmp > 0x39) tmp += 0x07;
WriteLCD(1,tmp);

tmp = byte & 0x0f;
tmp += 0x30;
if (tmp > 0x39) tmp += 0x07;
WriteLCD(1,tmp);
}

/**********************************************************

Name: void WriteStrLCD(char *ptr)

Description: Write a string from RAM on the LCD

Input: string pointer

Output: none

Misc:

**********************************************************/
void WriteStrLCD(char *ptr)
{
unsigned char i;

for (i=1;i<41;i++)
{
if (*ptr == 0x00) break;
WriteLCD(1,*ptr);
*ptr++ = 0x00;
}
}

/**********************************************************

Name: void WriteStrLCDConst(const char *ptr)

Description: Write a constant string on the LCD

Input: string pointer

Output: none

Misc:

**********************************************************/
void WriteStrLCDConst(const char *ptr)
{
unsigned char i;

for (i=1;i<41;i++)
{
if (*ptr == 0x00) break;
WriteLCD(1,*ptr++);
}
}

/**********************************************************

Name: void WriteLCD(unsigned char rs, unsigned char ch)

Description: Write a byte in rs of the LCD

Input: rs -> Register select
ch -> byte to write

Output: none

Misc:

**********************************************************/
void WriteLCD(unsigned char rs,unsigned char ch)
{
unsigned char Stat;

Stat = LCDPIN & 0x01;

PORTB = Stat;
if ((ch & 0x80) == 0x80) PORTB |= D7;
if ((ch & 0x40) == 0x40) PORTB |= D6;
if ((ch & 0x20) == 0x20) PORTB |= D5;
if ((ch & 0x10) == 0x10) PORTB |= D4;
if (rs == 1) PORTB |= RS;

PORTB |= E;
PORTB &= ~E;

PORTB = Stat;
if ((ch & 0x08) == 0x08) PORTB |= D7;
if ((ch & 0x04) == 0x04) PORTB |= D6;
if ((ch & 0x02) == 0x02) PORTB |= D5;
if ((ch & 0x01) == 0x01) PORTB |= D4;
if (rs == 1) PORTB |= RS;

PORTB |= E;
PORTB &= ~E;

Delay_50us(1);
}

/**********************************************************

Name: void Delay_50us(int Delay)

Description: Delay of 50 us with a 4Mhz resonator

Input: Delay X x 50us

Output: none

Misc:

**********************************************************/
void Delay_50us(int Delay)
{
int i,j;

for (i=0;i<Delay;i++)
{
for (j=1;j<20;j++);
asm("WDR");
}
}

/**********************************************************

Name: void InitLCD(void)

Description: Initialize LCD in 4bit mode

Input: none

Output: none

Misc:

**********************************************************/
void InitLCD(void)
{
LCDDDR = D7 + D6 + D5 + D4 + E + RS + RW;
LCDPORT = !(D7 + D6 + D5 + D4 + E + RS + RW);
Delay_50us(340);

LCDPORT = (D5 + D4); // Function Set 8 bit 3 time
LCDPORT |= E;
LCDPORT &= ~E;
Delay_50us(100);
LCDPORT |= E;
LCDPORT &= ~E;
Delay_50us(100);
LCDPORT |= E;
LCDPORT &= ~E;
Delay_50us(100);

LCDPORT = D5; // Function Set 4 bit
LCDPORT |= E;
LCDPORT &= ~E;
Delay_50us(100);

WriteLCD(0,0x28); // 2 line
WriteLCD(0,0x0c); // Display ON Cursor OFF Blink OFF
WriteLCD(0,0x01); // Clear display
Delay_50us(50);
WriteLCD(0,0x06); // Cursor INC Shift OFF
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…