当前位置: 代码迷 >> 单片机 >> 小弟我对小弟我的c51教材最后一节内容十分不明白,高手帮下忙好吗
  详细解决方案

小弟我对小弟我的c51教材最后一节内容十分不明白,高手帮下忙好吗

热度:100   发布时间:2016-04-28 16:10:30.0
我对我的c51教材最后一节内容十分不明白,高手帮下忙好吗?
这部分内容是有关EEPROM的内容,不懂EEPROM_CLK要不停地切换(我水平差,最好其它方面再给我提点一下)
EEPROM_CLK = 1; 
  EEPROM_CLK = 0;
整段程序是这样的:
#include <at89x52.h>  
  
#define EEPROM_CS P1_5  
#define EEPROM_CLK P1_6  
#define EEPROM_DI P1_7  
#define EEPROM_DO P1_4  
  
#define SEG_PORT P0  
#define COMM_PORT P1  
  
#define EEPROM_EWEN 0x9f  
  
#define WRITTEN_DATA 0xab  
#define ADDRESS 0x05  
  
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;  
  EEPROM_CLK = 1;  
  EEPROM_CLK = 0;  
  }  
  EEPROM_CLK = 1;  
  EEPROM_CLK = 0;  
  EEPROM_CLK = 1;  
  EEPROM_CLK = 0;  
  EEPROM_DI = 0;  
  EEPROM_CS = 0;  
}  
  
void EEPROM_Write(unsigned char addr, unsigned char writtenData)  
{  
//write to 93c46, only the lower 8 bits of the address will be written  
  unsigned char i;  
  addr |= 0x80;  
//only lower 7 bits of address is valid according to 93c46's datasheet.  
//so the highest bit is used as the second bit of write instruction  
  EEPROM_CS = 0;  
  EEPROM_DI = 0;  
  EEPROM_CS = 1;  
  
  EEPROM_DI = 1;  
  EEPROM_CLK = 1;  
  EEPROM_CLK = 0;  
  
  EEPROM_DI = 0;  
  EEPROM_CLK = 1;  
  EEPROM_CLK = 0;  
  
  for(i=0; i<8; i++)  
  {  
  EEPROM_DI = (addr>>(7-i))&1;  
  EEPROM_CLK = 1;  
  EEPROM_CLK = 0;  
  }  
  for(i=0; i<8; i++)  
  {  
  EEPROM_DI = (writtenData>>(7-i))&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 7 bits of the address will be output  
  unsigned char i;  
  unsigned char readData = 0;  
  
  EEPROM_DO = 1; //set as input  
  addr &= 0x7f;  
  
  EEPROM_DI = 0;  
  EEPROM_CLK = 0;  
  EEPROM_CS = 1;  
  
  EEPROM_DI = 1;  
  EEPROM_CLK = 1;  
  EEPROM_CLK = 0;  
  
  EEPROM_CLK = 1;  
  EEPROM_CLK = 0;  
  
  for(i=0; i<8; i++)  
  {  
  EEPROM_DI = (addr>>(7-i))&1;  
  EEPROM_CLK = 1;  
  EEPROM_CLK = 0;  
  }  
  for(i=0; i<8; i++)  
  {  
  相关解决方案