const RECTANGLE GtFullZoon1={0,0,239,319,0,0};
void spi_delay(unsigned int i)
{
while(--i);
}
//启动SPI
void StartSpi(void)
{
ADS7843_DCLK=0x00; //DCLK=0
ADS7843_CS=0xFF; //CS=0
ADS7843_DIN=0xFF; //DIN=0
ADS7843_DCLK=0xFF; //DCLK=0
ADS7843_CS=0x00; //CS=0
}
//停止SPI
void StopSpi(void)
{
ADS7843_CS=0xFF; //CS=0
}
//SPI初始化
void SpiInit(void)
{
SysCtlPeriEnable(ADS7843_PERI); //使能GPIOE和F口
GPIOPinTypeOut(ADS7843_DCLK_BASE,ADS7843_DCLK_PIN); //设置DCLK为输出
GPIOPinTypeOut(ADS7843_DIN_BASE,ADS7843_DIN_PIN); //设置DIN为输出
GPIOPinTypeIn(ADS7843_DOUT_BASE,ADS7843_DOUT_PIN); //设置DOUT为输入
GPIOPinTypeOut(ADS7843_CS_BASE,ADS7843_CS_PIN); //设置CS为输出
GPIOPinTypeIn(ADS7843_IRQ_BASE,ADS7843_IRQ_PIN); //设置IRQ为输入
}
//********************************************************************************
void touch_Init(void)
{
ADS7843_CS=0xFF; //CS输出高电平
ADS7843_DCLK=0xFF; //DCLK输出高电平
ADS7843_DIN=0xFF; //DIN输出高电平
}
/*********************************************************************************
******************************************************************************/
//模拟SPI接口 写函数
void MSPI0_WR_Data(unsigned char byte)
{
unsigned char i,data;
data=byte;
//spi_delay(2);
ADS7843_DCLK=0x00; //DCLK=0
for(i=0;i<8;i++)
{
ADS7843_DCLK=0x00; //DCLK=0
if(data&0x80)
ADS7843_DIN=0xFF; //DIN=1
else
ADS7843_DIN=0x00; //DIN=0
//spi_delay(5);
ADS7843_DCLK=0xFF; //DCLK=1
data<<=1;
}
}
//模拟spi接口 读函数
unsigned int spi_read(void)
{
unsigned char i;
unsigned int data=0;
ADS7843_DCLK=0x00; //DCLK=0
//spi_delay(1);
for(i=0;i<12;i++)
{
ADS7843_DCLK=0xFF; //DCLK=1
//spi_delay(1);
data<<=1;
if(GPIOPinRead(ADS7843_DOUT_BASE,ADS7843_DOUT_PIN) ) data++;
ADS7843_DCLK=0x00; //DCLK=0
//spi_delay(2);
}
return(data);
}
//读AD的值(触摸点处的坐标值)
unsigned short ADS7846_Read_XY(unsigned char command)
{
unsigned short XY_DATA = 0x0000;
StartSpi();
MSPI0_WR_Data(command);spi_delay(3);
//spi_delay(5);
ADS7843_DCLK=0xFF;spi_delay(2);//DCLK=1
//spi_delay(4);
ADS7843_DCLK=0x00;spi_delay(2);//DCLK=0
//spi_delay(4);
XY_DATA = (unsigned short)spi_read(); //高八位 SPI接收数据
StopSpi();
return(XY_DATA);
}
//选择相应通道值
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>