-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtouch.h
50 lines (38 loc) · 961 Bytes
/
touch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef __TOUCH_H
#define __TOUCH_H
//---包含头文件---//
#include<reg52.h>
#include<intrins.h>
//---重定义关键词---//
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef uint
#define uint unsigned int
#endif
//---定义数据类型---//
//12位的电压值
typedef struct
{
uint x;
uint y;
} XPT_XY;
extern XPT_XY xpt_xy;
//---定义芯片命令字节---//
#define XPT_CMD_X 0xD0 //读取X轴的命令
#define XPT_CMD_Y 0x90 //读取Y轴的命令
//---定义使用的IO口---//
sbit TOUCH_DOUT = P2^0; //输出
sbit TOUCH_CLK = P2^1; //时钟
sbit TOUCH_DIN = P2^2; //输入
sbit TOUCH_CS = P2^3; //片选
sbit TOUCH_PEN = P2^4; //检测触摸屏响应信号
//---声明全局函数---//
void TOUCH_SPI_Start(void); //起始
void TOUCH_SPI_Write(uchar dat); //写
uint TOUCH_SPI_Read(void); //读
uint TOUCH_XPT_ReadData(uchar cmd); //读电压数据
//读x,y值,不是存储在返回值里,返回值存储的是0,1
//x,y的值存储在全局变量里面,数据类型为uint型
uchar TOUCH_XPT_ReadXY(void);
#endif