Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/23/11 12:29
Read: times


 
#182996 - code for 24c02 wih 89c52
Responding to: ???'s previous message
You can try this code
define SDA & SCL pins according to your requirement in the beggining of program

/* register and subroutine for eeprom */

int stop(),
start(),
delay(),
shin(),
nak();

int writelastcount();
int writeset();
int shout(uchar serialout);
int readlasttime();
int readset();
int read_current();

int writelastcount()
{
stop();
start();
shout(0xa0);
shout(0x10);
shout(c[1] << 4 | c[0]);
shout(c[3] << 4 | c[2]);
shout(c[5] << 4 | c[4]);
stop();
SDA = 1;
SCL = 1;
}

int writeset()
{
WP = 0;
stop();
start();
shout(0xa0);
shout(0x20);
shout((set[1] << 4) | set[0]);
shout((set[3] << 4) | set[2]);
shout((dia[1] << 4) | dia[0]);
shout((dia[3] << 4) | dia[2]);
shout((time[1] << 4) | time[0]);
stop();
delay();
SDA = 1;
SCL = 1;
WP = 1;
}

stop()
{
SDA = 0;
SCL = 1;
_nop_();
SDA = 1;
_nop_();
_nop_();
_nop_();
}


start()
{
SDA = 1;
SCL = 0;
SCL = 1;
_nop_();
SDA = 0;
_nop_();
_nop_();
SCL = 0;
_nop_();
}



delay()
{
unsigned char dly1,dly2;
dly1 = 0x7f;
while(dly1 != 0X00)
{
dly2 = 0xff;
while(dly2 != 0X00)
--dly2;
--dly1;
}
}

readlastcount()
{
start();
shout(0xa0);
shout(0x10);

c[0] = read_current();
stop();
c[2] = read_current();
c[4] = read_current();

c[1] = (c[0] >> 4) & 0x0f;
c[0] = c[0] & 0x0f;
c[3] = (c[2] >> 4) & 0x0f;
c[2] = c[2] & 0x0f;

c[5] = (c[4] >> 4) & 0x0f;
c[4] = c[4] & 0x0f;

SDA = 1;
SCL = 1;
}

readset()
{
start();
shout(0xa0);
shout(0x20);

set[0] = read_current();
stop();
set[2] = read_current();

set[1] = (set[0] >> 4) & 0x0f;
set[0] = set[0] & 0x0f;
set[3] = (set[2] >> 4) & 0x0f;
set[2] = set[2] & 0x0f;

dia[0] = read_current();
dia[2] = read_current();

dia[1] = (dia[0] >> 4) & 0x0f;
dia[0] = dia[0] & 0x0f;
dia[3] = (dia[2] >> 4) & 0x0f;
dia[2] = dia[2] & 0x0f;

time[0] = read_current();
time[1] = (time[0] >> 4) & 0x0f;
time[0] = time[0] & 0x0f;

SDA = 1;
SCL = 1;
}

int read_current()
{
uchar serialin;

start();
shout(0xa1);
serialin = shin();
nak();
stop();
return serialin;
}

int shout(unsigned char serialout)
{
unsigned char eepromcounter;
eepromcounter = 0x08;
while(eepromcounter)
{
serialout = serialout << 1;
_nop_();
SDA = CY;
_nop_();
SCL = 1;
_nop_();
_nop_();
_nop_();
_nop_();
SCL = 0;
--eepromcounter;
}
SDA = 1;
_nop_();
_nop_();
SCL = 1;
_nop_();
_nop_();
_nop_();
_nop_();
CY = SDA;
SCL = 0;
}

int shin()
{
uchar eepromcounter,serialin;
SDA = 1;
eepromcounter = 0x08;
while(eepromcounter)
{
serialin = serialin << 1;
_nop_();
SCL = 1;
_nop_();
if(SDA)
serialin = serialin | 0X01;
SCL = 0;
--eepromcounter;
}
return serialin;
}


nak()
{
SDA = 1;
_nop_();
_nop_();
SCL = 1;
_nop_();
_nop_();
_nop_();
_nop_();
SCL = 0;
}

List of 13 messages in thread
TopicAuthorDate
Help me ? 89C52 interfacing with EEPROM 24C02            01/01/70 00:00      
   Do *not* use 'for' loops for delays!            01/01/70 00:00      
   100k is the upper limit            01/01/70 00:00      
      HLL delay loops - just don't do it!            01/01/70 00:00      
   that may be difficult            01/01/70 00:00      
      but there is a way            01/01/70 00:00      
   See if this code is of any help!            01/01/70 00:00      
      I doubt it very much            01/01/70 00:00      
      No, it isn't            01/01/70 00:00      
   doubts 1,2,3            01/01/70 00:00      
   code for 24c02 wih 89c52            01/01/70 00:00      
      Do *not* use 'for' loops for delays!            01/01/70 00:00      
      code?            01/01/70 00:00      

Back to Subject List