#include <REGX52.H>
#include <Delay.h>
sbit XPT2046_CS = P3 ^ 5;
sbit XPT2046_DCLK = P3 ^ 6;
sbit XPT2046_DIN = P3 ^ 4;
sbit XPT2046_DOUT = P3 ^ 7;
unsigned int XPT2046_read(unsigned char cmd)
{
unsigned int result = 0x00;
unsigned char i;
XPT2046_DCLK = 0;
XPT2046_CS = 0;
for (i = 0; i < 8; i++)
{
XPT2046_DIN = cmd & (0x80 >> i);
XPT2046_DCLK = 1;
XPT2046_DCLK = 0;
}
for (i = 0; i < 16; i++)
{
XPT2046_DCLK = 1;
XPT2046_DCLK = 0;
if (XPT2046_DOUT)
{
result |= (0x8000 >> i);
}
delay(1); //*不加读取数据不正常
}
XPT2046_CS = 1;
if (cmd & 0x08)
{
result >>= 8;
}
else
{
result >>= 4;
}
return result;
}
07-13
07-13
07-13
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交