ex18.c

来自「cedn开发板资料VxWorks实验代码 触摸屏实验(需外扩触摸屏)」· C语言 代码 · 共 102 行

C
102
字号
/****************************************************************************/
//
//
// 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 + =
减小字号Ctrl + -
显示快捷键?