/* Useful functions for using a HD44780 character LCD
 * The LCD should be connected through a 74168 8-bit SIPO
 * shift register (or any other SIPO shift register with some modification)
 */

#define LCD_PORT PORTB 	//Port where the shift register is connected
#define SH_DATA 5		//Pin for shift register data
#define SH_CLOCK 3		//Pin for shift register clock
#define RS 5			//Pin for LCD RS
#define EN 4			//Pin for LCD EN

#define LCD_COLS 16
#define LCD_ROWS 2
#define NEXT_STATION 0x10
#define PREV_STATION 0x18
#define LINE1_START 0x00
#define LINE1_END 0x27
#define LINE2_START 0x40
#define LINE2_END 0x67


//Useful LCD commands. Bitwise OR to get the effect you want
#define E_MODE 0x04		//Entry Mode
#define E_MODE_INCDEC 0x02		//Increment/Decrement Cursor
#define E_MODE_SHIFT 0x01		//Display(cursor) Shift
#define D_CNT 0x08		//Display Control
#define D_CNT_POW 0x04			//Display on/off
#define D_CNT_CUR 0x02			//Cursor on/off
#define D_CNT_BLINK 0x01		//Cursor Blink on/off
#define D_SHIFT 0x10		//Display Shift
#define D_SHIFT_CD 0x08			//Shift Cursor/Display
#define D_SHIFT_LR 0x04			//Move Right/Left
#define SET_DDRAM 0x80		//Set DDRAM Address

void init_lcd(void);				//Initialise and clear LCD
void instruction_cmd(char data);	//Send an 'instruction' command (RS = 0)
void data_cmd(char data);			//Send a 'data' command (RS = 1)
void print_string(char * string, char pos);	//Print string to LCD at DDRAM position 'pos'
void print_string_pmem(PGM_P pstring, char pos); //Like pring string, but a string stored in flash
void shift_out(char data);	//Used to shift data onto shift register
void ctos(char * s, char i); //Convert 8-bit number to 4-letter string
