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

📄 cxa2111.c

📁 可以从计算机向WINBOND516直接下载程序的源码
💻 C
字号:
/**------------------------------------------------------------------------
EEPROM.C

Fireware for XYYQ demo board

Copyright 2000 Xingyuan Instrument and equipment Co.,Ltd
-------------------------------------------------------------------------*/
#include <reg51.h>
#include "demo.h"




//-------------------------------------------------------------------
//	I2C_SendStart(void)
//-------------------------------------------------------------------
void I2C_SendStart2111(void)
{
	SDA_2111 = 1;
	SCL_2111 = 1;   
        ShortDelay(2);
	SDA_2111 = 0;
        ShortDelay(2);
	SCL_2111 = 0;           
}

//-------------------------------------------------------------------
//	I2C_SendStop(void)
//-------------------------------------------------------------------
void I2C_SendStop2111(void)
{       
	SDA_2111 = 0;
	SCL_2111 = 1;   
        ShortDelay(2);
	SDA_2111 = 1;
        ShortDelay(2);
	SCL_2111 = 0;
}
//-------------------------------------------------------------------
//	I2C_SendNACK(void)
//-------------------------------------------------------------------
void I2C_SendNACK2111(void)
{      
    SDA_2111 = 1;
	SCL_2111 = 1;   
        ShortDelay(2);
	SCL_2111 = 0;   
	SDA_2111 = 1;
        ShortDelay(2);        
}
//-------------------------------------------------------------------
//	I2C_SendByteWithStart(BYTE val)
//-------------------------------------------------------------------
bit I2C_SendByteWithStart2111(BYTE val)
{
    bit retVal;

    I2C_SendStart2111();
    retVal = I2C_SendByte2111(val);
    return(retVal);
}
//-------------------------------------------------------------------
//	I2C_GetACK(void)
//-------------------------------------------------------------------
bit I2C_GetACK2111(void)
{
    bit value;

	SDA_2111 = 1;
	SCL_2111 = 1;   
        ShortDelay(5);
    value = SDA_2111;
	SCL_2111 = 0;   
		ShortDelay(2);
                                  
    return (value);
}

//-------------------------------------------------------------------
//	I2C_SendByte(BYTE val)
//-------------------------------------------------------------------
bit I2C_SendByte2111(BYTE val)
{
	BYTE i;
    BYTE temp;	
    
    for(i=0; i<8; i++)
    {
    	temp = val;
        temp >>= 7-i;
        temp &= 0x01;
           
		SDA_2111 = temp;
		SCL_2111 = 1;   
            ShortDelay(2);
		SCL_2111 = 0;   
            ShortDelay(2); 		
    }
    return(I2C_GetACK2111());
}
//-------------------------------------------------------------------------

//------------------------I2C_GET BYTE WITH ADDRESS------------------------

//-------------------------------------------------------------------------
BYTE I2C_GetByteWithAddr(BYTE addr)
{
	BYTE i;
    BYTE temp;

    temp = 0;
	
	I2C_SendByteWithStart2111(WRITE2111);
    I2C_SendByte2111(addr);
    I2C_SendByteWithStart2111(WRITE2111);

	 for(i=0; i<8; i++)
    {
        temp <<= 1;

		SCL_2111 = 1;   
            ShortDelay(2);
		temp |= SDA_2111;
		SCL_2111 = 0;
            ShortDelay(2);
    }
    I2C_SendNACK2111();
	I2C_SendStop2111();
	I2C_ReleaseBus2111();
    return(temp);
}
//-------------------------------------------------------------------------

//-------------------I2C SEND BYTE WITH ADDRESS----------------------------

//-------------------------------------------------------------------------

bit I2C_SendByteWithAddr(BYTE addr,BYTE val)
{
	BYTE i;
    BYTE temp;	
    
	I2C_SendByteWithStart2111(WRITE2111);
    I2C_SendByte2111(addr);
  
    for(i=0; i<8; i++)
    {
    	temp = val;
        temp >>= 7-i;
        temp &= 0x01;
           
		SDA_2111 = temp;
		SCL_2111 = 1;   
            ShortDelay(2);
		SCL_2111 = 0;   
            ShortDelay(2); 		
    }
	I2C_SendStop2111();
	I2C_ReleaseBus2111();
    return(I2C_GetACK2111());
}

//-------------------------------------------------------------------
//	I2C_ReleaseBus(void)
//-------------------------------------------------------------------
void I2C_ReleaseBus2111(void)
{
	SCL_2111 = 1;   
	SDA_2111 = 1;
        
}
//========================================================================
//send control bytes to CXA2111
//========================================================================
void write2111(void)
{
    

	        I2C_SendByteWithAddr(0x00,Userdate.value0.items.ampRgain);
                 I2C_SendByteWithAddr(0x01,Userdate.value0.items.ampGgain);
                I2C_SendByteWithAddr(0x02,Userdate.value0.items.ampBgain);
		I2C_SendByteWithAddr(0x03,Userdate.value0.items.ampRbias);
		I2C_SendByteWithAddr(0x04,Userdate.value0.items.ampGbias);
		I2C_SendByteWithAddr(0x05,Userdate.value0.items.ampBbias);
		I2C_SendByteWithAddr(0x06,Userdate.value0.items.gamR_whp);
		I2C_SendByteWithAddr(0x07,Userdate.value0.items.gamG_whp);
		I2C_SendByteWithAddr(0x08,Userdate.value0.items.gamB_whp);
		I2C_SendByteWithAddr(0x09,Userdate.value0.items.gamR_b1p);
		I2C_SendByteWithAddr(0x0a,Userdate.value0.items.gamG_b1p);
		I2C_SendByteWithAddr(0x0b,Userdate.value0.items.gamB_b1p);
		I2C_SendByteWithAddr(0x0c,Userdate.value0.items.gamR_b2p);
		I2C_SendByteWithAddr(0x0d,Userdate.value0.items.gamG_b2p);
		I2C_SendByteWithAddr(0x0e,Userdate.value0.items.gamB_b2p);
		I2C_SendByteWithAddr(0x0f,Userdate.value0.items.gamR_whg);
		I2C_SendByteWithAddr(0x10,Userdate.value0.items.gamG_whg);
		I2C_SendByteWithAddr(0x11,Userdate.value0.items.gamB_whg);
		I2C_SendByteWithAddr(0x12,Userdate.value0.items.gamR_b1g);
		I2C_SendByteWithAddr(0x13,Userdate.value0.items.gamG_b1g);
		I2C_SendByteWithAddr(0x14,Userdate.value0.items.gamB_b1g);
		I2C_SendByteWithAddr(0x15,(Userdate.value0.items.gamR_b2g | Userdate.value1.items.gamoff | Userdate.value1.items.datest));
		I2C_SendByteWithAddr(0x16,(Userdate.value0.items.gamG_b2g | Userdate.value1.items.pos_cnt2));
		I2C_SendByteWithAddr(0x17,(Userdate.value0.items.gamB_b2g | Userdate.value1.items.pos_cnt1));
		I2C_SendByteWithAddr(0x18,(Userdate.value0.items.dly_cnt | Userdate.value1.items.dir_cnt | Userdate.value1.items.inv_cnt));
}

⌨️ 快捷键说明

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