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

📄 eeprom.c

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

Fireware for XYYQ demo board

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

//-------------------------------------------------------------------
//	ShortDelay(BYTE count)
//-------------------------------------------------------------------
void ShortDelay(BYTE count)
{   
    while(count){
            count--;
    }
}

//-------------------------------------------------------------------
//	I2C_SendStart(void)
//-------------------------------------------------------------------
void I2C_SendStart(void)
{
	I2C_SDA = 1;
	I2C_SCL = 1;   
        ShortDelay(2);
	I2C_SDA = 0;
        ShortDelay(2);
	I2C_SCL = 0;           
}

//-------------------------------------------------------------------
//	I2C_SendStop(void)
//-------------------------------------------------------------------
void I2C_SendStop(void)
{       
	I2C_SDA = 0;
	I2C_SCL = 1;   
        ShortDelay(2);
	I2C_SDA = 1;
        ShortDelay(2);
	I2C_SCL = 0;
}

//-------------------------------------------------------------------
//	I2C_SendACK(void)
//-------------------------------------------------------------------
void I2C_SendACK(void)
{       
	I2C_SDA = 0;
	I2C_SCL = 1;   
        ShortDelay(2);
	I2C_SCL = 0;   
	I2C_SDA = 1;
        ShortDelay(2);	
}

//-------------------------------------------------------------------
//	I2C_SendNACK(void)
//-------------------------------------------------------------------
void I2C_SendNACK(void)
{      
	I2C_SDA = 1;
	I2C_SCL = 1;   
        ShortDelay(2);
	I2C_SCL = 0;   
	I2C_SDA = 1;
        ShortDelay(2);        
}

//-------------------------------------------------------------------
//	I2C_GetACK(void)
//-------------------------------------------------------------------
bit I2C_GetACK(void)
{
    bit value;

	I2C_SDA = 1;
	I2C_SCL = 1;   
        ShortDelay(5);
    value = I2C_SDA;
	I2C_SCL = 0;   
		ShortDelay(2);
                                  
    return (value);
}
//-------------------------------------------------------------------
//	I2C_SendByteWithStart(BYTE val)
//-------------------------------------------------------------------
bit I2C_SendByteWithStart(BYTE val)
{
    bit retVal;

    I2C_SendStart();
    retVal = I2C_SendByte(val);
    return(retVal);
}
//-------------------------------------------------------------------
//	I2C_SendByte(BYTE val)
//-------------------------------------------------------------------
bit I2C_SendByte(BYTE val)
{
	BYTE i;
    BYTE temp;	
    
    for(i=0; i<8; i++)
    {
    	temp = val;
        temp >>= 7-i;
        temp &= 0x01;
           
		I2C_SDA = temp;
		I2C_SCL = 1;   
            ShortDelay(2);
		I2C_SCL = 0;   
            ShortDelay(2); 		
    }
    return(I2C_GetACK());
}
//-------------------------------------------------------------------
//	I2C_GetByte(void)
//-------------------------------------------------------------------
BYTE I2C_GetByte(void)
{
    BYTE i;
    BYTE temp;

    temp = 0;

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

		I2C_SCL = 1;   
            ShortDelay(2);
		temp |= I2C_SDA;
		I2C_SCL = 0;
            ShortDelay(2);
    }
    I2C_SendACK();
    return(temp);
}
//-------------------------------------------------------------------
//	I2C_ReleaseBus(void)
//-------------------------------------------------------------------
void I2C_ReleaseBus(void)
{
	I2C_SCL = 1;   
	I2C_SDA = 1;
        
}
//-------------------------------------------------------------------
//	I2C_GetLastByte(void)
//-------------------------------------------------------------------
BYTE I2C_GetLastByte(void)
{
    BYTE i;
    BYTE temp;

    temp = 0;

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

		I2C_SCL = 1;   
            ShortDelay(2);
		temp |= I2C_SDA;
		I2C_SCL = 0;
            ShortDelay(2);
	}
    I2C_SendNACK();
    return(temp);
}

 
//---------------------SET DEFAULT DATE------------------------------------

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

void SetDefaultData0(void)
{
    Userdate.value0.items.ampRgain = 255; 
    Userdate.value0.items.ampGgain = 255;
    Userdate.value0.items.ampBgain = 255;
    Userdate.value0.items.ampRbias = 0;
    Userdate.value0.items.ampGbias = 16;
    Userdate.value0.items.ampBbias = 0;
    Userdate.value0.items.gamR_whp = 156;
    Userdate.value0.items.gamG_whp = 156;
    Userdate.value0.items.gamB_whp = 156;
    Userdate.value0.items.gamR_b1p = 48;
    Userdate.value0.items.gamG_b1p = 48;
    Userdate.value0.items.gamB_b1p = 48;
    Userdate.value0.items.gamR_b2p = 84;
    Userdate.value0.items.gamG_b2p = 84;
    Userdate.value0.items.gamB_b2p = 84;
    Userdate.value0.items.gamR_whg = 0;
    Userdate.value0.items.gamG_whg = 0;
    Userdate.value0.items.gamB_whg = 0;
    Userdate.value0.items.gamR_b1g = 252;
    Userdate.value0.items.gamG_b1g = 252;
    Userdate.value0.items.gamB_b1g = 252;
    Userdate.value0.items.gamR_b2g = 252;
    Userdate.value0.items.gamG_b2g = 252;
    Userdate.value0.items.gamB_b2g = 252;
    Userdate.value0.items.dly_cnt =  0;	

		Userdate.value0.items.a1 = '1';
	Userdate.value0.items.a2 = '1';
	Userdate.value0.items.a3 = '1';
	Userdate.value0.items.a4 = '1';
	Userdate.value0.items.a5 = '1';
	Userdate.value0.items.a6 = '1';
	Userdate.value0.items.a7 = '1';
			
}
//-------------------------------------------------------------------------
                                                                
//----------------SET DEFAULT DATE1----------------------------------------
                                                                       
//-------------------------------------------------------------------------
void SetDefaultData1(void)
{
	Userdate.value1.items.gamoff = 0;                                     
	Userdate.value1.items.datest = 0;
	Userdate.value1.items.pos_cnt2 = 0;
	Userdate.value1.items.pos_cnt1 = 0;
	Userdate.value1.items.dir_cnt= 0;
	Userdate.value1.items.inv_cnt = 0;
	Userdate.value1.items.b6 = 222;
	Userdate.value1.items.b7 = 222;

}
//-------------------------------------------------------------------------

//------------------SET DATAULT DATE2--------------------------------------

//-------------------------------------------------------------------------
void SetDefaultData2(void)
{
		Userdate.value2.items.mirror = 1;
	Userdate.value2.items.flip = 0;
	Userdate.value2.items.minute = 0;
	Userdate.value2.items.hour = 0;
	Userdate.value2.items.c5 = 111;
	Userdate.value2.items.c6 = 111;
	Userdate.value2.items.c7 = 111;
	
}
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
void SetDefaultData3(void)
{
	
    Userdate.value3.items.m393_dlcyr = 0 ;
	Userdate.value3.items.m393_dlcyb = 0;
}
   ///////////////////////////new add 3500 and 3500 reg////////////
void SetDefaultData4(void)
{
        
       Userdate.value4.items.mode = 0;
	Userdate.value4.items.moveRightorLeft = 0x50;
	Userdate.value4.items.moveUporDown = 0x23;
       	Userdate.value4.items.m_address9 = 0xcc;
	Userdate.value4.items.m_ttlpolreg = 0x73;

	Userdate.value4.items.m_select_rgb = 255;
	Userdate.value4.items.m_pow = 0;
	
	
}
//-------------------------------------------------------------------------

//-------------------LOAD EEPROM-------------------------------------------

//-------------------------------------------------------------------------
void LoadEEPROM0(void)
{
        BYTE i;
        

        //value0
        I2C_SendByteWithStart(EEPROMWRITEID);
        I2C_SendByte(0);
        I2C_SendByteWithStart(EEPROMREADID);
	    for(i=0; i<7; i++){		
            Userdate.value0.bytes[i] = I2C_GetByte();
        }
        Userdate.value0.bytes[7] = I2C_GetLastByte();
        I2C_SendStop();
        I2C_ReleaseBus();
        ShortDelay(100);

        I2C_SendByteWithStart(EEPROMWRITEID);
        I2C_SendByte(8);
        I2C_SendByteWithStart(EEPROMREADID);
	    for(i=8; i<15; i++){		
            Userdate.value0.bytes[i] = I2C_GetByte();
        }
         Userdate.value0.bytes[15] = I2C_GetLastByte();
        I2C_SendStop();
        I2C_ReleaseBus();
        ShortDelay(100);

        I2C_SendByteWithStart(EEPROMWRITEID);
        I2C_SendByte(16);
        I2C_SendByteWithStart(EEPROMREADID);
	    for(i=16; i<23; i++){		
            Userdate.value0.bytes[i] = I2C_GetByte();
        }
        Userdate.value0.bytes[23] = I2C_GetLastByte();
        I2C_SendStop();
        I2C_ReleaseBus();
        ShortDelay(100);
       
        I2C_SendByteWithStart(EEPROMWRITEID);
        I2C_SendByte(24);
        I2C_SendByteWithStart(EEPROMREADID);
        for(i=24; i<31; i++){
           Userdate.value0.bytes[i] = I2C_GetLastByte();
        }
        Userdate.value0.bytes[31] = I2C_GetLastByte();
        I2C_SendStop();
        I2C_ReleaseBus();
        ShortDelay(100);
         
        //value1
	    I2C_SendByteWithStart(EEPROMWRITEID);
        I2C_SendByte(32);
        I2C_SendByteWithStart(EEPROMREADID);

        for(i=0; i<7; i++){
            Userdate.value1.bytes[i] = I2C_GetByte();
        }
        Userdate.value1.bytes[7] = I2C_GetLastByte();

        I2C_SendStop();
        I2C_ReleaseBus();
         ShortDelay(100);
       
	//value2
	    I2C_SendByteWithStart(EEPROMWRITEID);
        I2C_SendByte(48);
        I2C_SendByteWithStart(EEPROMREADID);
	    for(i=0 ;i<7; i++){
            Userdate.value2.bytes[i] = I2C_GetByte();
            ShortDelay(100);
        }
        Userdate.value2.bytes[7] = I2C_GetLastByte();
        ShortDelay(100);
        I2C_SendStop();
        I2C_ReleaseBus();
        ShortDelay(100);
         

        //value 3
	    I2C_SendByteWithStart(EEPROMWRITEID);
        I2C_SendByte(56);
        I2C_SendByteWithStart(EEPROMREADID);

        for(i=0; i<7; i++){
            Userdate.value3.bytes[i] = I2C_GetByte();
        }
        Userdate.value3.bytes[7] = I2C_GetLastByte();

        I2C_SendStop();
        I2C_ReleaseBus();
        ShortDelay(100);
        
          //value 4
	    I2C_SendByteWithStart(EEPROMWRITEID);
        I2C_SendByte(64);
        I2C_SendByteWithStart(EEPROMREADID);

        for(i=0; i<7; i++){
            Userdate.value4.bytes[i] = I2C_GetByte();
        }
        Userdate.value4.bytes[7] = I2C_GetLastByte();

        I2C_SendStop();
        I2C_ReleaseBus();
        ShortDelay(100);
		 //board info
	    I2C_SendByteWithStart(EEPROMWRITEID);
        I2C_SendByte(72);
        I2C_SendByteWithStart(EEPROMREADID);

        for(i=0; i<8; i++){
            Userdate.boardinfo.bytes[i] = I2C_GetByte();
        }
        Userdate.boardinfo.bytes[8] = I2C_GetLastByte();

        I2C_SendStop();
        I2C_ReleaseBus();
        ShortDelay(100);
        if(Userdate.value2.bytes[6] != 123 || Userdate.value2.bytes[7] != 111 )
        {   
            SetDefaultData0();
            SetDefaultData1();
            SetDefaultData2();
            SetDefaultData3();
            SetDefaultData4();
       }   
}



⌨️ 快捷键说明

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