AVR & ATmega

Tach Driver IC(ADC7843) Driver Source File

EP 기술연구소 2016. 7. 12. 12:53

/*****************************************************************
 Project : Touch & Graphic LCD(LG2401283) Board Control Program
 Device : AVR (ATmega32/TQFP44) & Touch Driver IC (ADS7843)
 Version :
 Date    : 2007-10-17 10:59오후
 Author  : JW Park(kornanp@empal.com)
 Company : EPIANICS Co., Ltd (Electronic Utopia)
 Comments:
 
*****************************************************************/
#ifndef  _ADS7843_def_
#define  _ADS7843_def_
/*
#define  TC_DCLK  PORTD.3 // 17 =
#define  TC_CS  PORTD.4  // 18 =
#define  TC_DataIn PORTD.5  // 19 =
#define  TC_BUSY  PIND.6  // 20 =
#define  TC_DataOut PIND.7  // 21 =
*/

#define  ADS_Start (1 << 7) // Start Bit.
#define  ADS_Mode (1 << 3) // 12-Bit/8-Bit Conversion Select Bit( 0=12bit, 1=8bit)
#define  ADS_DFR  (1 << 2)
#define  ADS_PD1  (1 << 1)
#define  ADS_PD0  (1 << 0)
#define  ADS_switch_shift 4

//#if defined(cortexm3)
// Get X position command
//#define CMD_Y_position ((1 << ADS_switch_shift) | ADS_Start | ADS_PD0 | ADS_PD1)
// Get Y position command
//#define CMD_X_position ((5 << ADS_switch_shift) | ADS_Start | ADS_PD0 | ADS_PD1)
//#else
// Get X position command
#define CMD_X_position ((1 << ADS_switch_shift) | ADS_Start)
// Get Y position command
#define CMD_Y_position ((5 << ADS_switch_shift) | ADS_Start)

#endif


#define CMD_ENABLE_PENIRQ  ((1 << ADS_switch_shift) | ADS_Start)

//===============================================================
void ADS_Command(unsigned char cmd)
{
 unsigned char i;
 
 for(i=0;i<8;i++){
  if(cmd & 0x80) TC_DataIn = 1;
  else TC_DataIn = 0;
  
  TC_DCLK = 1;
  cmd <<= 1;
  TC_DCLK = 0;
 }
 TC_DataIn = 0;
}

// Touch data read Routine
unsigned int ADS_DataRead()
{
 unsigned char i;
 unsigned int da;
 
 da = 0xFFF;
 TC_DCLK = 1;
 while(da){
  TC_DCLK = 0;
  if(TC_BUSY == 0) break;
  da--;
 }
 da = 0;
 for(i=0;i<12;i++){
  TC_DCLK = 1;
  da <<= 1;
  if(TC_DataOut) da |= 1;
  else da &= 0xFFFE;
  TC_DCLK = 0;
 }
 
 for(i=0;i<3;i++){
  TC_DCLK = 1;
  TC_DCLK = 1;
  TC_DCLK = 0;
 }
 return da;
}

//===============================================================
void ReadTouchPannel()
{
 unsigned int da;
 
 TC_CS = 0;
 
 ADS_Command(CMD_X_position);
 Touch_buff[x_axis] += ADS_DataRead();
 
 ADS_Command(CMD_Y_position);
 Touch_buff[y_axis] += ADS_DataRead();
 
 TC_CS = 1;
 
 if(++TouchChk_Count >= 16){
  TouchChk_Count = 0;
  da = (Touch_buff[0] / 16);
  if(da != 0xFFF){
   if(Touch_KeyFlag == 1) Touch_CuntinuKflag = 1;
   Touch_KeyFlag = 1;
   Touch_Data[0] = (0x0FFF - da);
   Touch_Data[1] = (Touch_buff[1] / 16);
  }
  else {
   Touch_KeyFlag = 0;
   Touch_CuntinuKflag = 0;
   Touch_Data[0] = 0;
   Touch_Data[1] = 0;
  }
  
  Touch_buff[0] = 0;
  Touch_buff[1] = 0;
 }
  
  
}

//#endif

'AVR & ATmega' 카테고리의 다른 글

AVR-GCC 정리  (0) 2019.11.28
Atmegaxx Micom Interrupt 처리에 따른 주의사항.  (0) 2016.07.25
Atmega32  (0) 2015.02.18
AVR 시리즈의 Fuse 비트 설정  (0) 2015.02.07
AVR Studio Download  (0) 2015.01.29