/* ---------------------------------------------------------------------
**	file: LCD_driver.h
**	function: header file for alphanumeric LCD driver
** author: Jakub Tiller
** last update: 23.10.2011
** ---------------------------------------------------------------------
*/

#ifndef _LCD_DEF_
#define _LCD_DEF_

#define CLR_BIT(data, bit) (data &= ~(1<<bit))
#define SET_BIT(data, bit) (data |= (1<<bit))

// Constants
#define LCD_PORT	PORTA
#define LCD_DDR	DDRA
#define RS_PIN		1				// pin where RS is connected
#define RW_PIN		2				// pin where RW is connected
#define E_PIN		3				// pin where E is connected
#define LCD_DISP_LENGTH	16		// number of characters in line
#define LCD_LINES		4			// number of lines

#define LCD_DDRAM		7			// bit to allow DDRAM access
#define LCD_CGRAM		6			// bit to allow CGRAM access
#define LCD_START_LINE1	0x00	// address of first character in first line
#define LCD_START_LINE2	0x40	
#define LCD_START_LINE3 0x10
#define LCD_START_LINE4	0x50

#define LCD_RETURN_HOME 1
#define LCD_CTRL			3
#define LCD_E_ON			2
#define LCD_CUR			1
#define LCD_CUR_BLINK	0	

#define PROGRESS_PER_CHAR 6	

typedef unsigned char BYTE;

typedef enum{
	LCD_INSTRUCTION = 0,
	LCD_DATA
} RS;

void lcd_write(BYTE, RS);
void lcd_e_click(void);
void lcd_instruction(BYTE);
void lcd_data(BYTE);
void lcd_clrscr(void);
void lcd_init(void);
void lcd_gotoXY(BYTE, BYTE);
void lcd_char(unsigned char);
void lcd_string(const char *str);
void lcd_copyFromFlash(const BYTE *FlashLoc);
void lcd_home(void);
void lcd_OFF(void);
void lcd_cursorOn(void);
void lcd_cursorBlinkOn(void);
void lcd_cursorOff(void);
void lcd_shiftRight(BYTE n);
void lcd_shiftLeft(BYTE n);
void lcd_curRight(BYTE n);
void lcd_curLeft(BYTE n);
void lcd_definechar(const uint8_t *pc,uint8_t char_code);
void lcd_defaultUserChar(void);
void lcd_progressBar(BYTE progress, BYTE maxprogress, BYTE length);

int LCD_sendStream(char c, FILE *stream);
/*
copy this line to main program file:
static FILE lcd_str = FDEV_SETUP_STREAM(LCD_sendStream, NULL, _FDEV_SETUP_WRITE);

copy this to below the main() statement
stdout = &lcd_str;

you need to include library stdio.h and then you can write anything to LCD by printf()

**** Warning **** 
big amount of program memory
*/




#endif
