please dont rip this site
/*
 *	LCD interface example
 *	Uses routines from delay.c
 *	This code will interface to a standard LCD controller
 *	like the Hitachi HD44780. It uses it in 4 bit mode, with
 *	the hardware connected as follows (the standard 14 pin 
 *	LCD connector is used):
 *	
 *	PORTB bits 0-3 are connected to the LCD data bits 4-7 (high nibble)
 *	PORTA bit 2 is connected to the LCD RS input (register select)
 *	PORTA bit 3 is connected to the LCD EN bit (enable)
 *	
 *	To use these routines, set up the port I/O (TRISA, TRISB) then
 *	call lcd_init(), then other routines as required.
 *
 * Copywrite Craig Lee 1998
 *	
 */

#include	<pic.h>
#include	"lcd.h"
#include	"delay.h"

#define LCD_RS	RA5	// Register select
#define LCD_EN	RB4	// Enable
#define LCD_D4 RB5	// Data bits
#define LCD_D5 RC5	// Data bits
#define LCD_D6 RC4	// Data bits
#define LCD_D7 RC3	// Data bits

#define	LCD_STROBE	((LCD_EN = 1),(LCD_EN=0))


/* write a byte to the LCD in 4 bit mode */

void
lcd_write(unsigned char c)
{
	if(c & 0x80) LCD_D7=1; else LCD_D7=0;
	if(c & 0x40) LCD_D6=1; else LCD_D6=0;
	if(c & 0x20) LCD_D5=1; else LCD_D5=0;
	if(c & 0x10) LCD_D4=1; else LCD_D4=0;
	LCD_STROBE;
	if(c & 0x08) LCD_D7=1; else LCD_D7=0;
	if(c & 0x04) LCD_D6=1; else LCD_D6=0;
	if(c & 0x02) LCD_D5=1; else LCD_D5=0;
	if(c & 0x01) LCD_D4=1; else LCD_D4=0;
	LCD_STROBE;	
	DelayUs(40);
}

/*
 * 	Clear and home the LCD
 */

void
lcd_clear(void)
{
	LCD_RS = 0;

	lcd_write(0x1);
	DelayMs(2);
}

/* write a string of chars to the LCD */

void
lcd_puts(const char * s)
{
	LCD_RS = 1;	// write characters

	while(*s) lcd_write(*s++);
}

/* write one character to the LCD */

void
lcd_putch(unsigned char c)
{
	LCD_RS = 1;	// write characters

	lcd_write(c);
}


/*
 * Go to the specified position
 */

void
lcd_goto(unsigned char pos)
{
	LCD_RS = 0;

	lcd_write(0x80 + pos);
}
	
/* initialise the LCD - put into 4 bit mode */

void
lcd_init(void)
{
	LCD_RS = 0;	// write control bytes

	DelayMs(15);// power on delay

	LCD_D4 = 1;	// init!	
	LCD_D5 = 1; //
	LCD_STROBE;	
	DelayMs(5);

	LCD_STROBE;	// init!	
	DelayUs(100);

	LCD_STROBE;	// init!	
	DelayMs(5);

	LCD_D4 = 0;	// set 4 bit mode
	LCD_STROBE;	
	DelayUs(40);
	
	lcd_write(0x28);// 4 bit mode, 1/16 duty, 5x8 font, 2lines
	lcd_write(0x0C);// display on
	lcd_write(0x06);// entry mode advance cursor
	lcd_write(0x01);// clear display and reset cursor
}


Questions:

Code:

Comments:


file: /Techref/microchip/language/c/io/lcd/hitachilcd-cl/lcd_c.htm, 23KB, , updated: 2009/11/13 13:19, local time: 2024/12/22 23:15,
TOP NEW HELP FIND: 
18.220.226.147:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://techref.massmind.org/techref/microchip/language/c/io/lcd/hitachilcd-cl/lcd_c.htm"> LCD interface example</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to techref.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .