📄 tp_test.c
字号:
#define _TP_TEST_C_
#include "reg51.h"
//#include "tp_test.h"
#define uchar unsigned char
#define uint unsigned int
uchar bdata num;
sbit bit7=num^7;
unsigned int TP_X=0,TP_Y=0;
unsigned int LCD_X=0,LCD_Y=0; //coordinate value read from TP
unsigned int ymin=12,ymax=230,xmin=12,xmax=230;
sbit TP_DCLK=P2^0;
sbit TP_CS=P2^1;
sbit TP_DIN=P2^2;
sbit TP_BUSY=P2^3;
sbit TP_DOUT=P2^4;
sbit TP_PENIRQ=P3^2;
void display_rgb(uint dat1,dat2);
void write_command(uchar cdatah,cdatal);
void write_data(uchar ddata_h,ddata_l);
void WCOM(uchar Register, uchar Upper_Code, uchar Lower_Code);
void delay(uint t);
uchar code home[];
uchar code email[];
uchar code book[];
uchar code phone[];
uchar code mp4[];
uchar code flash[];
uchar code camera[];
/////////////////////////////////////
void SPI_Start() //SPI开始
{
TP_DCLK=0;
TP_CS=1;
TP_DIN=1;
TP_DCLK=1;
TP_CS=0;
}
//////////////////////////////////
void TP_write(uchar t)
{
uchar i;
num=t;
for(i=0;i<8;i++)
{
TP_DIN=bit7;
TP_DCLK=0;
TP_DCLK=1; //rising edge
num=num<<1;
}
TP_DCLK=0;
}
uchar TP_read(void)
{
uchar i,tp_data=0;
TP_CS=0;
for(i=0;i<8;i++)
{
tp_data<<=1;
TP_DCLK=1; //falling edge
TP_DCLK=0;
if(TP_DOUT) tp_data++;
}
return(tp_data);
}
void get_TP_X_addr()//give the control byte,the read 5 times and get the average
{
uint i,sum=0;
for(i=0;i<5;i++)
{
TP_CS=0;
TP_write(0xd8+1);//PD0=0,PENIRQ DISABLE
sum+=TP_read();
TP_CS=1; //TP_CS=1;
}
TP_write(0xd8);//PD0=1,PENIRQ ENABLE
TP_X=sum/5+4;//get the average
}
void get_TP_Y_addr()//give the control byte,the read 5 times and get the average
{
uint i,sum=0;
for(i=0;i<5;i++)
{
TP_CS=0;
TP_write(0x98+1);//PD0=0,PENIRQ DISABLE
sum+=TP_read();
TP_CS=1; //TP_CS=1;
}
TP_write(0x98);//PD0=1,PENIRQ ENABLE
TP_Y=sum/5-11;//get the average
}
void write_to_LCD(uint TP_X,TP_Y)
{
uchar LCD_YH;
LCD_X=(TP_X-xmin)*1.1;//240/(xmax-xmin);
//LCD_X=LCD_X+5;
if (LCD_X>240) LCD_X=240;
if (LCD_X<0) LCD_X=0;
LCD_Y=(TP_Y-ymin)*1.468;//320/(ymax-ymin);
//LCD_Y=LCD_Y-13;
if (LCD_Y>320) LCD_Y=320;
if (LCD_Y<0) LCD_Y=0;
LCD_Y=320-LCD_Y;
LCD_YH=(LCD_Y>>8)&&0xff;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -