TA的每日心情 | 奋斗 2020-5-27 15:41 |
---|
签到天数: 868 天 连续签到: 1 天 [LV.10]以坛为家III
|
本帖最后由 wambob 于 2016-1-2 14:20 编辑
学习GD32f207一段时间了,点亮TFT-LCD后,开始移植触摸屏程序,240X320分辨率的LCD配备了电阻触摸屏,附带的资料中是关于51的代码,通过移植到GD32F207中学习电阻触摸屏。
一:触摸屏简介
本电阻触摸屏为4线触摸屏,控制器芯片使用了XPT2046,和芯片ADS7843是兼容的,内置12-bit ADC和同步串行接口。芯片示意图:
接线图:
其控制字为:
通过写控制字来读取触摸位置装换的数据。时序图:
二:触摸代码移植
触摸代码- #include "touch.h"
- void spistar(void)
- { CS_1;
- DCLK_1;
- DIN_1;
- }
- void WriteCharTo7843(unsigned char data)
- {
- unsigned char count =0;
- for(count=0;count<8;count++)
- {
- if(data&0x80){DIN_1;}
- else{DIN_0;}
- data<<=1;
- DCLK_0;
- DCLK_1;
- }
- }
-
- //**********************************************************
- unsigned int ReadCharFrom7843(void)
- {
- unsigned char count;
- unsigned int data=0;
- for(count=0;count<12;count++)
- {
- data<<=1;
- DCLK_1;
- DCLK_0;
- if(DOUT) (data)++;
- }
- return data;
- }
- void inttostr(int dd,unsigned char *str)
- {
- str[0]=dd/10000+48;
- str[1]=(dd/1000)-((dd/10000)*10)+48;
- str[2]=(dd/100)-((dd/1000)*10)+48;
- str[3]=(dd/10)-((dd/100)*10)+48;
- str[4]=dd-((dd/10)*10)+48;
- str[5]=0;
- }
- unsigned char Makpix(struct pix_ pix1,struct pix_ pix2)
- {
- unsigned char l=0;
- int x=pix1.x>pix2.x?pix1.x-pix2.x:pix2.x-pix1.x;
- int y=pix1.y>pix2.y?pix1.y-pix2.y:pix2.y-pix1.y;
- if(x<14&&y<11) //Èí¼þÂ˲¨£¬
- {
- l=1;
- Tp_pix.x=pix1.x;
- Tp_pix.y=pix1.y;
- }
- return l;
- }
- struct pix_ AD7843(void)
- {
- //delayms(1);
- //spistar(); //??SPI
- //while(BUSY);
- //delayms(1);
- struct pix_ pix;
- CS_0;
- WriteCharTo7843(0x90);
- //while(BUSY);
- //delayms(1);
- DCLK_1;
- DCLK_0;
- pix.y=ReadCharFrom7843();
- WriteCharTo7843(0xD0);
- DCLK_1;
- DCLK_0;
- pix.x=ReadCharFrom7843();
- CS_1;
- return pix;
- }
- unsigned char Getpix(void)
- {
- struct pix_ pix1;
- struct pix_ pix2;
- pix1=AD7843();
- pix2=AD7843();
- return Makpix(pix1,pix2);
- }
复制代码 主程序代码简单添加了检测触摸指示绿灯- int main(void)
- {
- unsigned char ss[6];
- unsigned int lx,ly,num=0;
- spistar();
- GPIO_config();
- SysTick_Configuration();
- LED_ON;
- Lcd_Init();
- Pant();
- showzifustr(0,0,"GD32F207",0xf800,0xffff);
-
- while(1)
- {
-
- if(Penirq==0)
- {
- Delay_1ms(200);
- if(Penirq==0)
- {
- if(Getpix()==1)
- {
- inttostr(Tp_pix.x,ss);
- showzifustr(10,305,"X:",0xf800,0xffff);
- showzifustr(25,305,ss,0xf800,0xffff);
- inttostr(Tp_pix.y,ss);
- showzifustr(185,305,"Y:",0xf800,0xffff);
- showzifustr(200,305,ss,0xf800,0xffff);
- lx=((Tp_pix.x-340)*10/144);
- if(lx>237)
- {
- lx=237;
- }
- ly=320-((Tp_pix.y-320)/11);
- Address_set(lx,ly,lx+5,ly+5);
- Lcd_Write_DATA(0XF800);
- num++;
- if(num%2)
- GPIO_SetBits( GPIOD, GPIO_PIN_12);
- else
- GPIO_ResetBits( GPIOD, GPIO_PIN_12);
- }
- }
- }
- // LCD_Picture1(0,0,239,319);
- // LCD_Picture(0,0,239,315);
- }
- }
复制代码
Template0.rar
(661.58 KB, 下载次数: 57)
|
|