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

📄 twowire.c

📁 STC89C58RD +宏芯(driver)驱动TOPPTFT_LCD
💻 C
📖 第 1 页 / 共 2 页
字号:

//    return(cAcknowledge);

}
#endif

void twdWr_Burst_P(void)
{
    StopCondition();
}

//twdWriteTable() is used for burst write for
//any I2C standar device
#if VIDEO_AVAILABLE
#ifdef VIDEO_SAA7114
#define EOT	-1
BOOL twdWriteTable(uCHAR cDevAddr, char *pString)
{
	uCHAR  cReg=0;
  uCHAR  cNum=0;
  while(*pString != EOT)
  {
		cReg = *pString++;
		cNum = *pString++;
    	if(!I2CWriteBytes(cDevAddr, cReg, cNum, pString))
			break;
		else
			pString += cNum;
	}
}
#endif
#endif
//--------------------------------------------------
// Write Multiple Bytes to Device
//--------------------------------------------------


#if  0
BOOL I2CWriteBytes(uCHAR cDevAddr, uCHAR cReg, uCHAR cNum, char *cData)
{
  /* start condition */
	StartCondition();

  /* send device ID and write data */
  if(!Send_Byte(cDevAddr))
  {
  	if(!Send_Byte(cReg))
		{
	   	while(cNum--)
	   	{
				if(Send_Byte(*cData++))  //If false: release line and return
        	{
        		StopCondition();
           	return(0);      /* unsuccess */
				}
 			}
	   	StopCondition();
    		return(1);
  	}
	}
  StopCondition();
  return(0);                  /* fail */
}
#endif
//--------------------------------------------------
// Read Multiple Bytes to Device
//--------------------------------------------------
BOOL I2CReadBytes(uCHAR cDevAddr, uCHAR cReg, uCHAR *pString, uCHAR cNum)
{
	/* write reg offset */
	StartCondition();
  if(Send_Byte(cDevAddr))
		return 0;  // Write address
  if(Send_Byte(cReg))
		return 0;

	/* read data */
  StartCondition();
  if (Send_Byte(cDevAddr | 0x01)) // Read address
		return 0;
	while(cNum)
  {
  	*pString++ = Read_Byte(cNum);
		cNum--;
	}

 	StopCondition();
  return 1;
}


void twdDelay(uWORD wLoops)
{
	uWORD wTemp;

    while (wLoops--) {
	    wTemp = 1000/6;	// one loop below takes about 11 us
        while (wTemp--);
    }
}
void twdDelay1(uWORD wLoops)
{
	uWORD wTemp;

    while (wLoops--) {
	    wTemp = 1000/6;	// one loop below takes about 11 us
        while (wTemp--);
    }
	/*
	I2CWriteByte(TW101,0x32,0x0f);
    while (wLoops){
	   if(I2CReadByte(TW101,0x32)&0x01){
	   	I2CWriteByte(TW101,0x32,0x0f);
      	wLoops--;
	   }
    }*/
}

// OSD config register Write
void OSDCfgWr(uCHAR index,uCHAR dat)
{
 I2CWriteByte(TW101,OSD_CFG_INDEX,index);
 I2CWriteByte(TW101,OSD_CFG_DATA,dat);
}

#ifdef TV
uCHAR TunerReadByte(uCHAR cDevAddr)  //uCHAR cReg)
{
	uCHAR cResult = 0;
    
#ifdef TWO_TW_BUS
  gbTwBusSel=0; 
#endif
   /* read data */
   StartCondition();
   if (Send_Byte(cDevAddr | 0x01)) // Read address
		return 0;
   cResult = Read_Byte(1);

   StopCondition();
   return cResult;
}
//--------------------------------------------------
// Write Byte to Device 
//--------------------------------------------------

#ifdef PAL
#define STEPCODE	0xC8	//Step:50KHz
#endif
#ifdef NTSC
#define STEPCODE	0xCE	//Step:62.5KHz
#endif

uCHAR TunerWriteByte1(uCHAR cDevAddr, uCHAR cDecH, uCHAR cDecL,uCHAR bData, uCHAR cData)
{
    cDevAddr &= 0xFE;   // Force WRITE address
    
    // start condition 
    StartCondition();

    // send device ID and write data 
   if(!Send_Byte(cDevAddr))
   {
		if(!Send_Byte(cDecH))
		{
			if(!Send_Byte(cDecL))
        	{
				if(!Send_Byte(bData))
				{
           		if(!Send_Byte(cData))
            		{
               		StopCondition();
                		return(0);      // success 
					}
            	}
        	}
		}
    }
    StopCondition();
    return(1);                  // fail 
}

uCHAR TunerWriteByte(uCHAR cDevAddr, uCHAR cDecH, uCHAR cDecL, uCHAR cData)
{
    cDevAddr &= 0xFE;   // Force WRITE address
    
    // start condition 
    StartCondition();

    // send device ID and write data 
   if(!Send_Byte(cDevAddr))
   {
		if(!Send_Byte(cDecH))
		{
			if(!Send_Byte(cDecL))
        	{
				if(!Send_Byte(STEPCODE))
				{
           		if(!Send_Byte(cData))
            		{
               		StopCondition();
                		return(0);      // success 
					}
            	}
        	}
		}
    }
    StopCondition();
    return(1);                  // fail 
}
#endif



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sm TP 06/04/10 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
void set_select_scl()
{
	SCL_3W=1;
	//_outp(SCL, 0x04);
}

void clear_select_scl()
{
	SCL_3W=0;
	//_outp(SCL, 0x00);
}

void set_select_sda()
{
//	SCEN_3W=1;
	SDA_3W=1;

}

void clear_select_sda()
{
//	SCEN_3W=0;
	SDA_3W=0;
	
}

void delay(long int a)
{
	int b;
	for (; a>0; a--)
	for(b=0;b<100;b++)  ;
}
/*
void i2c_start()
{
	delay(6);
	set_select_sda();  	delay(6);
	set_select_scl();  delay(6);//SCL = 1; 
	clear_select_sda();	delay(6);
	clear_select_scl();	delay(6);//SCL = 0;
}

void i2c_stop()
{
	delay(6);
	clear_select_sda();
	delay(6);
	set_select_scl();//	SCL = 1;
	delay(6);	
	set_select_sda();
}*/
/*
char read_select_sda()
{
  unsigned char recv_data;
  recv_data=SDA_3W; //_inp(ACK);

 if( (recv_data & 0x40) ==0x40)         //just the 11st pin of DB25  //if high cur-->0
	 return 1;

  return 0;
}*/
/*
unsigned char i2c_1byte_read()
{
	 
	unsigned char rdata=0,i;
	delay(6);

	for(i=0;i<8;i++)
	{
		set_select_scl();//SCL = 1;
		delay(6);
		rdata = rdata << 1;
		if(read_select_sda()==1)             //make sure the input pin  and assign
		  {
		  	rdata|=0x01;
		  }
		clear_select_scl();	//SCL = 0;
		delay(6);
	}
	set_select_sda();
	delay(6);    
	set_select_scl();//SCL = 1;			
	delay(6);
	clear_select_scl();	//SCL = 0;
	delay(6);
	return rdata;
}*/

void i2c_1byte_write(unsigned char wdata)
{
    unsigned char i;
	delay(6);
    
	for(i=0;i<8;i++)
	{
		if((wdata & 0x80)==0) clear_select_sda();
		else     	      set_select_sda();
	
		set_select_scl();//SCL = 1;
		delay(6);
		clear_select_scl();	//SCL = 0;
		delay(6);
		wdata = wdata << 1;
	}

	set_select_sda();	delay(6);    
	set_select_scl();	delay(6);//SCL = 1;			//... ack ?	

	clear_select_scl();		delay(6);//SCL = 0;
}





//use new chip 3 line 
//   ****************************************************
void write_3_1byte(unsigned char addr,unsigned char  wdata)
{
//   Three_Enable=0; 
   SCEN_3W=0;
   write_7bit(addr<<2);
   write_8bit(wdata);
//   Three_Enable=1; 
      SCEN_3W=1;
	clear_select_sda();//SDA = 0;			
	delay(6);
	clear_select_scl();	//SCL = 0;
	delay(6);




}
/*
void read_3_1byte(unsigned char  addr,unsigned char *wdata)
{
//   Three_Enable=0; 
   SCEN_3W=0;
   write_7bit(addr<<2 |0x02);
   read_8bit(wdata);
//   Three_Enable=1;
  SCEN_3W=1;
   clear_select_sda();//SCL = 0;			
   delay(6);
   clear_select_scl();	//SCL = 0;
   delay(6);
}
*/

void write_7bit(unsigned char wdata)
{
	unsigned char i;
	delay(6);
    
    
	for(i=0;i<7;i++)
	{
		if((wdata & 0x80)==0) clear_select_sda();
		else     	      set_select_sda();
	
		delay(2);
		set_select_scl();//SCL = 1;
		delay(6);
		clear_select_scl();	//SCL = 0;
		delay(4);
		wdata = wdata << 1;
	}

	set_select_sda();	delay(6);    
	set_select_scl();	delay(6);//SCL = 1;			//... ack ?	

	clear_select_scl();		delay(6);//SCL = 0;


}

void write_8bit(unsigned char wdata)
{
	unsigned char i;
	delay(6);
    
	for(i=0;i<8;i++)
	{
		if((wdata & 0x80)==0) clear_select_sda();
		else     	      set_select_sda();
	
		delay(2);
		set_select_scl();//SCL = 1;
		delay(6);
		clear_select_scl();	//SCL = 0;
		delay(4);
		wdata = wdata << 1;
	}


}

/*
void read_8bit(unsigned char *wdata)
{
	 
	unsigned char rdata=0,i;
	delay(6);

	for(i=0;i<8;i++)
	{
		set_select_scl();//SCL = 1;
		delay(6);
		rdata = rdata << 1;
		if(read_select_sda()==1)             //make sure the input pin  and assign
		  {
		  	rdata|=0x01;
		  }
		clear_select_scl();	//SCL = 0;
		delay(6);
	}
	*wdata=rdata;
}
*/

⌨️ 快捷键说明

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