|
楼主 |
发表于 2015-11-16 10:59:20
|
显示全部楼层
我将与触摸和LCD相关的原理图和程序发上来,请大家帮我一起分析分析,如果资料还不够完善的我将积极配合上传,谢谢。
/***********************************Touch_SPI.c文件*************************************/
/***********************************TouchConf.c文件*************************************/
- #include "GUI.h"
- #include "stddef.h"
- #include "TouchConf.h"
- #ifndef _WINDOWS
- #include "LPC177x_8x.h"
- #include "Touch_spi.h"
- #endif
- /*********************************************************************/
- extern short TP_X[1],TP_Y[1],Pressed_Flag;
- extern short AD_X[1],AD_Y[1];
- // Touch screen
- #define TCS_LOW() (LPC_GPIO0->CLR |= (0x1<<6)) //TOUCH CS P0.6
- #define TCS_HIGH() (LPC_GPIO0->SET |= (0x1<<6))
- #define PEN_State (LPC_GPIO2->PIN&(0x1<<15)) //P2.15
- #define TOUCH_BUSY (LPC_GPIO2->PIN&(0x1<<14))
- /*
- #define TCS_LOW() (LPC_GPIO2->CLR |= (0x1<<23)) //TOUCH CS P2.23
- #define TCS_HIGH() (LPC_GPIO2->SET |= (0x1<<23))
- #define PEN_State (LPC_GPIO0->PIN&(0x1<<16))
- #define TOUCH_BUSY (LPC_GPIO0->PIN&(0x1<<15))
- */
- /*********************************************************************
- a[0]=A a[1]=B a[2]=C a[3]=D a[4]=E a[5]=F a[6]=运算除数
- x[n] y[n] 触摸屏坐标 xfb[n] yfb[n] 显示屏坐标
- *********************************************************************/
- typedef struct {
- int x[5], xfb[5];
- int y[5], yfb[5];
- int a[7]; //int占4个字节
- } calibration;
- calibration cal;
- /*********************************************************************
- *
- * Global functions for GUI touch
- *
- **********************************************************************
- */
- #if GUI_SUPPORT_TOUCH // Used when touch screen support is enabled
- /*********************************************************************
- *
- * Touch_Delay
- *
- *********************************************************************/
- void Touch_Delay(void)
- {
- uint32_t i;
- for(i=0;i<1000;i++);
- }
- /*********************************************************************
- * 函数名:Touch_Init()
- * 参数 :void
- * 返回值:void
- * 描述 :触摸屏初始化
- *********************************************************************/
- void Touch_Init(uint16_t lcd_xsize,uint16_t lcd_ysize)
- {
- /*初始化触摸屏*/
-
- LPC_IOCON->P0_6 &= ~0x07; // P0.6 - TP_CS - used as GPIO
- LPC_GPIO0->DIR |=(0x01<<6);
- LPC_GPIO0->SET |=(0x01<<6);
-
- LPC_IOCON ->P2_15 =0x00; //P2.15 PENIRQ INPUT
- LPC_GPIO2->DIR &=~(0x01<<15);
-
- /*
- LPC_IOCON->P2_23 &= ~0x07; // P2.23 - TP_CS - used as GPIO
- LPC_GPIO2->DIR |=(0x01<<23);
- LPC_GPIO2->SET |=(0x01<<23);
-
- LPC_IOCON ->P0_16 =0x00; //P0.16 PENIRQ INPUT
- LPC_GPIO0->DIR &=~(0x01<<16);
- */
-
- //LPC_GPIOINT->IO2IntEnF|=1<<15; //使能GPIO2的15管脚的下降沿中断
- /*配置GPIO中断的先占优先级为1,从优先级为1*/
- //NVIC_SetPriority(GPIO_IRQn, ((0x01<<3)|0x01));
- /*使能GPIO的中断通道*/
- //NVIC_EnableIRQ(GPIO_IRQn);
-
- SPI_GPIOInit();
- }
- /*********************************************************************
- * Function Name : Touch_ReadAdXY
- * Description : 读取ADS7843/TSC2046 通道X+ 通道Y+的ADC值
- * Input : None
- * Output : None
- * Return : ADS7843/TSC2046 返回 通道X+ 通道Y+的ADC值
- * Attention : None
- *********************************************************************/
- void Touch_ReadAdXY(int *x,int *y)
- {
- int adx=0,ady=0;
-
- adx = SPI_WriteRead(TOUCH_CHX); //读取X坐标指令
- ady = SPI_WriteRead(TOUCH_CHY); //读取Y坐标指令
- *x=adx;
- *y=ady;
- }
- /*********************************************************************
- 函 数 名:unsigned short Softfilter(int (*dat)[13])
- 功 能:数据滤波
- 说 明:无
- 入口参数:(*dat)[13]
- 返 回 值:无
- 设 计:zhou feng 日 期:2012-09-10
- 修 改: 日 期:
- *********************************************************************/
- unsigned short Softfilter(int (*dat)[13])
- {
- unsigned int dbt[3],tmpx =0xFFF;
- signed int m0,m1,m2;
- /******************降序排列************************
- for(m0=0;m0<13;m0++)
- {
- for(m1=0;m1<13;m1++)
- {
- if(dat[0][m1]<dat[0][m1+1])
- {
- m2 = dat[0][m1];
- dat[0][m1] = dat[0][m1+1];
- dat[0][m1+1] = m2;
- }
- }
- }
- *******************升序排列***********************/
- for(m0=0;m0<(13-1);m0++)
- {
- for(m1=m0+1;m1<13;m1++)
- {
- if(dat[0][m0]>dat[0][m1])
- {
- m2 = dat[0][m0];
- dat[0][m0] = dat[0][m1];
- dat[0][m1] = m2;
- }
- }
- }
- /*************************************************/
- dbt[0] = (dat[0][2]+ dat[0][3]+dat[0][4])/3; //取中间9个有效数据,分3组取平均
- dbt[1] = (dat[0][5]+ dat[0][6]+dat[0][7])/3;
- dbt[2] = (dat[0][8]+ dat[0][9]+dat[0][10])/3;
- m0 = dbt[0]-dbt[1];
- m1 = dbt[1]-dbt[2];
- m2 = dbt[2]-dbt[0];
-
- m0 = m0>0?m0:(-m0);
- m1 = m1>0?m1:(-m1);
- m2 = m2>0?m2:(-m2);
- /*************************************************/
- if(m0<THRESHOLD && m1<THRESHOLD && m2<THRESHOLD) //调节数据跳变量门限值
- {
- if(m0<m1)
- {
- if(m2<m0)
- {
- tmpx = (dbt[0]+dbt[2])/2;
- }
- else
- {
- tmpx = (dbt[0]+dbt[1])/2;
- }
- }
- else if(m2<m1)
- {
- tmpx = (dbt[0]+dbt[2])/2;
- }
- else
- {
- tmpx = (dbt[1]+dbt[2])/2;
- }
- }
- else
- {
- tmpx = 0xFFF;
- }
-
- return (unsigned short)tmpx;
- }
- /*********************************************************************
- 函 数 名:Coordinate * Read_ADS7846_Filter(void)
- 功 能:读取触摸数据(带滤波处理)
- 说 明:无
- 入口参数:无
- 返 回 值:无
- 设 计:zhou feng 日 期:2012-09-10
- 修 改: 日 期:
- *********************************************************************/
- Coordinate * Read_ADS7846_Filter(void)
- {
- static Coordinate screen;
- unsigned char t=0,count=0;
- int databuffer[2][13]={{5,7,9,3,2,6,4,0,3,0,0,0,0},{5,7,9,3,2,6,4,0,3,0,0,0,0}};
- do{
- DelayNo(200);
- DelayNo(200);
-
- if(!PEN_State) //触摸按下
- {
- databuffer[0][count] = SPI_WriteRead(TOUCH_CHX); //读取X坐标指令
- databuffer[1][count] = SPI_WriteRead(TOUCH_CHY); //读取Y坐标指令
- count++;
- }
- }while(!PEN_State && count<13);
- screen.x = 0;
- screen.y = 0;
- if(count == 13)
- {
- screen.x = Softfilter(&databuffer[0]); //连续13组X数据滤波处理
- screen.y = Softfilter(&databuffer[1]); //连续13组Y数据滤波处理
- if(screen.x==0xFFF || screen.y==0xFFF) return 0;
- else return &screen;
- }
- return 0; //没有触摸压下
- }
- /*********************************************************************
- *
- * GUI_TOUCH_X_ActivateX()
- *
- * Function decription:
- * Called from GUI, if touch support is enabled.
- * Switches on voltage on X-axis,
- * prepares measurement for Y-axis.
- * Voltage on Y-axis is switched off.
- */
- //void GUI_TOUCH_X_ActivateX(void)
- //{
- //}
- /*********************************************************************
- *
- * GUI_TOUCH_X_ActivateY()
- *
- * Function decription:
- * Called from GUI, if touch support is enabled.
- * Switches on voltage on Y-axis,
- * prepares measurement for X-axis.
- * Voltage on X-axis is switched off.
- */
- //void GUI_TOUCH_X_ActivateY(void)
- //{
- //}
- /*********************************************************************
- *
- * GUI_TOUCH_X_MeasureX()
- *
- * Function decription:
- * Called from GUI, if touch support is enabled.
- * Measures voltage of X-axis.
- */
- //int GUI_TOUCH_X_MeasureX(void)
- //{
- // return 0;//_TouchX;
- //}
- /*********************************************************************
- *
- * GUI_TOUCH_X_MeasureY()
- *
- * Function decription:
- * Called from GUI, if touch support is enabled.
- * Measures voltage of Y-axis.
- */
- //int GUI_TOUCH_X_MeasureY(void)
- //{
- // return 0;//_TouchY;
- //}
- /*********************************************************************
- * 函数名:int perform_calibration(calibration *cal)
- * 参数 :void
- * 返回值:void
- * 描述 :五点触摸校准算法
- *********************************************************************/
- int perform_calibration(calibration *cal)
- {
- int j;
- float n, x, y, x2, y2, xy, z, zx, zy;
- float det, a, b, c, e, f, i;
- float scaling = 65536.0;
- // Get sums for matrix
- n = x = y = x2 = y2 = xy = 0;
- for(j=0;j<5;j++)
- {
- n += 1.0;
- x += (float)cal->x[j];
- y += (float)cal->y[j];
- x2 += (float)(cal->x[j]*cal->x[j]);
- y2 += (float)(cal->y[j]*cal->y[j]);
- xy += (float)(cal->x[j]*cal->y[j]);
- }
- //Get determinant of matrix -- check if determinant is too small
- det = n*(x2*y2 - xy*xy) + x*(xy*y - x*y2) + y*(x*xy - y*x2);
- if(det < 0.1 && det > -0.1)
- {
- //printf("ts_calibrate: determinant is too small -- %f\n\r",det);
- return 0;
- }
- // Get elements of inverse matrix
- a = (x2*y2 - xy*xy)/det;
- b = (xy*y - x*y2)/det;
- c = (x*xy - y*x2)/det;
- e = (n*y2 - y*y)/det;
- f = (x*y - n*xy)/det;
- i = (n*x2 - x*x)/det;
- // Get sums for x calibration
- z = zx = zy = 0;
- for(j=0;j<5;j++)
- {
- z += (float)cal->xfb[j];
- zx += (float)(cal->xfb[j]*cal->x[j]);
- zy += (float)(cal->xfb[j]*cal->y[j]);
- }
- // Now multiply out to get the calibration for framebuffer x coord
- cal->a[2] = (int)((a*z + b*zx + c*zy)*(scaling));
- cal->a[0] = (int)((b*z + e*zx + f*zy)*(scaling));
- cal->a[1] = (int)((c*z + f*zx + i*zy)*(scaling));
- // printf("%f %f %f\n\r",(a*z + b*zx + c*zy),
- // (b*z + e*zx + f*zy),
- // (c*z + f*zx + i*zy));
- // Get sums for y calibration
- z = zx = zy = 0;
- for(j=0;j<5;j++)
- {
- z += (float)cal->yfb[j];
- zx += (float)(cal->yfb[j]*cal->x[j]);
- zy += (float)(cal->yfb[j]*cal->y[j]);
- }
- // Now multiply out to get the calibration for framebuffer y coord
- cal->a[5] = (int)((a*z + b*zx + c*zy)*(scaling));
- cal->a[3] = (int)((b*z + e*zx + f*zy)*(scaling));
- cal->a[4] = (int)((c*z + f*zx + i*zy)*(scaling));
- // printf("%f %f %f\n\r",(a*z + b*zx + c*zy),
- // (b*z + e*zx + f*zy),
- // (c*z + f*zx + i*zy));
- // If we got here, we're OK, so assign scaling to a[6] and return
- cal->a[6] = (int)scaling;
- return 1;
- }
- /********************************************************************/
- typedef struct
- {
- int Min;
- int Max;
- } tMinMax;
- extern tMinMax xyMinMax[2];
- extern int CalibrationComplete;
- int ax_Phys[2],ay_Phys[2];
- /*********************************************************************
- * 函数名:void _ExecCalibration( int x_size, int y_size )
- * 参数 :void
- * 返回值:void
- * 描述 :触摸自校准(五点校准)
- *********************************************************************/
- void _ExecCalibration( int x_size, int y_size ) //x_size=X尺寸 y_size=Y尺寸
- {
- /* calculate log. Positions */
- int ax[5], ay[5];
- Coordinate *p;
-
- ax[0] = 20; ay[0] = 20; //(20,20) 左上
- ax[1] = x_size -20; ay[1] = 20; //(x_size-20,20) 右上
- ax[2] = x_size -20; ay[2] = y_size-20; //(x_size-20,y_size-20) 右下
- ax[3] = 20; ay[3] = y_size-20; //(20,y_size-20) 左下
- ax[4] = x_size/2; ay[4] = y_size/2; //(x_size/2,y_size/2) 中心
- CalibrationComplete = 0; //标志清0
- GUI_TOUCH_SetDefaultCalibration(); //设置默认的校准参数(GUI)
- /*----------------左上------------------------*/
- /* _Calibrate upper left */
- GUI_SetFont(&GUI_Font13_ASCII);
- GUI_SetBkColor(GUI_BLUE);
- GUI_Clear();
- GUI_SetColor(GUI_WHITE); GUI_FillCircle(ax[0], ay[0], 10);
- GUI_SetColor(GUI_BLUE); GUI_FillCircle(ax[0], ay[0], 5);
- GUI_SetColor(GUI_WHITE);
- GUI_DispStringAt("Press here", ax[0]+20, ay[0]);
- do{
- p = Read_ADS7846_Filter(); //触摸屏按下扫描
- if (p!=(void*)0)
- {
- cal.xfb[0] = 20; //LCD坐标
- cal.yfb[0] = 20;
- cal.x[0] = p->x; //TOUCH坐标
- cal.y[0] = p->y;
- break;
- }
- GUI_Delay (10);
- } while (1);
- GUI_SetColor(GUI_RED); GUI_FillCircle(ax[0], ay[0], 5);
- GUI_SetColor(GUI_WHITE);
- while(!PEN_State); /* 等待触摸放开 */
- GUI_Clear();
- GUI_DispStringAt("OK", ax[0]+20, ay[0]);
-
- /*----------------右上------------------------*/
- GUI_Delay (1000);
- GUI_SetBkColor(GUI_BLUE);
- GUI_Clear();
- GUI_SetColor(GUI_WHITE); GUI_FillCircle(ax[1], ay[1], 10);
- GUI_SetColor(GUI_BLUE); GUI_FillCircle(ax[1], ay[1], 5);
- GUI_SetColor(GUI_WHITE);
- GUI_SetTextAlign(GUI_TA_RIGHT); //文本右对齐
- GUI_DispStringAt("Press here", ax[1]-20, ay[1]);
- do {
- p = Read_ADS7846_Filter(); //触摸屏按下扫描
- if (p!=(void*)0)
- {
- cal.xfb[1] = x_size-20;
- cal.yfb[1] = 20;
- cal.x[1] = p->x ;
- cal.y[1] = p->y;
- break;
- }
- GUI_Delay (10);
- } while (1);
- GUI_SetColor(GUI_RED); GUI_FillCircle(ax[1], ay[1], 5);
- GUI_SetColor(GUI_WHITE);
- while(!PEN_State); /* 等待触摸放开 */
- GUI_Clear();
- GUI_DispStringAt("OK", ax[1]-20, ay[1]);
-
- /*----------------右下------------------------*/
- GUI_Delay (1000);
- GUI_Clear();
- GUI_SetColor(GUI_WHITE); GUI_FillCircle(ax[2], ay[2], 10);
- GUI_SetColor(GUI_BLUE); GUI_FillCircle(ax[2], ay[2], 5);
- GUI_SetColor(GUI_WHITE);
- GUI_SetTextAlign(GUI_TA_RIGHT); //文本右对齐
- GUI_DispStringAt("Press here", ax[2]-20, ay[2]);
- do {
- p = Read_ADS7846_Filter(); //触摸屏按下扫描
- if (p!=(void*)0)
- {
- cal.xfb[2] = x_size -20;
- cal.yfb[2] = y_size -20;
- cal.x[2] = p->x;
- cal.y[2] = p->y;
- break;
- }
- GUI_Delay (10);
- } while (1);
- GUI_SetColor(GUI_RED); GUI_FillCircle(ax[2], ay[2], 5);
- GUI_SetColor(GUI_WHITE);
- while(!PEN_State); /* 等待触摸放开 */
- GUI_Clear();
- GUI_DispStringAt("OK", ax[2]-20, ay[2]);
- /*----------------左下------------------------*/
- GUI_Delay (1000);
- GUI_Clear();
- GUI_SetColor(GUI_WHITE); GUI_FillCircle(ax[3], ay[3], 10);
- GUI_SetColor(GUI_BLUE); GUI_FillCircle(ax[3], ay[3], 5);
- GUI_SetColor(GUI_WHITE);
- //GUI_SetTextAlign(GUI_TA_RIGHT);
- GUI_SetTextAlign(GUI_TA_LEFT); //文本左对齐
- GUI_DispStringAt("Press here", ax[3]+20, ay[3]);
- do {
- p = Read_ADS7846_Filter(); //触摸屏按下扫描
- if (p!=(void*)0)
- {
- cal.xfb[3] = 20;
- cal.yfb[3] = y_size -20;
- cal.x[3] = p->x ;
- cal.y[3] = p->y ;
- break;
- }
- GUI_Delay (10);
- } while (1);
- GUI_SetColor(GUI_RED); GUI_FillCircle(ax[3], ay[3], 5);
- GUI_SetColor(GUI_WHITE);
- while(!PEN_State); /* 等待触摸放开 */
- GUI_Clear();
- GUI_DispStringAt("OK", ax[3]+20, ay[3]);
- /*----------------中心------------------------*/
- GUI_Delay (1000);
- GUI_Clear();
- GUI_SetColor(GUI_WHITE); GUI_FillCircle(ax[4], ay[4], 10);
- GUI_SetColor(GUI_BLUE); GUI_FillCircle(ax[4], ay[4], 5);
- GUI_SetColor(GUI_WHITE);
- GUI_SetTextAlign(GUI_TA_LEFT); //文本左对齐
- GUI_DispStringAt("Press here", ax[4]+20, ay[4]);
- do {
- p = Read_ADS7846_Filter(); //触摸屏按下扫描
- if (p!=(void*)0)
- {
- cal.xfb[4] = x_size/2;
- cal.yfb[4] = y_size/2;
- cal.x[4] = p->x ;
- cal.y[4] = p->y ;
- break;
- }
- GUI_Delay (10);
- } while (1);
- GUI_SetColor(GUI_RED); GUI_FillCircle(ax[4], ay[4], 5);
- GUI_SetColor(GUI_WHITE);
- while(!PEN_State); /* 等待触摸放开 */
- GUI_Clear();
- GUI_DispStringAt("OK", ax[4]+20, ay[4]);
- /*-----------------------------------------------------*/
- /* calculate and display values for configuration file */
- /*-----------------------------------------------------*/
- {
- GUI_Delay (1000);
- GUI_Clear();
- GUI_DispString ("x0: "); GUI_DispDec(cal.x[0], 4); //显示(左上)坐标数
- GUI_DispString (" y0: "); GUI_DispDec(cal.y[0], 4); GUI_DispNextLine();
- GUI_DispString ("x1: "); GUI_DispDec(cal.x[1], 4); //显示(右上)坐标数
- GUI_DispString (" y1: "); GUI_DispDec(cal.y[1], 4); GUI_DispNextLine();
- GUI_DispString ("x2: "); GUI_DispDec(cal.x[2], 4); //显示(右下)坐标数
- GUI_DispString (" y2: "); GUI_DispDec(cal.y[2], 4); GUI_DispNextLine();
- GUI_DispString ("x3: "); GUI_DispDec(cal.x[3], 4); //显示(左下)坐标数
- GUI_DispString (" y3: "); GUI_DispDec(cal.y[3], 4); GUI_DispNextLine();
- GUI_DispString ("x4: "); GUI_DispDec(cal.x[4], 4); //显示(中心)坐标数
- GUI_DispString (" y4: "); GUI_DispDec(cal.y[4], 4); GUI_DispNextLine();
-
- GUI_DispString ("Please touch display to continue...");
- /*-------------------------------------*/
- GUI_Delay(1000);
- do {
- p = Read_ADS7846_Filter(); //触摸屏按下扫描
- if (p!=(void*)0)
- break;
- GUI_Delay (10);
- } while (1);
- }
- while(!PEN_State); /* 等待触摸放开 */
- /*-----------------------------------------------------*/
- CalibrationComplete = 1; //标志置1
- perform_calibration(&cal); //触摸校准算法(得到校准参数)
- }
- /*********************************************************************
- * 函数名:short Calibrate_X(unsigned int ad_x,unsigned int ad_y)
- * 参数 :void
- * 返回值:short
- * 描述 :X坐标转化
- *********************************************************************/
- short Calibrate_X(unsigned int ad_x,unsigned int ad_y)
- {
- int temp; //4byte
- short value; //2byte
-
- temp =(int)((ad_x*cal.a[0]+ad_y*cal.a[1]+cal.a[2])/cal.a[6]);
- value =(short)temp;
- return value;
- }
- /*********************************************************************
- * 函数名:short Calibrate_Y(unsigned int ad_x,unsigned int ad_y)
- * 参数 :void
- * 返回值:short
- * 描述 :Y坐标转化
- *********************************************************************/
- short Calibrate_Y(unsigned int ad_x,unsigned int ad_y)
- {
- int temp; //4byte
- short value; //2byte
-
- temp =(int)((ad_x*cal.a[3]+ad_y*cal.a[4]+cal.a[5])/cal.a[6]);
- value =(short)temp;
-
- return value;
- }
- /*********************************************************************
- * 函数名:void TouchTask( int x_size, int y_size )
- * 参数 :void
- * 返回值:void
- * 描述 :触摸屏扫描(10ms)
- *********************************************************************/
- void TouchTask( int x_size, int y_size )
- {
- static uint16_t xOld;
- static uint16_t yOld;
- static uint8_t PressedOld;
- short x=0, y=0, xDiff=0, yDiff=0;
- Coordinate* p;
- p = Read_ADS7846_Filter(); //触摸屏按下扫描
- /*****************触摸按下(有效数据)*************************/
- /*** Touch screen is pressed ***/
- if (p!=(void *)0)
- {
- Pressed_Flag = 1; //触摸按下
- AD_X[0] = p->x; //X坐标AD值
- AD_Y[0] = p->y; //Y坐标AD值
- /*-----------LCD坐标值转换--------------*/
- x = Calibrate_X(p->x ,p->y );// TBD: Insert function which reads current x value
- y = Calibrate_Y(p->x ,p->y );// TBD: Insert function which reads current y value
- /*----------逻辑坐标容错处理------------*/
- if(x<0) x = 0;
- else if(x>x_size) x = x_size;
- if(y<0) y = 0;
- else if(y>y_size) y = y_size;
- /*** The touch has already been pressed ***/
- if(PressedOld == 1) //触摸(上一次)已经按下
- {
- //Calculate difference between new and old position
- xDiff = (x > xOld) ? (x - xOld) : (xOld - x); //计算出前后两次按下的X坐标差值
- yDiff = (y > yOld) ? (y - yOld) : (yOld - y); //计算出前后两次按下的Y坐标差值
- // Store state if new position differs significantly from old position
- if(xDiff + yDiff > 2) //消抖处理
- {
- xOld = x;
- yOld = y;
- TP_X[0] = x;
- TP_Y[0] = y;
- GUI_TOUCH_StoreState(x, y);
- }
- }
- /*** The touch was previously released ***/
- // Store state regardless position
- else //触摸(上一次)未按下
- {
- //if((x != 0) && (y != 0))
- //{
- xOld = x;
- yOld = y;
- TP_X[0] = x;
- TP_Y[0] = y;
- PressedOld = 1;
- GUI_TOUCH_StoreState(x, y);
- //}
- }
- /*** Touch screen is not pressed ***/
- // Store state if it was released recently
- }
- /**********************无触摸按下****************************/
- else if(PEN_State) /* 触摸中断线高电平 */
- {
- Pressed_Flag = 0; //触摸未按下
- if(PressedOld == 1)
- {
- PressedOld = 0;
- GUI_TOUCH_StoreState(-1, -1);
- }
- }
- /*****************触摸按下(无效野点)*************************/
- else
- {
- /* 无效数据,不做处理*/
- }
- /************************************************************/
- //GUI_X_Delay(20);
- }
- /*******************************************************************************************/
- #endif // GUI_SUPPORT_TOUCH
复制代码
/****************************************main.c文件*******************************************/
- /*************************************************************************
- * Function Name: GLCD_Init
- * Parameters: const unsigned long *pPain, const unsigned long * pPallete
- *
- * Return: none
- *
- * Description: GLCD controller init
- *
- *************************************************************************/
- void GLCD_Init (void)
- {
- // Assign pins
- g_pIOCON->P2_9 = 0x06; // VD3, R0 //RGB(565)
- g_pIOCON->P2_6 = 0x07; // VD4, R1
- g_pIOCON->P2_7 = 0x07; // VD5, R2
- g_pIOCON->P4_28 = 0x05; // VD6, R3
- g_pIOCON->P4_29 = 0x05; // VD7, R4
- g_pIOCON->P1_20 = 0x07; // VD10, G0
- g_pIOCON->P1_21 = 0x07; // VD11, G1
- g_pIOCON->P1_22 = 0x07; // VD12, G2
- g_pIOCON->P1_23 = 0x07; // VD13, G3
- g_pIOCON->P1_24 = 0x07; // VD14, G4
- g_pIOCON->P1_25 = 0x07; // VD15, G5
-
- g_pIOCON->P2_13 = 0x07; // VD19, B0
- g_pIOCON->P1_26 = 0x07; // VD20, B1
- g_pIOCON->P1_27 = 0x07; // VD21, B2
- g_pIOCON->P1_28 = 0x07; // VD22, B3
- g_pIOCON->P1_29 = 0x07; // VD23, B4
-
- g_pIOCON->P2_2 = 0x07; // DCLK
- g_pIOCON->P2_0 = 0x07; // DSIP(power)
- g_pIOCON->P2_5 = 0x07; // HSYNC
- g_pIOCON->P2_3 = 0x07; // VSYNC
- g_pIOCON->P2_4 = 0x07; // DataEn(LCD_ENAB_M)
- g_pIOCON->P2_1 = 0x00; // Backlight(P21)
-
- // >>> debug >>>
- // <<< debug <<<
-
- /*Back light enable*/
- LPC_GPIO2->DIR = (1<<1); //P2.1设置为输出
- LPC_GPIO2->SET= (5<<1); //背光高电平(点亮)
- //Turn on LCD clock
- LPC_SC->PCONP |= 1<<0;
-
- // Disable cursor
- g_pLCD->CRSR_CTRL &=~(1<<0);
-
- // disable GLCD controller
- g_pLCD->CTRL = 0; //LCD失能
-
- g_pLCD->CTRL &= ~(0x07 <<1); //LcdBpp 每像素LCD位 000=1bpp
- // RGB565
- g_pLCD->CTRL |= (6<<1); //RGB(565) 110=16bpp
-
- // TFT panel
- g_pLCD->CTRL |= (1<<5); //LcdTFT=1 TFT类型
- // single panel
- g_pLCD->CTRL &= ~(1<<7); //LcdDual=0 LCD单面板
- // notmal output
- g_pLCD->CTRL &= ~(1<<8); //RGB格式
- // little endian byte order
- g_pLCD->CTRL &= ~(1<<9); //小端字节序
- // little endian pix order
- g_pLCD->CTRL &= ~(1<<10);
- // disable power
- g_pLCD->CTRL &= ~(1<<11); //LCD功率失能
- /*-------------------------------------------*/
- /*-------------------------------------------*/
- // init pixel clock
- g_pSC->LCD_CFG = PeripheralClock / ((unsigned long) C_GLCD_PIX_CLK); //LCD刷新率8M左右
- // bypass inrenal clk divider
- g_pLCD->POL |=(1<<26); //旁路像素时钟分频器逻辑
- // clock source for the LCD block is HCLK
- g_pLCD->POL &= ~(1<<5); //LCD时钟源为内部CCLK
- // LCDFP pin is active LOW and inactive HIGH
- g_pLCD->POL |= (1<<11);
- // LCDLP pin is active LOW and inactive HIGH
- g_pLCD->POL |= (1<<12);
- // data is driven out into the LCD on the falling edge
- g_pLCD->POL &= ~(1<<13);
- // active high
- g_pLCD->POL &= ~(1<<14);
- g_pLCD->POL &= ~(0x3FF <<16);
- g_pLCD->POL |= (C_GLCD_H_SIZE-1)<<16; //每线时钟(每行像素PPL=480)
-
- // init Horizontal Timing 水平时序寄存器
- g_pLCD->TIMH = 0; //reset TIMH before set value
- g_pLCD->TIMH |= (C_GLCD_H_BACK_PORCH - 1)<<24; //水平后沿
- g_pLCD->TIMH |= (C_GLCD_H_FRONT_PORCH - 1)<<16; //水平前沿
- g_pLCD->TIMH |= (C_GLCD_H_PULSE - 1)<<8; //水平同步脉冲宽度
- g_pLCD->TIMH |= ((C_GLCD_H_SIZE/16) - 1)<<2; //每行像素
-
- // init Vertical Timing 垂直时序寄存器
- g_pLCD->TIMV = 0; //reset TIMV value before setting
- g_pLCD->TIMV |= (C_GLCD_V_BACK_PORCH)<<24; //垂直后沿
- g_pLCD->TIMV |= (C_GLCD_V_FRONT_PORCH)<<16; //垂直前沿
- g_pLCD->TIMV |= (C_GLCD_V_PULSE - 1)<<10; //垂直同步脉冲宽度
- g_pLCD->TIMV |= C_GLCD_V_SIZE - 1; //每面板线数
- // Frame Base Address doubleword aligned
- g_pLCD->UPBASE = LCD_VRAM_BASE_ADDR & ~7UL ; //上面板帧基址寄存器 (低三位地址屏蔽) 注:UL = unsigned long(确定当前数值类型)
- g_pLCD->LPBASE = LCD_VRAM_BASE_ADDR & ~7UL ; //下面板帧基址寄存器 (低三位地址屏蔽) 注:UL = unsigned long(确定当前数值类型)
- /*-------------------------------------------*/
- /*-------------------------------------------*/
- }
- /*************************************************************************
- * Function Name: GLCD_SetPallet
- * Parameters: const unsigned long * pPallete
- *
- * Return: none
- *
- * Description: GLCD init colour pallete
- *
- *************************************************************************/
- void GLCD_SetPallet (const unsigned long * pPallete)
- {
- unsigned long i;
- unsigned long * pDst = (unsigned long *)g_pLCD->PAL; //彩色调色板寄存器
- // assert(pPallete);
- for (i = 0; i < 128; i++) //128个位置
- {
- *pDst++ = *pPallete++;
- }
- }
- /*************************************************************************
- * Function Name: GLCD_Ctrl
- * Parameters: Bool bEna
- * < Bool = unsigned long >
- * Return: none
- *
- * Description: GLCD enable disabe sequence
- *
- *************************************************************************/
- void GLCD_Ctrl (Bool bEna)
- {
- volatile unsigned long i;
- if (bEna)
- {
- /*LCD_CTRL_bit.LcdEn = 1;*/
- g_pLCD->CTRL |= (1<<0); //LCD使能
- for(i = C_GLCD_PWR_ENA_DIS_DLY; i; i--);
- /*LCD_CTRL_bit.LcdPwr= 1;*/ //enable power
- g_pLCD->CTRL |= (1<<11);
- }
- else
- {
- /*LCD_CTRL_bit.LcdPwr= 0;*/ // disable power
- g_pLCD->CTRL &= ~(1<<11);
- for(i = C_GLCD_PWR_ENA_DIS_DLY; i; i--);
- /*LCD_CTRL_bit.LcdEn = 0;*/
- g_pLCD->CTRL &= ~(1<<0); //LCD失能
- }
- }
- /*****************************************************************************/
- typedef struct POINT
- {
- uint16_t x;
- uint16_t y;
- }Coordinate;
- /*****************************************************************************/
- Coordinate* ptouch;
- GUI_PID_STATE Touch_State;
- int TT_buffer[2][32];
- /******************************************************************************
- ** Main Function main()
- 主频率为84MHz EMC频率为84MHz USB频率为48MHz
- ******************************************************************************/
- int main (void)
- {
- HW_X_Config(); //硬件初始化
- SystemInit(); //系统初始化设置
- SDRAM_Init(); //SDRAM初始化
- GLCD_Init (); //LCD驱动函数
- GLCD_Ctrl (1); //LCD使能 (把这条指令加上后TFT工作,但是触摸读取数据就跳变很厉害了)
- Touch_Init(480,272); //触摸驱动
- while(1)
- {
- ptouch = Read_ADS7846_Filter(); //触摸按键扫描
- if (ptouch!=(void *)0) //触摸按下
- {
- TT_buffer[0][i]=ptouch->x;
- TT_buffer[1][i]=ptouch->y;
- }
- else //无触摸按键
- {
- TT_buffer[0][i]=0;
- TT_buffer[1][i]=0;
- }
- i++; if(i>31) i=0;
- delayMs(0,10);
- }
- }
-
-
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|