在线情况
楼主
  • 头像
  • 级别
  • 门派
  • 职务总版主
  • 声望+9
  • 财富5
  • 积分3065
  • 经验390701
  • 文章6744
  • 注册2006-03-07
51操作AT93C46的三个常用函数
作者: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]
[ 此帖最后由DC在2012-11-8 0:42:50从 电子通识 转移过来 ]
[COLOR=#0000ff]欢迎发贴分享设计心得、开源DIY...[/COLOR]
Powered by LeadBBS 9.2 .
Page created in 0.2500 seconds with 5 queries.