This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

EEPROM 93c46 with 89c51

I am looking for example(s) on writing/reading EEPROMs (93c46) using 89c51 in C.
Any help shall be higly appreciated.

Mansoor

Parents
  • void chngestate(unsigned char command)
    {unsigned char i;


    cs=0;//chip select
    Din=0;//In
    CLK=0;//Clock
    CLK=0;
    cs=1;
    Din=1;
    CLK=1;
    CLK=0;
    for (i=0;i<7;i++)
    {
    if (command&0x80)
    Din=1;
    else
    Din=0;
    CLK=1;
    command<<=1;
    CLK=0;
    }
    buf<<=1;
    if (command&0x80)
    Din=1;
    else
    Din=0;
    CLK=1;
    cs=0;
    _nop_();
    _nop_();
    }
    int eeread(unsigned char address)
    {
    unsigned int result=0;
    unsigned int c=0x8000;
    unsigned char i,buf;
    buf=address&(0xbf)|(0x80);
    cs=0;
    Din=0;
    CLK=0;
    CLK=0;
    cs=1;
    Din=1;
    CLK=1;
    CLK=0;
    for (i=0;i<8;i++)
    {
    if (buf&0x80)
    Din=1;
    else
    Din=0;
    CLK=1;
    buf<<=1;
    CLK=0;
    }
    Din=0;
    //16 bit read msb first
    for (i=0;i<16;i++)
    {
    CLK=1;
    if (Dout) result|=c;//out
    CLK=0;
    c>>=1;
    }
    CLK=1;
    cs=0;
    Din=0;
    return(result);
    }
    void eewrite(unsigned int dat,unsigned char address)
    { unsigned int buf1=dat;
    unsigned char i,buf;
    buf=address&(0x7f)|(0x40);
    cs=0;
    Din=0;
    CLK=0;
    cs=1;
    CLK=0;
    Din=1;
    CLK=1;
    CLK=0;
    for (i=0;i<8;i++)
    {
    if (buf&0x80)
    Din=1;
    else
    Din=0;
    CLK=1;
    buf<<=1;
    CLK=0;
    }
    //send 16 bit data msb first
    for (i=0;i<15;i++)
    {
    if (buf1&0x8000)
    Din=1;
    else
    Din=0;
    CLK=1;
    buf1<<=1;
    CLK=0;
    }
    if (buf1&0x8000)
    Din=1;
    else
    Din=0;
    CLK=1;
    Din=0;
    cs=0;
    _nop_();
    _nop_();
    cs=1;
    _nop_();
    _nop_();
    while (Dout!=1);
    cs=0;
    _nop_();
    _nop_();
    }

Reply
  • void chngestate(unsigned char command)
    {unsigned char i;


    cs=0;//chip select
    Din=0;//In
    CLK=0;//Clock
    CLK=0;
    cs=1;
    Din=1;
    CLK=1;
    CLK=0;
    for (i=0;i<7;i++)
    {
    if (command&0x80)
    Din=1;
    else
    Din=0;
    CLK=1;
    command<<=1;
    CLK=0;
    }
    buf<<=1;
    if (command&0x80)
    Din=1;
    else
    Din=0;
    CLK=1;
    cs=0;
    _nop_();
    _nop_();
    }
    int eeread(unsigned char address)
    {
    unsigned int result=0;
    unsigned int c=0x8000;
    unsigned char i,buf;
    buf=address&(0xbf)|(0x80);
    cs=0;
    Din=0;
    CLK=0;
    CLK=0;
    cs=1;
    Din=1;
    CLK=1;
    CLK=0;
    for (i=0;i<8;i++)
    {
    if (buf&0x80)
    Din=1;
    else
    Din=0;
    CLK=1;
    buf<<=1;
    CLK=0;
    }
    Din=0;
    //16 bit read msb first
    for (i=0;i<16;i++)
    {
    CLK=1;
    if (Dout) result|=c;//out
    CLK=0;
    c>>=1;
    }
    CLK=1;
    cs=0;
    Din=0;
    return(result);
    }
    void eewrite(unsigned int dat,unsigned char address)
    { unsigned int buf1=dat;
    unsigned char i,buf;
    buf=address&(0x7f)|(0x40);
    cs=0;
    Din=0;
    CLK=0;
    cs=1;
    CLK=0;
    Din=1;
    CLK=1;
    CLK=0;
    for (i=0;i<8;i++)
    {
    if (buf&0x80)
    Din=1;
    else
    Din=0;
    CLK=1;
    buf<<=1;
    CLK=0;
    }
    //send 16 bit data msb first
    for (i=0;i<15;i++)
    {
    if (buf1&0x8000)
    Din=1;
    else
    Din=0;
    CLK=1;
    buf1<<=1;
    CLK=0;
    }
    if (buf1&0x8000)
    Din=1;
    else
    Din=0;
    CLK=1;
    Din=0;
    cs=0;
    _nop_();
    _nop_();
    cs=1;
    _nop_();
    _nop_();
    while (Dout!=1);
    cs=0;
    _nop_();
    _nop_();
    }

Children