#ifndef __vrtc_h__
#define __vrtc_h__
#include<reg51.h>
#include<Vdelay.h>
sbit sda=P1^0;
sbit scl=P1^1;
void start_bit()
{
sda=1;
scl=1;
sda=0;
scl=0;
}
void stop_bit()
{
scl=0;
sda=0;
scl=1;
sda=1;
}
void write_mem(unsigned char m )
{
unsigned char i;
unsigned char b;
b=m;
for(i=0;i<8;i++)
{
b=(b & 0x80);
if(b!=0)
sda=1;
else
sda=0;
b=m<<1;
m=b;
scl=1;
scl=0;
}
scl=1;
scl=0;
}
unsigned char read_mem()
{
unsigned char i,a1,b1=0;
sda=1;
for(i=0;i<8;i++)
{
scl=0;
delay();
scl=1;
delay();
if(sda==1)
b1=(b1 | 0x01);
a1=b1;
b1=b1<<1;
}
scl=1;
scl=0;
// val = a1;
return a1;
}
unsigned char read_eprom(unsigned char addr)
{
unsigned char a1=0xd0,a2=0xd1,dat;
start_bit();
write_mem(a1);
write_mem(addr);
start_bit();
write_mem(a2);
dat = read_mem();
stop_bit();
delay1();
return dat;
}
void write_eprom(unsigned char addr,unsigned char b)
{
unsigned char ad=0xd0;
start_bit();
write_mem(ad);
write_mem(addr);
write_mem(b);
stop_bit();
delay1();
}
#endif