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

📄 ex18.c

📁 cedn开发板资料VxWorks实验代码 触摸屏实验(需外扩触摸屏)
💻 C
字号:
/****************************************************************************/
//
//
// Created by Starlight Embeded Studio
//         www.cedn.cn
// If there are any concerns on the code
// go to www.cedn.cn for discussion
//
/****************************************************************************/

#include <stdio.h>
#include "44B.H"

void Delay(int time)
{
  static int DelayLoopCount = 500;
  int i,j=0;
  for(j=0;j<time;j++)
  for(i=0;i<DelayLoopCount;i++);  
}

int  GetTouch(void)
{
  return (rPDATG & 0x04);
}

void SetTouchIdle(void)
{
   *(CPLD_REG5) = 0x07;
}

void SetTouchIo(void)
{
   rCLKCON = rCLKCON | (1<<12);

   rPCONG &= 0xFFFFFFCF; 
   rPUPG  |= 0x00000000; 

   SetTouchIdle();

   Delay(100);
}

void SetTouchY(void)
{
   *(CPLD_REG5) = 0x05;
}

void SetTouchX(void)
{
   *(CPLD_REG5) = 0x0A;
}


void TouchADC(unsigned short *x, unsigned short *y) 
{
  int  i;

  if (!GetTouch()) return;

  rADCPSR = 10;	
  SetTouchX();
  Delay(1000);
  {
    rADCCON = 0x1 | (1<<2);
    while(rADCCON & 0x1);
    while(!(rADCCON & 0x40));
    for(i = 0; i < rADCPSR; i++);
    *x = rADCDAT;
  }

  rADCPSR = 10;	
  SetTouchY();
  Delay(1000);
  {
    rADCCON = 0x1|(0<<2);
    while(rADCCON & 0x1);
    while(!(rADCCON & 0x40));
    for(i = 0; i < rADCPSR; i++);
    *y = rADCDAT;
  }

  SetTouchIdle();
  printf("(X,Y)=(%3d,%3d)\n",*x,*y);  
}


void Test18()
{
	  
  unsigned short x1,y1;

  printf("Start Test Touch Screen!\n");
  
  SetTouchIdle();
  
  
  
  while(1) TouchADC(&x1,&y1);  
  return; 
}

⌨️ 快捷键说明

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