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

📄 tsc2046.c

📁 LPC1788的USBHOST的FATFS移植
💻 C
字号:
#include "lpc177x_8x_ssp.h"	
#include "lpc177x_8x_pinsel.h"
#include "TSC2046.h"

#define CS_PIN 	(1<<13)

#define _USING_SSP		(LPC_SSP0)

#define FIFOSIZE		8

unsigned char SSP0Send( unsigned char indata );

void touch_cs_low(void);
void touch_cs_high(void);

/********************************************************************/
/*																	*/
/*	TSC2046	Pin connect												*/
/*	MISO:	P2.26													*/
/*	MOSI:	P2.27													*/
/*	SCK:	P2.22													*/
/*	CS:		P1.13													*/
/*	IRQ:	P2.11(EINT1)											*/
/*																	*/
/********************************************************************/

#define CH_X  0xd0//0x90
#define CH_Y  0x90//0xd0
#define CS_PIN 	(1<<13)


unsigned short Touch_Read(unsigned char indata)
{
	unsigned short tp_value;
	touch_cs_low();

	// Write cmd
	tp_value = SSP0Send(indata);

	// Read date
	tp_value = SSP0Send(0);
	tp_value = (unsigned short)(tp_value << 8) +SSP0Send(0);
	touch_cs_high();

	return tp_value;
}

unsigned short Touch_GetPhyX(void)
{
  return (Touch_Read(CH_X)>>3);
}

unsigned short Touch_GetPhyY(void)
{
  return (Touch_Read(CH_Y)>>3);
}

int  Touch_MeasurementX(void)
{	
  int p=0;
  unsigned char i;
  for(i=0;i<4;i++)
  	p += Touch_GetPhyX();
  return ( p>>2 );
}

int  Touch_MeasurementY(void)
{
  int p=0;
  unsigned char i;
  for(i=0;i<4;i++)
  	p += Touch_GetPhyY();
  return ( p>>2 );
}



/**********************************************************************/
void touch_cs_low(void)
{
   LPC_GPIO1->CLR = CS_PIN;
}

/***********************************************************************
 *
 * Function: touch_cs_high
 *
 * Purpose: Chip select High for touch panel
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: None
 *
 **********************************************************************/
void touch_cs_high(void)
{
  LPC_GPIO1->SET = CS_PIN;
}

/*****************************************************************************
** Function name:		SSP0Send
**
** Descriptions:		
**
** parameters:			buffer pointer, and the block length
** Returned value:		None
** 
*****************************************************************************/
unsigned char SSP0Send( unsigned char indata )
{
  while((LPC_SSP0->SR & 0x02) == 0);	// Wait Tx FIFO empty 
  LPC_SSP0->DR = indata;
  while((LPC_SSP0->SR& 0x01) == 0); 	// Send out all data in the FIFO		
  while((LPC_SSP0->SR& 0x04) == 0); 	// Wait for the Rx data
  return LPC_SSP0->DR;
}


void Init_TSC2046(void)
{
	SSP_CFG_Type SSP_ConfigStruct;
	int i,Dummy;

	Dummy = Dummy;

	PINSEL_ConfigPin ( 2, 22, 2);
	PINSEL_ConfigPin ( 2, 26, 2);
	PINSEL_ConfigPin ( 2, 27, 2);
		/* Initializing SSP device section ------------------------------------------------------ */
	// initialize SSP configuration structure to default
	SSP_ConfigStructInit(&SSP_ConfigStruct);

	// Initialize SSP peripheral with parameter given in structure above
	SSP_Init(_USING_SSP, &SSP_ConfigStruct); 
		// Enable SSP peripheral
	SSP_Cmd(_USING_SSP, ENABLE);

	for ( i = 0; i < FIFOSIZE; i++ )
  {
	Dummy = LPC_SSP0->DR;		/* clear the RxFIFO */
  }
}



⌨️ 快捷键说明

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