/*
 * Library for LCD display and AVR microcontrollers
 * Author: Peter Fleury (http://homepage.hispeed.ch/peterfleury/)
 * Modified by: Tomas Fryza (fryza@feec.vutbr.cz)
 *              Thomas Breining (breinint@esiee.fr)
 */
#ifndef _LCD_H
#define _LCD_H 1


#define LCD_PORT		PORTA		// MCU port for LCD
#define LCD_RS_PIN		1			// RS control input of LCD
#define LCD_RW_PIN		2			// R/W control input of LCD
#define LCD_E_PIN		3			// enable control input of LCD
#define LCD_DISP_LENGTH	16			// lenght of one LCD line

#define LCD_DDRAM		7
#define LCD_START_LINE1	0x00		// address of first line beginning
#define LCD_START_LINE2	0x40		// address of second line beginning
#define LCD_START_LINE3 0x10		// address of third line beginning
#define LCD_START_LINE4	0x50		// address of fourth line beginning

#define DDR( x )		( *(&x - 1) )	// address of data direction register
#define lcd_rw_high()	LCD_PORT |=  _BV( LCD_RW_PIN )
#define lcd_rw_low()	LCD_PORT &= ~_BV( LCD_RW_PIN )
#define lcd_e_delay()	__asm__ __volatile__( "nop\n nop\n nop" )
#define lcd_e_high()	LCD_PORT  |=  _BV( LCD_E_PIN )
#define lcd_e_low()		LCD_PORT  &= ~_BV( LCD_E_PIN )
#define lcd_e_toggle()	toggle_e()
#define lcd_rs_high()	LCD_PORT |=  _BV( LCD_RS_PIN )
#define lcd_rs_low()	LCD_PORT &= ~_BV( LCD_RS_PIN )


void lcd_init( void ) ;				// initialization of LCD display
void lcd_clrscr( void ) ;			// clear LCD screen
void lcd_command( char ) ;			// send 1-byte instruction to LCD
void lcd_data( char ) ;				// send 1-byte data to LCD
void lcd_write( char, char ) ;		// send instruction or data to LCD
void toggle_e( void ) ;				// generate enable pulse
void lcd_gotoxy( char, char ) ;		// move cursor to new position
void lcd_putc( char c ) ;			// put char to LCD
void lcd_puts( const char *s ) ;	// put string (char succession) to LCD
void lcd_newline( void ) ;			// move cursor to next line
void lcd_firstline( void ) ;		// move cursor to first line
void lcd_secondline( void ) ;		// move cursor to second line
void lcd_thirdline( void ) ;		// move cursor to third line
void lcd_fourthline( void ) ;		// move cursor to fourth line


#endif

