#include "p_apps.h"
#include "PalmChip.h"

#define LCD_CONTROL_WAIT	660
#define LCD_DATA_WAIT		55	
#define XdataSlow()			CKCON |= 0x06
#define XdataNormal()		CKCON &= 0xf9

#define	_iSleepDivide	16

void SysSleep(ULONG lUSecond)
{
	DLONG l, lSecond;

	lSecond = lUSecond/_iSleepDivide;
	for (l = 0; l < lSecond; l ++)
	{
	}
}

#if defined LCD_HY1602 || defined LCD_HY1604

void write_data_byte(UCHAR ch)
{
	XdataSlow();
	XBYTE[LCD_DATA_OUT] = ch;
	XdataNormal();
	SysSleep(LCD_DATA_WAIT);
}

void write_control_byte(UCHAR ch)
{
	XdataSlow();
	XBYTE[LCD_INST_OUT] = ch;
	XdataNormal();
	SysSleep(LCD_CONTROL_WAIT);
}

#elif defined LCD_GPM227A0	

void write_data_byte(UCHAR ch)
{
	XdataSlow();
	XBYTE[LCD_DATA_OUT] = ch;
	XdataNormal();	
	SysSleep(LCD_DATA_WAIT);

	XdataSlow();	
	XBYTE[LCD_DATA_OUT] = ch << 4;	
	XdataNormal();
	SysSleep(LCD_DATA_WAIT);
}

void write_control_byte(UCHAR ch)
{
	XdataSlow();
	XBYTE[LCD_INST_OUT] = ch;
	XdataNormal();
	SysSleep(LCD_CONTROL_WAIT);

	XdataSlow();
	XBYTE[LCD_INST_OUT] = ch << 4;
	XdataNormal();
	SysSleep(LCD_CONTROL_WAIT);
}

#endif

void BootIndication(UCHAR iPos)
{
	write_control_byte(0xc0+iPos);
	write_data_byte(0xff);
}

