缺点:透光性不好,只支持单次单点触摸,容易被划伤
注:手机,平板等一般为电容式。。。。工业用品一般为电阻式
触摸屏+AD转换器--->传递给单片机
单片机的IO口对(I方C)进行控制驱动IC,从而控制触摸屏
主函数部分:
touch.c部分:
touch.h部分:
注:需要tftlcd部分代码和gui部分代码,由于代码过长(2000+行),无法放置,需要的私聊我
以下仅为main.c部分的代码,总代码过长,无法全部放置,需要代码的私聊我
#include "public.h" #include "uart.h" #include "tftlcd.h" #include "touch.h" #include "gui.h" u8 Touch_RST=0; //触摸测试 void TOUCH_Test(void) { static u16 penColor = BLUE; TOUCH_Scan(); if(xpt_xy.sta) { if(xpt_xy.lcdx>tftlcd_data.width) xpt_xy.lcdx=tftlcd_data.width-1; if(xpt_xy.lcdy>tftlcd_data.height) xpt_xy.lcdy=tftlcd_data.height-1; if((xpt_xy.lcdx>=(tftlcd_data.width-3*12))&&(xpt_xy.lcdy<24)) Touch_RST=1; if(xpt_xy.lcdy > tftlcd_data.height - 20) { if(xpt_xy.lcdx>100) { penColor = YELLOW; } else if(xpt_xy.lcdx>80) { penColor = CYAN; } else if(xpt_xy.lcdx>60) { penColor = GREEN; } else if(xpt_xy.lcdx>40) { penColor = MAGENTA; } else if(xpt_xy.lcdx>20) { penColor = RED; } else if(xpt_xy.lcdx>0) { penColor = BLUE; } } else { LCD_Fill(xpt_xy.lcdx-2,xpt_xy.lcdy-2,xpt_xy.lcdx+2,xpt_xy.lcdy+2,penColor); } } } //GUI测试 void GUI_Test(void) { FRONT_COLOR=WHITE; LCD_ShowFontHZ(tftlcd_data.width/2-2*24-12, 0,"普中科技"); LCD_ShowString(tftlcd_data.width/2-7*12,30,tftlcd_data.width,tftlcd_data.height,24,"www.prechin.cn"); LCD_ShowString(tftlcd_data.width/2-7*8,55,tftlcd_data.width,tftlcd_data.height,24,"GUI Test"); FRONT_COLOR=RED; gui_draw_bigpoint(10,55,GREEN); gui_draw_bline(10,80,120,80,10,GREEN); gui_draw_rectangle(10,95,30,30,GREEN); gui_draw_arcrectangle(50,95,30,30,5,1,BLUE,GREEN); gui_fill_rectangle(90,95,30,30,GREEN); //gui_fill_circle(90,120,20,GREEN); gui_fill_ellipse(30,150,20,10,GREEN); //更多的GUI等待大家来发掘和编写 delay_ms(2000); LCD_Clear(BACK_COLOR); } void main() { u16 color=0; UART_Init(); TFTLCD_Init(); Start: //GUI_Test(); FRONT_COLOR=WHITE; LCD_ShowFontHZ(tftlcd_data.width/2-2*24-12, 0,"普中科技"); LCD_ShowString(tftlcd_data.width/2-7*12,30,tftlcd_data.width,tftlcd_data.height,24,"www.prechin.cn"); FRONT_COLOR=RED; LCD_ShowString(tftlcd_data.width-3*12,0,tftlcd_data.width,tftlcd_data.height,24,"RST"); LCD_Fill(0, tftlcd_data.height - 20, 20, tftlcd_data.height, BLUE); LCD_Fill(20, tftlcd_data.height - 20, 40, tftlcd_data.height, RED); LCD_Fill(40, tftlcd_data.height - 20, 60, tftlcd_data.height, MAGENTA); LCD_Fill(60, tftlcd_data.height - 20, 80, tftlcd_data.height, GREEN); LCD_Fill(80, tftlcd_data.height - 20, 100, tftlcd_data.height, CYAN); LCD_Fill(100, tftlcd_data.height - 20, 120, tftlcd_data.height, YELLOW); while(1) { if(Touch_RST) { Touch_RST=0; LCD_Clear(BACK_COLOR); goto Start; } TOUCH_Test(); } }