OpenVINOTM,给你看得见的未来!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » EEPROM,25AA640,VC33 【求助】串行EEPROM 25AA640

共2条 1/1 1 跳转至

EEPROM,25AA640,VC33 【求助】串行EEPROM 25AA640与VC33的C语言读写程序

院士
2006-12-22 22:43:00    评分
EEPROM,25AA640,VC33 【求助】串行EEPROM 25AA640与VC33的C语言读写程序



关键词: EEPROM     25AA640     求助     串行     语言         

院士
2006-12-22 22:43:00    评分
2楼
问 十万火急!!!我现在正在调试25AA640,已经整了两个星期了还没调通,不知道问题出在哪里了?请各位大虾帮忙检查一下下面的程序!!小弟不胜感激。。。
我的接线如下:
SI--->FSX0;
SO--->FSR0;
SCK-->XF0;
CS--->XF1;
附程序:
#define SET_DSP_IO0 SERIAL_PORT_CONTROL1 |= 0x0400
#define CLR_DSP_IO0 SERIAL_PORT_CONTROL1 &= (0xffff-0x0400)

#define SO SERIAL_PORT_CONTROL2 &= 0x0800

#define SET_SCK IOF|= 0x04
#define CLR_SCK IOF&= (0xff-0x04)
#define SET_CS IOF|= 0x40
#define CLR_CS IOF&= (0xff-0x40)

void main(void)
{      int a;
       a=0;
       SERIAL_PORT_CONTROL1 = 0x0222;
       SERIAL_PORT_CONTROL2 = 0x0022;     
       IOF=0x22;
       
       CLR_SCK;
       CLR_CS;
       WriteEEPROM(8,0x06);
       SET_CS;
       CLR_SCK;
       CLR_CS;
       WriteEEPROM(8,0x02);
       CLR_SCK;
       WriteEEPROM(16,0x0100);
       CLR_SCK;
       WriteEEPROM(8,0x55);
       CLR_SCK;
       SET_CS;
      
       CLR_SCK;
       CLR_CS;
       WriteEEPROM(8,0x03);
       SET_SCK;
       CLR_SCK;
       WriteEEPROM(16,0x0100);
       a=ReadEEPROM(8)& 0xff;
       SET_CS;
       CLR_SCK;          
}                     

void WR_EN(void)
{
     CLR_CS;
     WriteEEPROM(8,0x06);
     SET_CS;
}

int RD_SR(void)
{   int j;
    CLR_CS;
    WriteEEPROM(8,0x05);
    j=ReadEEPROM(8);
    SET_CS;
  return j;
}

void WR_SR(void)
{
     CLR_CS;
     WriteEEPROM(8,0x06);
     SET_CS;
     CLR_CS;
     WriteEEPROM(8,0x01);
     WriteEEPROM(8,0x00);
     SET_CS;
     StopEEPROM();
}   
              
void WriteEEPROM(int iBits,int iValue)        
{
            
    do {
        CLR_SCK;
        Delay_100NS();
        ADDR_EEPROM = iValue >> (iBits - 1);
        iBits--;
        if((ADDR_EEPROM&0x01)==0)        
        CLR_DSP_IO0;
        else         
        SET_DSP_IO0;
        SET_SCK;
        Delay_100NS();             
    }while(iBits != 0);
}      

int ReadEEPROM(int iBits)            
{
    int iData;
    iData=0x00;
    ADDR_EEPROM=0x00;      
    do{
        SET_SCK;
        Delay_100NS();
        CLR_SCK;
        Delay_100NS();
        CLR_SCK;
        Delay_100NS();
        ADDR_EEPROM=SERIAL_PORT_CONTROL2>>11;
        iData|=(ADDR_EEPROM & 0x01)<<(iBits-1);
        iBits--;
        CLR_SCK;
        Delay_100NS();                 
    }while(iBits !=0 );    
    return iData;
}

void StopEEPROM(void)   /* 等待8位数据写完  */
{
    int iData;
    do {
        CLR_CS;
        iData=RD_SR();
        SET_CS;
        }while((iData & 0x01)!=0); /*fake check the last bit */
}

void  Delay_100NS()
{
    unsigned int i,j;
    for(i=0;i<10;i++) {j=i;}   
}      
  1: 个人觉得应该是程序有问题最好还是自己单步调试程序,发现问题, 2: 我知道程序有问题,可我找不出来阿!  大哥,我已经找了2个多星期了还是没有找出问题来!能不能帮我检查检查啊。。。

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]