⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hwdriver.c

📁 手写IC(EPH1100)的80C51驱动软件。
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <string.h>
#include <stdlib.h>
#include "newtypes.h"
#include "globals.h"
#include "display.h"
#include "string.h"
#include "fs.h"
#include "userapi.h"
#include "input.h"
#include "learn.h"
#include "sysdata.h"
#include "ctype.h"
#include "cursor.h"
#include "debug.h"
#include "eph1100.h"

BYTE ReceiveCommannd(void);
BYTE SetHostReady(void);
BYTE SetWakeup(void);
BYTE SetRotateMode(void);
void OpenLCD(void);
void WriteLCDCmd(uint8 val);
void WriteLCDData(uint8 val);
void CloseLCD(void);
#define		RS_H()		sfrLcdA0 = 1	

data bit bWndGetResult,QuickTouch,nRecEnd,LastTime;
extern data BYTE HwType;

static code BYTE CRCTable[]=
{
//	00
#include "crctab.c"	
};

//code BYTE HostWakeup[7] = {0,0,0,0,0,0,0};
code BYTE AckWakeup[8] = {0x50,0x33,0x04,0x00,0x00,0x00,0x00,0x00};

code BYTE SetCharactor[8] = {0x50,0x10,0x04,0xFF,0x01,0xFF,0xFF,0x00};
//code BYTE SetChinse2[8] = {0x50,0x10,0x04,0xFF,0x02,0xFF,0xFF,0x00};
//code BYTE SetCapsLetter[8] = {0x50,0x10,0x04,0xFF,0x04,0xFF,0xFF,0x00};
//code BYTE SetNumber[8] = {0x50,0x10,0x04,0xFF,0x08,0xFF,0xFF,0x00};
//code BYTE Setsymbol[8] = {0x50,0x10,0x04,0xFF,0x10,0xFF,0xFF,0x00};
//code BYTE Setgesture[8] = {0x50,0x10,0x04,0xFF,0x20,0xFF,0xFF,0x00};

code BYTE InkingOn[8] = {0x50,0x14,0x04,0x01,0xFF,0xFF,0xFF,0x00};
//code BYTE InkingOff[7] ={0x50,0x14,0x04,0x00,0xFF,0xFF,0xFF};
code BYTE PenupTime[8] = {0x50,0x1A,0x04,0x03,0xFF,0xFF,0xFF,0x00};		//600ms
//code BYTE AskRecognize[7] ={0x50,0x1B,0x04,0xFF,0xFF,0xFF,0xFF};
code BYTE AckYesRecog[8] = {0x50,0x1B,0x04,0xFF,0xFF,0xFF,0xFF,0x00};
//code BYTE AckNoRecog[7]={0x50,0x1B,0x04,0x00,0x00,0x00,0x00};
code BYTE HostReady[8] = {0x50,0x1c,0x04,0xff,0xff,0xff,0xff,0x00};
//code BYTE SetEvenOn[7] = {0x50,0x1D,0x04,0x01,0xFF,0xFF,0xFF};
code BYTE SetEvenOff[8] = {0x50,0x1D,0x04,0x00,0xFF,0xFF,0xFF,0x00};
code BYTE PenTimeOffset[8]={0x50,0x1E,0x04,0x01,0xFF,0xFF,0xFF,0x00};
code BYTE ComboCodeTab[8] ={0x50,0x41,0x04,0x00,0xFF,0xFF,0xFF,0x00};
code BYTE TradCodeTab[8]={0x50,0x41,0x04,0x01,0xFF,0xFF,0xFF,0x00};
code BYTE SimpleCodeTab[8]={0x50,0x41,0x04,0x02,0xFF,0xFF,0xFF,0x00};
code BYTE SoftReset[8]={0x50,0x42,0x04,0xFF,0xFF,0xFF,0xFF,0x00};
code BYTE InitPowerOn[8]={0x50,0x42,0x04,0x00,0x00,0x00,0x00,0x00};
code BYTE AbortInking[8]={0x50,0x43,0x04,0xFF,0xFF,0xFF,0xFF,0x00};
code BYTE Calibration[8]={0x50,0x44,0x04,0xFF,0xFF,0xFF,0xFF,0x00};
//code BYTE SetTopLeft[7]={0x50,0x44,0x04,0x25,0x36,0xFF,0xFF};
//code BYTE SetBotRight[7]={0x50,0x44,0x04,0xFF,0xFF,0xd7,0xec};
code BYTE WriteArea[8] = {0x50,0x46,0x04,0x00,0x00,0xA0,0xF0,0x00};    //240x160
code BYTE SetRecogMode[8] = {0x50,0x49,0x04,0x00,0xFF,0xFF,0xFF,0x00};
code BYTE SetGraphicMode[8] = {0x50,0x49,0x04,0x01,0xFF,0xFF,0xFF,0x00};
code BYTE IdleTime[8]={0x50,0x4A,0x04,0x01,0x02,0xFF,0xFF,0x00};		//tap wakeup and 15s
code BYTE AckError[8]={0x50,0x00,0x04,0x00,0x00,0x00,0x00,0x00};
//code BYTE RotateMode[7]={0x50,0x4C,0x04,0x30,0xFF,0xFF,0xFF};
#if 1
void ClearHwArea(void)
{
	uint8 x,y;
	
	OpenLCD();
	WriteLCDCmd(0x30);		// EXT =0
	WriteLCDCmd(0x75);
	WriteLCDData(65);
	WriteLCDData(159);
	WriteLCDCmd(0x15);					//column address set
	WriteLCDData(66/3+31);					//start column
	WriteLCDData(66/3+93/3+31-1);	//end column
	WriteLCDCmd(0x5C);		//entry memory write mode	
	RS_H();
	sfrMediaType = MEDIA_NANDFLASH;
	sfrNfTime = LCD_TIME;
	sfrNfMode = 0x01;
	for(y=0;y<93;y++)
	{
		for(x = 0; x < 31 ;x++)
		{
			sfrNfData = 0xf8;
			sfrNfData = 0xf8;
			sfrNfData = 0xf8;
		}	
	}	
	CloseLCD();	
}
#endif
unsigned char GenerateCRC(unsigned char *Packet,int size)
{
	int i;
	unsigned char value;
	value=0;
	for(i=0;i<size-1;i++)
	{
		value ^= Packet[i];
		value = CRCTable[value];
	}
	return value;
}

#if 0
void main(void)
{
	unsigned char Packet[8]; //produce checksum of 8bytes package
	int I;
	for(I=0;I<8;I++)Packet[I]=0;
	Packet[7]=GenerateCRC(Packet,sizeof(Packet)) //checksum place the eighth
}
#endif
#if 0
BYTE ReceiveChar(void)
{
	BYTE ch;
	while(!RI);
	{
		RI = 0;
		ch = SBUF0;
	}	
	return ch;
}
#endif
#if 0
void SendChar(uint8 ch) 
{
	while(!TI);
	{
		TI = 0;
		SBUF0 = ch;
	}
}
#endif
#if 1
void SendCommand(BYTE *buf) 
{
	memcpy(g_eph.TraBuf,buf,8);
	g_eph.TraLen = 0;
	TI = 1;
	while(1)
	{
		if(g_eph.TraLen>=8)
			break;
	}
	g_eph.RecLen = 0;
	g_eph.RecBuf[0] = 0xff;
	QuickTouch = 0;
	LastTime = 0;
	nRecEnd = 1;
}
#endif

BYTE ReceiveCommannd(void) 
{	
	BYTE len=0xff,tm;
	WORD i=0;
	
	tm = g_eph.RecLen;
	while(1)
	{
		if(g_eph.RecBuf[0]==0)
		{
			//SysDeadDelay(4);
			if(g_eph.RecLen==1)
			{	
				//g_eph.RecLen = 0;
				return 1;
			}
			else
			{
				g_eph.RecLen = 0;
				return 0;
			}	
		}	
		if(g_eph.RecLen>=3&&len==0xff)
		{	
			len = g_eph.RecBuf[2];
			if(len>32)
			{
				g_eph.RecLen = 0;
				return 0;
			}		
		}	
		if(g_eph.RecLen == len+4)
		{
//			g_eph.RecLen = 0;
			nRecEnd = 1;
			return 1;
		}	
		if(g_eph.RecLen>32)
		{
				g_eph.RecLen = 0;
				return 0;				
		}
		if(tm == g_eph.RecLen)
		{
			if(LastTime&&i==10)
			{	
				return 0;
			}	
			i++;
			if(i==400)
			{
					g_eph.RecLen = 0;
					return 0;
			}	
		}
		else
		{
				tm = g_eph.RecLen;
				i = 0;
		}		
	}
	return 0;
}

bool CheckReceiveOk(BYTE *buf,BYTE *str)
{
	BYTE i;
	
	for(i=0;i<8;i++)
	{
		if(buf[i]!=str[i])
			return 0;
	}
	return 1;
}

bool WriteAndWait(BYTE *buf,BYTE *ptr)
{
	WORD cyctime = 0,rec;
	
	LastTime = 0;
	while(1)
	{
		SendCommand(buf);
//		SysDeadDelay(8);
		rec=ReceiveCommannd();
		if(rec)
		{
			if(CheckReceiveOk(ptr,g_eph.RecBuf))
			{
//				if(g_eph.RecLen==0)
//					g_eph.RecBuf[0]=0xff;
				SysDeadDelay(10);
				return 1;
			}
		}	
//		if(g_eph.RecLen==0)
//			g_eph.RecBuf[0]=0xff;
		SysDeadDelay(12);
		if(cyctime==5)
			return 0;
		cyctime++;
	}
	
}
#if 0
bool PoweOnEph1100(void)
{
	BYTE buf[8];
	
	ReceiveCommannd();
	memcpy(buf,InitPowerOn,8);
	buf[7]=GenerateCRC(buf,8);
	
	if(CheckReceiveOk(buf,str))
		return 1;
	
	memcpy(buf,SoftReset,8);
	buf[3]=0xff;
	buf[7]=GenerateCRC(buf,8);
	if(CheckReceiveOk(buf,str))
		return 1;
	return 0;
}
#endif
#if 0
BYTE SetSoftReset(void)
{
	BYTE buf[8],ptr[8];

	memcpy(buf,SoftReset,8);
	buf[7]=GenerateCRC(buf,8);
	
	memcpy(ptr,buf,8);
	if(!WriteAndWait(buf,ptr))
		return 0;
	return 1;
}
#endif
BYTE SwitchInking(BYTE mode)
{
	BYTE buf[8],ptr[8];

	memcpy(buf,InkingOn,8);
	buf[3]=mode;
	buf[7]=GenerateCRC(buf,8);
	
	memcpy(ptr,buf,8);
	ptr[3]=0xff;
	ptr[7]=GenerateCRC(ptr,8);
	return WriteAndWait(buf,ptr);
}
BYTE SetPenupTime(BYTE ti)
{
	BYTE buf[8],ptr[8];

	memcpy(buf,PenupTime,8);
	buf[3]=ti;
	buf[7]=GenerateCRC(buf,8);

	memcpy(ptr,buf,7);
	ptr[3]=0xff;
	ptr[7]=GenerateCRC(ptr,8);
	return WriteAndWait(buf,ptr);
}
BYTE SwitchEven(BYTE even)
{
	BYTE buf[8],ptr[8];
	
	memcpy(buf,SetEvenOff,8);
	buf[3]=even;
	buf[7]=GenerateCRC(buf,8);

	memcpy(ptr,buf,7);
	ptr[3]=0xff;
	ptr[7]=GenerateCRC(ptr,8);
	return WriteAndWait(buf,ptr);
}

BYTE SetPenTimeOffset(BYTE offset)
{
	BYTE buf[8],ptr[8];

	memcpy(buf,PenTimeOffset,8);
	buf[3]= offset;
	buf[7]=GenerateCRC(buf,8);

	memcpy(ptr,buf,8);
	ptr[3]=0xff;
	ptr[7]=GenerateCRC(ptr,8);
	return WriteAndWait(buf,ptr);
}

BYTE SetWtiteArea(BYTE left,BYTE top,BYTE right,BYTE bottom)
{
	BYTE buf[8],ptr[8];
	
	memcpy(buf,WriteArea,8);
	buf[3]=left;
	buf[4]=top;
	buf[5]=right;
	buf[6]=bottom;
	buf[7]=GenerateCRC(buf,8);
	memcpy(ptr,buf,8);
	ptr[3]=0xff;
	ptr[4]=0xff;
	ptr[5]=0xff;
	ptr[6]=0xff;
	ptr[7]=GenerateCRC(ptr,8);
	return WriteAndWait(buf,ptr);
/*	if(WriteAndWait(buf,ptr))
	{
		SysDeadDelay(15);
		if(left==top==right==bottom==0)
			SetPenupTime(1);
		else
			SetPenupTime(3);
		return 1;
	}	
	else
		return 0;
*/	
}
BYTE SwitchGraphicMode(BYTE mode)
{
	BYTE buf[8],ptr[8];
	
	memcpy(buf,SetRecogMode,8);
	buf[3]=mode;
	buf[7]=GenerateCRC(buf,8);

	memcpy(ptr,buf,8);
	ptr[3]=0xff;
	ptr[7]=GenerateCRC(ptr,8);
	return WriteAndWait(buf,ptr);
}

BYTE SetIdleTime(BYTE idle)
{
	BYTE buf[8],ptr[8];
	
	memcpy(buf,IdleTime,8);
	buf[4]=idle;
	buf[7]=GenerateCRC(buf,8);

	memcpy(ptr,buf,8);
	ptr[3]=0xff;
	ptr[4]=0xff;
	ptr[7]=GenerateCRC(ptr,8);
	return WriteAndWait(buf,ptr);
}

/*************************************
mode: 01:chinese I
      02:chinese II
      04:capital letter
      08:numeral
      10:symbol
      20:gesture
      40:hiragana
      80:katakana
*************************************/
#if 0
BYTE SwitchRecognMode(BYTE mode)
{
	BYTE buf[8],ptr[8];
	
	memcpy(buf,SetCapsLetter,8);
	buf[4]=mode;
	buf[7]=GenerateCRC(buf,8);

	memcpy(ptr,buf,8);
	ptr[3]=0xff;
	ptr[7]=GenerateCRC(ptr,8);
	return WriteAndWait(buf,ptr);
}
#endif
BYTE SetCharactorMode(BYTE mode,BYTE type)
{
	BYTE buf[8],ptr[8];
	
	memcpy(buf,SetCharactor,8);
	buf[3]=mode;
	buf[4]=type;
	buf[7]=GenerateCRC(buf,8);

	memcpy(ptr,buf,8);
	ptr[3]=0xff;
	ptr[4]=0xff;
	ptr[7]=GenerateCRC(ptr,8);
	return WriteAndWait(buf,ptr);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -