⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 touch.c

📁 aiji-s3c44b0在iar下的源码
💻 C
字号:
/*
 * $Revision: 1.1 $
 */

// Read touch panel and echo point on LCD screen.

#include "s3c44b0x.h"
#include "main.h"
#include "graphics.h"


#define LCD_X_MAX 320     // or 320 dot (lcd type)
#define LCD_Y_MAX 240     // or 240 dot

#define TOUCH_MAX_X_LIMIT 800   // touch value limit x (at 320-240 dot mode)
#define TOUCH_MAX_Y_LIMIT 500   // touch value limit y

#define LCD_RED   0xe0
#define LCD_GREEN 0x19
#define LCD_BLUE  0x03

// port description
// rPDATE7 = touch_xh(touch0)
// rPDATE6 = touch_xl(touch2)
// rPDATE5 = touch_yh(touch1)
// rPDATE4 = touch_yl(touch3)
// rPDATG3 = Eint3

static void ReadTouchXY(int* touch_x, int* touch_y);


void port_init(void)
{
  rPCONE=(rPCONE & 0x300ff) | 0x0400; //pe5(touch_yh)out, pe467 input
  rPUPE=0xff;
  rPDATE=(rPDATE & 0x0f) | 0x0;       // data low 4,6,7 ( 5= low out )
}


void TouchLCDExample(void)
{
  int OFFSET_X;
  int OFFSET_Y;
  int touch_reso_x;
  int touch_reso_y;
  int X_DIV;
  int Y_DIV;
  int x;
  int y;

  //
  // Calibrate upper left corner, LCD (0,0)
  //
  
  // Mark area to touch.
  Glib_FilledRectangle(5, 5, 15, 15, LCD_RED | LCD_GREEN);

retry_min_point:
  ReadTouchXY(&x, &y);


  // Sanity check of returned touch coordinates.
  if (x < 350 || y < 350 ||
      x > 550 || y > 550)
    goto retry_min_point;

  OFFSET_X=x;
  OFFSET_Y=y;

  // Erase touch calibration area.
  Glib_FilledRectangle(5, 5, 15, 15, 0x00);

  Delay(4000);

  //
  // Calibrate lower right corner, LCD (320,240)
  //

  // Mark area to touch.
  Glib_FilledRectangle(LCD_X_MAX-16, LCD_Y_MAX-16,
                       LCD_X_MAX-6, LCD_Y_MAX-6, LCD_RED | LCD_GREEN);

retry_max_point:                       
  ReadTouchXY(&x, &y);
  // Sanity check of returned touch coordinates.
  if (x > 150 || y > 150 ||
      x < 0 || y < 0)
    goto retry_max_point;
    
  // Erase touch calibration area.
  Glib_FilledRectangle(LCD_X_MAX-16, LCD_Y_MAX-16, LCD_X_MAX-6, LCD_Y_MAX-6, 0x00);

  touch_reso_x=x-OFFSET_X;
  touch_reso_y=y-OFFSET_Y;	

  X_DIV=(LCD_X_MAX*1000)/touch_reso_x;
  Y_DIV=(LCD_Y_MAX*1000)/touch_reso_y;

  Delay(4000);

  //
  //  Read touch coordinates and draw red rectangle at touch point.
  //

  rPCONG=(rPCONG & 0xfffc);  //eint0 input mode
  while(rPDATG & 0x01)
  {
    ReadTouchXY(&x, &y);
    x = ((x-OFFSET_X)*X_DIV)/1000;
    y = ((y-OFFSET_Y)*Y_DIV)/1000;
    // Clip x coordinate
    if (x < 0)
      x = 0;
    if (x >= LCD_X_MAX)
      x = LCD_X_MAX - 1;
    // Clip y coordinate
    if (y < 0)
      y = 0;
    if (y >= LCD_Y_MAX)
      y = LCD_Y_MAX - 1;
    Glib_FilledRectangle(x, y, x+10, y+10, 0xc0);
  }
  rPCONG=0xffff;  //all eint mode 
}


static void ReadTouchXY(int* touch_x, int* touch_y)
{
  int j;
  int temp[16];
  
  port_init();
  Delay(100);
  rPUPG=0xff; 
  rPCONG=(rPCONG & 0xff3f);  //eint3 input mode

  while (rPDATG & 0x8);                // waiting for input 
  Delay(100);

  /* Read A0 (x)*/
  rADCPSR=0xF;
  rPCONE=((rPCONE & 0x300FF) | 0x0500); //PE5,4 OUT, 7,6 INPUT
  rPDATE= 0x20;   // PE5, high, PE4 low
  Delay(100);
  
  for (j=0; j<16; j++) 
  {
    rADCCON= (0x1 | (0x0<<2));        // ADC0 Enable
    while (rADCCON & 0x1) ;
    while(!(rADCCON & 0x40)) ;
    temp[j] = rADCDAT;
  }
  *touch_x = (temp[5] + temp[6] + temp[7] + temp[8] + temp[9]) / 5;

  /* Read A1 */
  rADCPSR= 0xF;
  rPCONE=((rPCONE & 0x300FF) | 0x5000); //PE7,6 OUT,5,4  INPUT
  rPDATE= 0x80;   // PE6, low, PE7 high
  Delay(100);

  for (j=0; j<16; j++)
  {
    rADCCON= 0x1 | (0x1<<2);    /* ADC1 Enable */
    while (rADCCON & 0x1) ;
    while (!(rADCCON & 0x40)) ;
    temp[j] = rADCDAT;
  }
  *touch_y = ( temp[5] + temp[6] + temp[7] + temp[8] + temp[9]) / 5;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -