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

📄 tsc2200_exp.c

📁 ADI系列DSP blackfin BF533 触摸屏 基于亿旗的开发板
💻 C
字号:
#include <ccblkfn.h>
#include <cdefBF533.h>
#include <stdio.h>
#include "tsc2200_exp.h"
#include "sys_res.h"
#include "segled.h"
#include "sys_func.h"
#include "uart.h"
#include "spi.h"


//Read value of a register of TSC2200
unsigned short TSC2200_Read(unsigned short addr)
{
    unsigned short temp;   
    SPI_SEL_LOW;    //Clear SS low
    SPI_send_data(TSC_CMD_READ | addr);
    SPI_RDBR_Clr();		// Clear receiver buffer
    temp = SPI_receive_data();
    SPI_SEL_HIGH;   //Set SS high
    return temp;
}
//Write value to the register of TSC2200
void TSC2200_Write(unsigned short addr,unsigned short data)
{
    SPI_SEL_LOW;   //Clear SS low
    Delay(100);
    SPI_send_data(addr);
    SPI_send_data(data);
    Delay(100);
    SPI_SEL_HIGH;  //Set SS high 
}
//Check if the TSC2200 is exist
bool Detect_TSC2200(void)
{
	TSC2200_Write(TSC_CMD_RESET,RESET_RESET);  //Reset the TSC2200
	Delay(100);
	return (TSC2200_Read(TSC_CMD_ADC) == 0x4000);  //0x4000 is the default value of reg ADC
}
//Initial the TSC2200
void TSC2200_Init(void)
{
	TSC2200_Write(TSC_CMD_RESET,RESET_RESET);  //Reset the TSC2200
	Delay(100);
	TSC2200_Write(TSC_CMD_ADC, 0xC4A2);Delay(100);//Stop ADC convertor
	TSC2200_Write(TSC_CMD_REF, 0x0017);Delay(100);
	TSC2200_Write(TSC_CMD_CFG, 0x000A);Delay(100);
	TSC2200_Write(TSC_CMD_ADC, 0x07FF);Delay(100); // Put TSC to Host and slowest mode
	TSC2200_Write(TSC_CMD_ADC, 0x84A2);Delay(100);	// Setup ADC,TSC control,Read XYZ,12 bit,8 bytes average
}
//Check if data is available
bool TSC2200DataAvailable(void)
{
	return ((TSC2200_Read(TSC_CMD_CFG) & CFG_DAVB) == 0x0000);
}
//Read the X Y coordinates
void TSC2200ReadXY(unsigned short *px,unsigned short *py)
{
	*px = TSC2200_Read(TSC_CMD_X);
	*py = TSC2200_Read(TSC_CMD_Y);
}

void Tsc2200_Exp(void)
{
	unsigned short temp = 0x0000,x,y; //Store the X,Y

	SPI_SELECT_TSC2200; // Set SPI select pin to TSC2200
	
	while(!Detect_TSC2200()) 
	    printf("No TSC2200 exist!\n");
	
	printf("TSC2200 exist!\n");
	
	TSC2200_Init();
	
	while (1)
	{
		if (!(TSC2200_Read(TSC_CMD_CFG) & CFG_DAVB))
		{
		    ledblk();
		    TSC2200ReadXY(&x,&y);
	        printf("X=%d;Y=%d;\n",x,y);
		}
	}
}

⌨️ 快捷键说明

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