作者:Thfli
[CODE]
void EEPROM_Write_Enable(void)
{
//give EWEN command to 93c46, allowing write of 93c46 unsigned char i; EEPROM_CS = 0; EEPROM_CLK = 0; EEPROM_CS = 1; for(i=0;i<8;i++) { EEPROM_DI = (EEPROM_EWEN>>(7-i))&1;//)?1:0; EEPROM_CLK = 1; EEPROM_CLK = 0; } EEPROM_CLK = 0; EEPROM_CLK = 1; EEPROM_CLK = 0; EEPROM_DI = 0; EEPROM_CS = 0;
}
//*****************************************************************
void EEPROM_Write(unsigned char Addr,unsigned char Data)
{
//write to 93c46, only the lower 8 bits of the address will be written unsigned char i; Addr &= 0x3f; Addr |= 0x40; EEPROM_CS = 0; EEPROM_DI = 0; EEPROM_CS = 1; EEPROM_DI = 1; EEPROM_CLK = 1; EEPROM_CLK = 0; for(i=0;i<8;i++) { EEPROM_DI = (Addr>>(7-i))&1; EEPROM_CLK = 1; EEPROM_CLK = 1; EEPROM_CLK = 0; } for(i=0;i<8;i++) { EEPROM_CLK = 1; EEPROM_CLK = 1; EEPROM_CLK = 0; }
for(i=0;i<8;i++) { EEPROM_DI = (Data>>(7-i))&1; EEPROM_CLK = 1; EEPROM_CLK = 1; EEPROM_CLK = 0; } EEPROM_DI = 0; EEPROM_CS = 0; EEPROM_CS = 1; while(!EEPROM_DO); EEPROM_CS = 0; }
//***************************************************************** unsigned char EEPROM_Read(unsigned char Addr) { //read 93c46, only the lower 8 bits of the address will be output unsigned char i; unsigned char Data=0; Addr &= 0x3f; Addr |= 0x80; EEPROM_DI = 0; EEPROM_CLK = 0; EEPROM_CS = 1; EEPROM_DI = 1; EEPROM_CLK = 1; EEPROM_CLK=0; for(i=0;i<8;i++) { EEPROM_DI = (Addr>>(7-i))&1; EEPROM_CLK = 1; EEPROM_CLK = 1; EEPROM_CLK = 0; } for(i=0;i<8;i++) { EEPROM_CLK = 1; EEPROM_CLK=0; } for(i=0;i<8;i++) { EEPROM_CLK = 1; if(EEPROM_DO) { Data |= 1<<(7-i); } EEPROM_CLK = 0; } EEPROM_DI = 0; EEPROM_CS = 0; return Data;
}
[/CODE] |