出现的问题是:一只手指按下没反应;两只手指按下,只有一只手指是有反应的;
三只手指按下,只有两只手指有反应,这是为何?
代码如下:
[mw_shl_code=c,true]#include "sys.h"
#include "delay.h"
#include "led.h"
#include "usart.h"
#include "lcd.h"
#include "beep.h"
#include "touch.h"
/*
本实验的目的是:
通过触摸屏实现一个手写的功能;
*/
/*
1.现象:
两只手按下时,只有一只手有反应;
三只手按下时,只有两只手有反应;
四只手按下时,只有三只手有反应,为何?
2.加上if()语句的判断,则全然不行,思考为什么?
*/
int main(void){
u32 i;
u16 x ;
u16 y;
u8 buf[16] = {0};
Stm32_Clock_Init(336,8,2,7);//设置时钟,168MHZ
delay_init(168); //初始化延时函数
LED_Init();
uart_init(84-1,115200);
lcd_init();
Touch_Init();
LCD_Reg = 0X2C00;
for(i=0;i<799*479;i++){
LCD_Ram = 0Xffff;
}
while(1){
//在这里采用轮询方式
Read_Reg(0x814e,buf,1);
if(buf[0]&0x80){ //若有数据收到,则获取坐标,然后在LCD上描点;[/mw_shl_code]
[mw_shl_code=c,true]
switch(buf[0]&0xf){
case 1:
Read_Reg(0x8158,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
break;
case 2:
Read_Reg(0x8158,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
Read_Reg(0x8160,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
break;
case 3:
Read_Reg(0x8158,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
Read_Reg(0x8160,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
Read_Reg(0x8158,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
Read_Reg(0x8168,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
break;
case 4:
Read_Reg(0x8158,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
Read_Reg(0x8160,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
Read_Reg(0x8168,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
Read_Reg(0x8170,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
break;
case 5:
Read_Reg(0x8158,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
Read_Reg(0x8160,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
Read_Reg(0x8168,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
Read_Reg(0x8170,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
Read_Reg(0x8178,buf,4);
x = buf[0] | (buf[1]<<8);
y = buf[2] | (buf[3]<<8);
Big_Point_Color(x,y,0xf800);
break;
}
buf[0] &=0x7f ;//清标志;
Write_Reg(0x814e,buf,1);
}
}
}
[/mw_shl_code]
0x8150可以读坐标信息,但是没写;0x8178不能用于读坐标信息,但是它写成可以读,有同感的+1;
一周热门 更多>