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

📄 手写板.c

📁 Keil C 编程的手写板
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>
#include "command.h"
#include <absacc.h>
//#include <AT89X51.H>

#define	TPCR	0xC0
#define ADCS	0XC1
#define TPXR	0XC8
#define TPYR	0XC9
#define TPZR	0XCA
#define PRECI_MK1	0X03
#define PRECI_MK2	0XFFe0
#define PREC		16                    //12
#define MASK1		0x01			//之前有无触摸
#define	XTAL		24000000		//MCU振荡频率
#define baudrate	9600			//通信波特率

#define SPD	P3_2
#define SCLK	P3_4
#define	SDIO	P3_3
#define	PS2_DATA	P3_5
#define PS2_CLK		P3_6
#define SM	P3_7
/*-----------------------RS232 输入输出定义 begin--------------------------------*/
#define OLEN	8			//串行发送缓冲区的大小
unsigned char ostart;			//发送缓冲区的起始索引
unsigned char oend;			//发送缓冲区的结束索引
char outbuf[OLEN];			//定义发送缓冲区

#define	ILEN	8			//串行接收缓冲区的大小
unsigned char istart;			//接收缓冲区的起始索引
unsigned char iend;			//接收缓冲区的结束索引
char inbuf[ILEN];			//定义接收缓冲区

bit sendfull;				//标志:标识发送缓冲区满
bit sendactive;				//标志:标识发送器激活
bit SignMouse_flag;			//标志:标识是鼠标模式还是手写签名板模式
						//1:Signature_Pad
						//0:Mouse


/*-----------------------RS232 输入输出定义 end  --------------------------------*/

void Print_Pen_orientation(unsigned char x2,unsigned char y2) small;
void Read_Keypad(unsigned int * x_ptr,unsigned int * y_ptr) small;
//bit Check_Pen_ori(void) small;
unsigned char Read_TP_status(void) small;
void arrive2here(void) small;
//bit Check_Pen_Error(unsigned int i,unsigned int j) small;
void ce(unsigned char,unsigned char) small;
void drawPoint(unsigned int x,unsigned int y) small;
void dispPoint(void) small;
//void loadmsg(unsigned char) small;
void InitRS232(void) small;
unsigned char read_sensor(unsigned char address) small;
//void delay1(unsigned char count) small;
unsigned char read_move(unsigned char *senddata) small;
unsigned char read_button(unsigned char *senddata) small;

void serial(void);

unsigned char read_sensor(unsigned char address);
void delayM(unsigned char count);
unsigned char read_move(unsigned char *senddata);
unsigned char read_button(unsigned char *senddata);



void rs232_mouse(void);

void sensor_init(void);


void loaddefault(void);

void batdelayM(void);
void sensor_reset(void);
//=============================================================================//
unsigned char code Pen_orientation_TAB1[ ]={0x00,0x00,0x40,0x02,0x20,0x04,0x10,0x08,0x09,0x90,0x04,0x20,0x00,0x00,0x08,0x10,0x08,0x10,0x00,0x00,0x04,0x20,0x09,0x90,0x10,0x08,0x20,0x04,0x40,0x02,0x00,0x00};
unsigned char code tError2[ ]={"123456789"};
//unsigned char code SegVal_TAB[ ]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char code SegVal_TAB[ ]={0x03,0x80,0xC0,0x60,0x30,0x18,0x0C,0x06};
//=============================================================================//
unsigned int x0,y0,x_dif,y_dif,x,y;
unsigned char flag;
unsigned char senddata[4]={0, 0, 0, 0};			//24 september 3 o'clk added
unsigned char  lenght=0;
unsigned char  *receive=0;
unsigned int   pdcount=600;
bit enable=0;
void main(void)
{
	
	EA=1;
	P3=0xff;
	delay(50);
	if(SM==1)
	{
		SignMouse_flag=1;
		LCD_Reset();
		LCD_Initial();
		LCD_Clear();
		LCD_CmdWrite(0x00,0xcd);
		GotoXY(0,0);
		PrintStr("你好",30000);
		LCD_Clear();
		//while(Check_Pen_ori());

		InitRS232();
		x0=0x18*4;//0x58;
		y0=0x1e*4;//58;
		x_dif=0xcc*4-x0;//608;//160*3;
		y_dif=0xc2*4-y0;//456;//120*3;
		LCD_Clear();
		LCD_CmdWrite(0x00,0xC5);
		while(1)
		{	
			
			dispPoint();
		}
	}
	else
	{
		/*EA=0;
		SignMouse_flag=0;
		LCD_Reset();
		LCD_Initial();
		LCD_Clear();
		LCD_CmdWrite(0x00,0xcd);
		GotoXY(0,0);
		PrintStr("Mouse",30000);
		LCD_Clear();
		EA=1;
		InitRS232();
		rs232_mouse();*/
		
		
		
		
	}	
}

//=============================================================================//
void Print_Pen_orientation(unsigned char x2,unsigned char y2) small
{
	unsigned char i;
	unsigned char temp1,temp2;
	temp1=x2/8-1;
	temp2=y2-8;
	
	LCD_CmdWrite(0x00,0xC5);	//绘图模式
	//GotoXY(x2/8,y2-8);
	GotoXY(temp1,temp2);
	for(i=1;i<=32;i++)
	{
		LCD_DataWrite(Pen_orientation_TAB1[i-1]);
		i++;
		LCD_DataWrite(Pen_orientation_TAB1[i-1]);
		GotoXY(temp1,temp2+i/2);
	}
}
		

//=============================================================================//
/*bit Check_Pen_ori(void) small
{
	unsigned char tError;
	unsigned int x1,y1,x2,y3,temp1,temp2;
	tError=0;
	LCD_CmdWrite(0x00,0xCD);
	LCD_Clear();
	GotoXY(6,44);				//请轻触目标中心
	PrintStr("请你轻触",1);
	GotoXY(6,64);				//请轻触目标中心
	PrintStr("目标中心",1);
	Print_Pen_orientation(40,40);
	while(!Read_TP_status());
	//arrive2here();
	Read_Keypad(&x1,&y1);
	while(Read_TP_status());		//笔未提起,等待

	LCD_CmdWrite(0x00,0xCD);
	LCD_Clear();
	GotoXY(6,44);				//请轻触目标中心
	PrintStr("请你轻触",1);
	GotoXY(6,64);				//请轻触目标中心
	PrintStr("目标中心",1);
	Print_Pen_orientation(120,40);
	while(!Read_TP_status());
	
	Read_Keypad(&x2,&temp1);
	
	tError|=(Check_Pen_Error(temp1,y1)?0x01:0x00);
	//ce(tError,0x01);
	while(Read_TP_status());		//笔未提起,等待
	LCD_CmdWrite(0x00,0xCD);
	LCD_Clear();

	GotoXY(6,44);				//请轻触目标中心
	PrintStr("请你轻触",1);
	GotoXY(6,64);				//请轻触目标中心
	PrintStr("目标中心",1);
	Print_Pen_orientation(40,120);
	while(!Read_TP_status());
	
	Read_Keypad(&temp1,&y3);
	tError|=(Check_Pen_Error(temp1,x1)?0x02:0x00);
	
	while(Read_TP_status());		//笔未提起,等待	
	//ce(tError,0x02);
	LCD_CmdWrite(0x00,0xCD);
	LCD_Clear();
	
	GotoXY(6,44);				//请轻触目标中心
	PrintStr("请你轻触",1);
	GotoXY(6,64);				//请轻触目标中心
	PrintStr("目标中心",1);
	Print_Pen_orientation(120,120);
	while(!Read_TP_status());
	
	Read_Keypad(&temp1,&temp2);
	tError|=(Check_Pen_Error(temp1,x2)?0x04:0x00);
	//ce(tError,0x04);
	
	tError|=(Check_Pen_Error(temp2,y3)?0x08:0x00);
	//ce(tError,0x08);
	while(Read_TP_status());		//笔未提起,等待
	LCD_Clear();
	//tError=0;
	if(tError==0)
	{
		LCD_CmdWrite(0x00,0xCD);
		GotoXY(8,44);				
		PrintStr("笔尖",1);
		GotoXY(6,64);				
		PrintStr("校对成功",1);
		delay(30000);
		delay(30000);
		x0=x1-(x2-x1)/2;
		y0=y1-(y3-y1)/2;
		x_dif=(x2-x1)*2;
		y_dif=(y3-y1)*2;
		return 0;
	}
	else
	{
		LCD_CmdWrite(0x00,0xCD);
		GotoXY(8,44);				
		PrintStr("笔尖",1);
		GotoXY(6,64);				
		PrintStr("校对失败",1);
		delay(30000);
		return 1;
	}
	
}*/
//=============================================================================//
unsigned char Read_TP_status(void) small
{	
	LCD_CmdWrite(0xC0,0x08);   // Touch Panel Control Register...
  	LCD_CmdWrite(0xC1,0x35);   // ADC Status Register...	
  	delay(100);
  	return  LCD_CmdRead(0xC1) & 0x40; 
}
//=============================================================================//
void arrive2here(void) small
{
	LCD_CmdWrite(0x00,0xCD);
	GotoXY(0,0);
	PrintStr("好了",30000);
	while(1);
}  
//=============================================================================//
void Read_Keypad(unsigned int * x_ptr,unsigned int * y_ptr) small
{
	/*unsigned char temp1;
	LCD_CmdWrite(TPCR,0xCC);
	while(!(LCD_CmdRead(0xc1)&0x80));
	//delay(100);
	*y_ptr=LCD_CmdRead(TPYR);
	*y_ptr=(*y_ptr)<<2;
	temp1=LCD_CmdRead(TPZR);
	*y_ptr+=(temp1&0x30)>>4;	//右移4位
	LCD_CmdWrite(TPCR,0xC3);
	while(!(LCD_CmdRead(0xc1)&0x80));
	//delay(100);
	*x_ptr=LCD_CmdRead(TPXR);
	*x_ptr=(*x_ptr)<<2;
	temp1=LCD_CmdRead(TPZR);
	*x_ptr+=(temp1&0X03);*/
	unsigned char temp1;
	LCD_CmdWrite(TPCR,0xCC);
	delay(10);
	//while(!(LCD_CmdRead(0xc1)&0x80));
	*y_ptr=LCD_CmdRead(TPYR);
	*y_ptr=(*y_ptr)<<2;
	
	temp1=LCD_CmdRead(TPZR);
	*y_ptr+=(temp1&0x30)>>4;	//右移4位
	
	LCD_CmdWrite(TPCR,0xC3);
	delay(10);
	//while(!(LCD_CmdRead(0xc1)&0x80));
	*x_ptr=LCD_CmdRead(TPXR);
	*x_ptr=(*x_ptr)<<2;
	temp1=LCD_CmdRead(TPZR);
	*x_ptr+=temp1&0x03;
}
//=============================================================================//
/*void OpenSignPad(void) small
{
	LCD_CmdWrite(0xC0,0x08);
	LCD_CmdWrite(0xC1,0x3c);
}*/
//=============================================================================//
/*bit Check_Pen_Error(unsigned int i,unsigned int j) small
{
	if(i==j)return 0;
	if(i>j)
	{
		if((i-j)<PREC)
		{
			return 0;
		}
		else
		{
			return 1;
		}
	}
	else
	{
		if((j-i)<PREC)
		{
			return 0;
		}
		else
		{
			return 1;
		}
	}
}*/
//=============================================================================//
/*void ce(unsigned char tError,unsigned char mask) small
{
	if(tError&mask)
	{
		LCD_CmdWrite(0x00,0xCD); 
		GotoXY(6,80);
		PrintStr("E",30000);
	}
}
*/
//=============================================================================//
void drawPoint(unsigned int x,unsigned int y) small
{
	unsigned long x_temp, y_temp;
	unsigned char seg_addr,com,seg_val,i;//k;

	x_temp=x>x0?((x-x0)<x_dif?(x-x0):x_dif):1;
	seg_addr=((x_temp*240)/x_dif-1)/8;
	seg_val=SegVal_TAB[((x_temp*240)/x_dif)%8];
	y_temp=y>y0?((y-y0)<y_dif?(y-y0):y_dif):1;
	com=(y_temp*160)/y_dif-1;

	
	GotoXY(seg_addr,com);
	i=LCD_RamRead();
	LCD_DataWrite(seg_val|i);
	if(com<239)com++;
	GotoXY(seg_addr,com);
	i=LCD_RamRead();
	LCD_DataWrite(seg_val|i);
	
	//============================================================
	/*LCD_CmdWrite(0x00,0xcd);
         GotoXY(6,40);
         PrintStr("seg_addr:",1);
         putHEX2(seg_addr);         // Touch panel Segment "High" Byte data
         PrintStr(".",1);
         putHEX2(k);
       //----------------------------------------------------------------------  
         GotoXY(6,60);
         PrintStr("com:",1);
         putHEX2(com); 
         GotoXY(6,80);
         PrintStr("x:",1);
         putHEX((unsigned int)(x_temp/4));
         GotoXY(6,100);
         PrintStr("y:",1);
         putHEX((unsigned int)(y_temp/4));
         delay(1000);
         LCD_CmdWrite(0x00,0xC5);*/
         //================================================================
}
//=============================================================================//
void dispPoint(void) small
{
	//unsigned char cmd_buf[4]={0,0,0,0};
	//unsigned char i;
	unsigned long temp,temp3;
	unsigned char *ptr1;
	unsigned int temp1,temp2;
	if(Read_TP_status())
	{

⌨️ 快捷键说明

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