unsigned char Touch_data_process(unsigned char touch_command) { unsigned int idata temp; I2CWriteByte_noAddrsss(Touch_tsc2003_address,touch_command); temp = I2CReadByte_TK2003(Touch_tsc2003_address); return((temp>>8)&0xff); } unsigned char I2CWriteByte_noAddrsss(unsigned char cDevAddr,unsigned char cData) { /* start condition */ StartCondition(); cDevAddr &= 0xFE; /*Force WRITE address*/ /* send device ID and write data */ if(!Send_Byte(cDevAddr)) { if(!Send_Byte(cData)) { StopCondition(); return(0); /* success */ } } StopCondition(); return(1); } unsigned int I2CReadByte_TK2003(unsigned char cDevAddr) { unsigned int temp; StartCondition(); if(Send_Byte(cDevAddr | 0x01)) return 0; /*Write address*/ temp = Read_Byte(1); temp<<=8; temp |= Read_Byte(1); StopCondition(); return(temp); } #define X_POSITION_COMMAND 0xc6 //8bit ADC #define Y_POSITION_COMMAND 0xd6 //8bit ADC datax = Touch_data_process(X_POSITION_COMMAND); datay = Touch_data_process(Y_POSITION_COMMAND);
|