Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

storage problem in seriel memory 24c04.

Status
Not open for further replies.

tapu

Full Member level 5
Full Member level 5
Joined
Sep 15, 2014
Messages
246
Helped
1
Reputation
2
Reaction score
2
Trophy points
1,298
Location
india
Visit site
Activity points
3,164
Dear all,
I have made alarm clock by using rtc ds1307.here I use serial memory 24c04 for storing multiple alarms. alarm clock was running successfully without any storage error..but now I purchased new 24c04 then alarm hour stored but alarm minutes is not stored.I have tried three IC's of different shops but problem is same.please reply.
Thanks,
Zakariya
 

Hi,

The problem is in line 24 of your code.

Honestly...how can we give a satisfying answer without useful information?
No code, no circuit, no supply voltages, no signal voltages and timings, no memory brand, no exact memory type.....

Klaus
 

Dear all,
sorry for replying late.
This problom is not in old memory 24c04.here i have a given circuit,ic brand & code please check.
Code:
#include <REGX51.H>





sbit set=P1^0;
sbit mov=P1^1;
sbit inc=P1^2;
sbit dec=P1^3;
sbit rly=P1^4;
sbit e5=P1^5;//3rd e5
sbit e6=P2^3;//4th	e6
sbit blink=P2^1;
sbit bus=P3^7;
sbit ind=P3^6;
sbit e4=P1^7;//1st e4
sbit e3=P1^6;//2nd e3
sbit SDA=P2^6;
sbit SCL=P2^7;

bit d;
bit e;
bit f;
bit nxt;
bit nxta;

unsigned char dec_hex(unsigned char tt)
{
if(tt>59)
tt+=36;

else if(tt>49)
tt+=30;
else if(tt>39)
tt+=24;
else if(tt>29)
tt+=18;
else if(tt>19)
tt+=12;
else if(tt>9)
tt+=6;
return(tt);
} 


void all_disp();
void time_set();

void alarm_set();

void set_date();
void blink_on();
	void buzzer();
void no_op();
void setdisp_ampm();
	 void alarm_setsat();

unsigned int zt;



void alarm_chk1();
void alarm_chk2();
void alarm_chk3();
void alarm_chk4();

void alarm_bell_HI();
void alarm_bell_LOW();
void display_day();
void puls();
void no_puls();




#define First_Line 0x80
#define Second_Line 0xc0
#define Curser_On 0x0f
#define Curser_Off 0x0c
#define Clear_Display 0x01
#define idle f==1

#define Data_Port P0

sbit Lcd_rs = P2^0;
//sbit Lcd_rw = P2^1;
sbit Lcd_en = P2^2;

sbit sda_rtc =P2^5;
sbit scl_rtc =P2^4;

/*sbit Lcd_rs = P3^5;
sbit Lcd_rw = P3^6;
sbit Lcd_en = P3^7; */

void Lcd8_Init();
void Lcd8_Command(unsigned char);
void Lcd8_Write(unsigned char,unsigned char);
void Lcd8_Display(unsigned char,const unsigned char*,unsigned int);
void Lcd8_decimal2(unsigned char,unsigned char val);
void Delay(unsigned int);
void del();

void hour_mode();
void set_mod1();
void set_mod2();

unsigned char LB,SB;
void Seg8_decimal2(min);

void Led8decimal2(hour);
unsigned char num;
void EEPROM_WriteByte(unsigned char eeprom_Address, unsigned char eeprom_Data);
unsigned char EEPROM_ReadByte(unsigned char eeprom_Address);
void I2C_Start();
void I2C_Stop(void);
void I2C_Ack();
void I2C_Write(unsigned char dat);
unsigned char I2C_Read();
 #define EEPROM_ID 0xa0
void delay_ms(unsigned int ms_count);
void I2C_NoAck();
void I2C_Clock();
void delay_us(unsigned int us_count);
void msdelay(unsigned int value);
void emerg_bell();

//unsigned char number[]="1,2,3,4";



#define DS1307_ID 0xD0
#define SEC 0x00
#define MIN 0x01
#define HOUR 0x02
#define DAY 0x03
#define DATE 0x04
#define MONTH 0x05
#define YEAR 0x06
#define ctrl 0x07
#define FRIDAY 0x06
#define SATURDAY 0x07
#define SUNDAY 0x01



DS1307_get(unsigned char);
void DS1307_settime(unsigned char, unsigned char, unsigned char);
void DS1307_setdate(unsigned char, unsigned char, unsigned char,unsigned char);
Send2lcd(unsigned char);
void Rtc_Write(unsigned char,unsigned char);
Rtc_Read(unsigned char);
void Rtc_rd_wr_sub();
void Rtc_Init();
void Rtc_Start();
void Rtc_Tx();
void Rtc_Rx();
void Rtc_Stop();
void Rtc_Ack();
void disp();
void disp_time();
void display_ampm();
void dispampm();
void set_ampm();

void set_mod();

void alarm_chk1();
void alarm_chk2();
void alarm_chk3();
void alarm_chk4();

void all_alrmset();
 void all_alrmsetsat();

void friday_chk();
void regular_chk();
	void saturday_chk();

void idle_chk();
void key_lock2();


unsigned int Rtc_add_wr,Rtc_add_rd;
unsigned char d_rtc,datain_rtc,in_rtc,temp_rtc,dat_rtc,flag_rtc;

unsigned char i,j,a[10],cur=0,cur1=0,cur2=0,cur3=0,cur4=0;
unsigned char dati,sec,hour,min,date,day,month,year,mode=0,sec1,hour1,min1,sec2,hour2,min2,hh,mm,ss,dd,mn,yy,ahour,amin,asec,amin1,ahour1;
 

unsigned char count[8]={0x82,0x85,0x8a,0x8d,0xc2,0xc5,0xcb,0xcd};   ///0x8a changed
code unsigned char memo[40]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38};
code unsigned char memo1[40]={0x39,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x70,0x71,0x72,0x73,0x74,0x75,0x76};

unsigned char count1[4]={0x86,0x89,0xc6,0xc9};  
unsigned char count2[2]={0x8b,0xcb};   

unsigned char rly_hex(unsigned char tt)
{
if(tt>59)
tt+=36;
else if(tt>49)
tt+=30;
else if(tt>39)
tt+=24;
else if(tt>29)
tt+=18;
else if(tt>19)
tt+=12;
else if(tt>9)
tt+=6;
return(tt);
} 

void all_disp()
	
{
	
sec = DS1307_get(SEC);
min = DS1307_get(MIN);
hour = DS1307_get(HOUR);
	
dispampm();
setdisp_ampm();
hour=hour& 0x1f;
display_ampm();

date = DS1307_get(DATE);
day = DS1307_get(DAY);
month = DS1307_get(MONTH);
year = DS1307_get(YEAR);
	
sec=Send2lcd(sec);
min=Send2lcd(min);
hour=Send2lcd(hour);
day=Send2lcd(day);
	
date=Send2lcd(date);
year=Send2lcd(year);
month=Send2lcd(month);
	



Lcd8_decimal2(0xc6,hour);
Lcd8_Write(0xc8,'.');
Lcd8_decimal2(0xc9,min);
Lcd8_Write(0xcb,'.');
Lcd8_decimal2(0xcc,sec);
	Lcd8_decimal2(0x82,date);
Lcd8_Write(0x84,'-');
Lcd8_decimal2(0x85,month);
Lcd8_Write(0x87,'-');
Lcd8_Display(0x88,"20 ",2);

Lcd8_decimal2(0x8a,year);

//Lcd8_decimal2(0x8d,day);


Seg8_decimal2(min);
Led8decimal2(hour);



}

void main()
	
{
nxt=0;
rly=0;	
dati=0x00;
Lcd8_Init();
Lcd8_Display(0x82,"ZAKARIYA ",8);
	Lcd8_Display(0xc3,"Technologies ",12);

Delay(65000);
Delay(65000);



Lcd8_Command(0x01);
Rtc_Init();
	//puls();


//DS1307_setdate(0x04,0x11,0x11);
//DS1307_settime(0x16,0x00,0x00);

while(1)
	
{
	//P1=EEPROM_ReadByte(memo[1]);

	dati++;
all_disp();
//disp();
	display_day();
//idle_chk();if(idle) goto jump;  //No alarm betwen 8pm to 6am

//if(day==SATURDAY) goto jump;
//if(day==SUNDAY) goto jump;

//if(day==FRIDAY)
//friday_chk();
//else
	//if(day==SATURDAY)
	//saturday_chk();
	//else
regular_chk();
jump:
	if(!set)
		key_lock2();  ///show as keypad locked(when press set/inc/dec)

 if(!inc)
	 key_lock2();  ///show as keypad locked(when press set/inc/dec)

 if(!dec)
	 
   key_lock2();  ///show as keypad locked(when press set/inc/dec)

 
 if(!dec)
 alarm_bell_HI();

  if(!set)
 alarm_bell_LOW();

if(mov==0)
{
Delay(65000);
Delay(65000);
Delay(65000);
}
if(mov==0)
{
		Lcd8_Command(0x01);

	Lcd8_Display(0xc4,"Unlocked ",8);
	Delay(65000);
time_set();
	cur2=0;
	cur4=0;
			Lcd8_Command(0x01);
		Lcd8_Command(0x0c);

	Lcd8_Display(0x82,"REGULAR ",7);
	Lcd8_Display(0xC4,"SCHEDULE ",8);

		Delay(65000);
		Delay(65000);

all_alrmset();
			//Lcd8_Command(0x01);
	//Lcd8_Display(0x82,"SATURDAY",8);
	//Lcd8_Display(0xC4,"SCHEDULE ",8);

		Delay(65000);
		Delay(65000);

//all_alrmsetsat();

set_date();

}
if(dati==0x03)
{
blink=~blink;
dati=0x00;
}
}
}


void dispampm()
	
{
	if(hour==0x00)
	{
		 d=0;

Rtc_Start();

Rtc_Write(0x02,0x40);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x01)
	{
				 d=0;

Rtc_Start();

Rtc_Write(0x02,0x41);
 
Rtc_Stop(); /* Stop i2c bus */
	}

			if(hour==0x02)
	{
				 d=0;

Rtc_Start();

Rtc_Write(0x02,0x42);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x03)
	{
				 d=0;

Rtc_Start();

Rtc_Write(0x02,0x43);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x04)
	{
				 d=0;

Rtc_Start();

Rtc_Write(0x02,0x44);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x05)
	{
				 d=0;

Rtc_Start();

Rtc_Write(0x02,0x45);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x06)
	{
				 d=0;

Rtc_Start();

Rtc_Write(0x02,0x46);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x07)
	{
				 d=0;

Rtc_Start();

Rtc_Write(0x02,0x47);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x08)
	{
				 d=0;

Rtc_Start();

Rtc_Write(0x02,0x48);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x09)
	{
				 d=0;

Rtc_Start();

Rtc_Write(0x02,0x49);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x10)
	{
				 d=0;

Rtc_Start();

Rtc_Write(0x02,0x4a);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x11)
	{
				 d=0;

Rtc_Start();

Rtc_Write(0x02,0x4b);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x12)
	{
				 d=1;

Rtc_Start();

Rtc_Write(0x02,0x72);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x13)
	{
						 d=1;

Rtc_Start();

Rtc_Write(0x02,0x61);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x14)
	{
						 d=1;

Rtc_Start();

Rtc_Write(0x02,0x62);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x15)
	{
						 d=1;

Rtc_Start();

Rtc_Write(0x02,0x63);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x16)
	{
						 d=1;

Rtc_Start();

Rtc_Write(0x02,0x64);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x17)
	{
						 d=1;

Rtc_Start();

Rtc_Write(0x02,0x65);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x18)
	{
						 d=1;

Rtc_Start();

Rtc_Write(0x02,0x66);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x19)
	{
						 d=1;

Rtc_Start();

Rtc_Write(0x02,0x67);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x20)
	{
						 d=1;

Rtc_Start();

Rtc_Write(0x02,0x68);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x21)
	{
						 d=1;

Rtc_Start();

Rtc_Write(0x02,0x69);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x22)
	{
						 d=1;

Rtc_Start();

Rtc_Write(0x02,0x6a);
 
Rtc_Stop(); /* Stop i2c bus */
	}

		if(hour==0x23)
	{
						 d=1;

Rtc_Start();

Rtc_Write(0x02,0x6b);
 
Rtc_Stop(); /* Stop i2c bus */
	}
	
}





void key_lock2() 
{

 
{
	Lcd8_Command(0x01);

	Lcd8_Display(0xc1,"Keypad locked ",13);

Delay(65000);
Lcd8_Command(0x01);
}
}






void idle_chk()
	
{
if(hour==8)
	if(d==1)
		f=1;
if(hour==9)
	if(d==1)
		f=1;
if(hour==10)
	if(d==1)
if(hour==11)
	if(d==1)
	f=1;
if(hour==12)
	if(d==0)
	f=1;
if(hour==1)
	if(d==0)
	f=1;
if(hour==2)
	if(d==0)
	f=1;
if(hour==3)
	if(d==0)
	f=1;
if(hour==4)
	if(d==0)
	f=1;
if(hour==5)
	if(d==0)
	f=1;
if(hour==6)
	if(d==0)
	f=1;
	
	
}	

 void all_alrmset(void)
 {
	 nxt=0;
	 up:alarm_set();
	 //alarm_setsat();
	 if(nxt==0) goto up;

 }
 
  void all_alrmsetsat(void)
 {
	 nxta=0;
	 up:alarm_setsat();
	 if(nxta==0) goto up;

 }
 

 
 
 
 
 
 void friday_chk()
 {
 }

 void regular_chk()
 {
 alarm_chk1();
alarm_chk2();
 }

 
  void saturday_chk()
 {
 alarm_chk3();
 alarm_chk4();
 }

 
 
 void setdisp_ampm()
 {
	 	if(hour==0x52)
	  d=0;
     
		if(hour==0x41)
	  d=0;
    if(hour==0x42)
	  d=0;
    if(hour==0x43)
	  d=0;
		if(hour==0x44)
	  d=0;
    if(hour==0x45)
	  d=0;
    if(hour==0x46)
	  d=0;
    if(hour==0x47)
	  d=0;
    if(hour==0x48)
	  d=0;
    if(hour==0x49)
	  d=0;
    if(hour==0x4a)
	  d=0;
    if(hour==0x4b)
	  d=0;

	if(hour==0x72)
    d=1;
  if(hour==0x61)
    d=1;
  if(hour==0x62)
    d=1;
  if(hour==0x63)
    d=1;
  if(hour==0x64)
    d=1;
  if(hour==0x65)
    d=1;
  if(hour==0x66)
    d=1;
  if(hour==0x67)
    d=1;
  if(hour==0x68)
    d=1;
  if(hour==0x69)
    d=1;
  if(hour==0x6a)
    d=1;
  if(hour==0x6b)
    d=1;

 }






void disp_time()
	
{
sec = DS1307_get(SEC);
min = DS1307_get(MIN);
hour = DS1307_get(HOUR);
	hour=hour& 0x1f;
sec=Send2lcd(sec);
min=Send2lcd(min);
hour=Send2lcd(hour);

	Lcd8_decimal2(0xc2,hour);
Lcd8_Write(0xc4,'.');
Lcd8_decimal2(0xc5,min);
Lcd8_Write(0xc7,'.');
Lcd8_decimal2(0xc8,sec);
set_ampm();


Seg8_decimal2(min);
Led8decimal2(hour);
	
	
}
void display_ampm()
	
{
 if(d==0)
  Lcd8_Display(0xce,"AM ",2);/////////////////////////////////////////////////////////changed

 if(d==1)
	Lcd8_Display(0xce,"PM ",2);/////////////////////////////////////////////////////////changed
}


void set_ampm()
{
	 if(d==0)
  Lcd8_Display(0xcb,"AM ",2);/////////////////////////////////////////////////////////changed

 if(d==1)
	Lcd8_Display(0xcb,"PM ",2);/////////////////////////////////////////////////////////changed

}

void emerg_bell()
{
}

void no_op()

{
	
}
	
void hour_mode()
	
{
	
	if(hour>12)
		hour=hour-12;
	
}

void puls()
	
{
	Rtc_Start();

Rtc_Write(0x07,0x10); /* Write date on RAM address 04H */
	

Rtc_Stop(); /* Stop i2c bus */
}

void no_puls()
{
Rtc_Start();

Rtc_Write(0x07,0x00); /* Write date on RAM address 04H */
	

Rtc_Stop(); /* Stop i2c bus */
}


void display_day()
{

 if(day==0x01)
 
Lcd8_Display(0xc1,"SUN    ",3);

 if(day==0x02)

Lcd8_Display(0xc1,"MON    ",3);
 if(day==0x03)

Lcd8_Display(0xc1,"TUE   ",3);
 if(day==0x04)

Lcd8_Display(0xc1,"WED ",3);
 if(day==0x05)

Lcd8_Display(0xc1,"THU  ",3);
 if(day==0x06)

Lcd8_Display(0xc1,"FRI    ",3);
 if(day==0x07)

Lcd8_Display(0xc1,"SAT  ",3);

}


void set_date()

{
	blink_on();

Lcd8_Command(0x01);

	
all_disp();
	Lcd8_decimal2(0x8d,day);
cur=0;
while(set)
{
	
	Lcd8_Command(0x0f);
Lcd8_Command(count[cur]);

if(mov==0)
{
while(!mov);
cur++;
			blink_on();

if(cur==4)
cur=0;
}


else if(count[cur]==0x82)
{
if(inc==0)
{
while(inc==0);
date++;
blink_on();
Lcd8_decimal2(count[cur],date);

if(date>31)
date=0;
}

else if(dec==0)
{
while(!dec);
date--;
blink_on();

if(date==0xff)
date=99;
}

}

else if(count[cur]==0x85)
{
if(inc==0)
{
while(inc==0);
month++;
	blink_on();

Lcd8_decimal2(count[cur],month);


if(month>12)
month=0;
}

else if(dec==0)
{
while(!dec);
month--;
	blink_on();

if(month==0xff)
month=99;
}

}


else if(count[cur]==0x8a)
{
if(inc==0)
{
while(!inc);
year++;
	blink_on();

	Lcd8_decimal2(count[cur],year);

if(year>99)
year=0;
}
else if(dec==0)
{
while(!dec);
year--;
	blink_on();

if(year==0xff)
year=99;
}
}



else if(count[cur]==0x8d)
{
if(inc==0)
{
while(!inc);
day++;
	blink_on();

 //Lcd8_Command(0x01);


	display_day();

	Lcd8_decimal2(count[cur],day);

if(day>6)
day=0;
}
else if(dec==0)
{
while(!dec);
day--;
	blink_on();
		display_day();


if(day==0xff)
day=7;
}
}


}
dd=dec_hex(date);
mn=dec_hex(month);
yy=dec_hex(year);
									
day=dec_hex(day);



DS1307_setdate(dd,mn,yy,day); 

Lcd8_Command(0x0c);
puls();


}



void blink_on()
{
blink=0;
  Delay(6500);
blink=1;
	
}

void set_mod()
	
{
	
if(mode==1)
{
d=0;

Lcd8_Display(0xcb,"AM ",2);/////////////////////////////////////////////////////////changed
}

if(mode==2)

{
d=1;
Lcd8_Display(0xcb,"PM ",2);/////////////////////////////////////////////////////////changed
	
}

}	


void set_mod1()
	
{
	
if(mode==1)
{
d=0;
		//hour=hour-12;

Lcd8_Display(0x8b,"AM ",2);/////////////////////////////////////////////////////////changed
}

if(mode==2)

{
	d=1;
	//hour=hour+12;
Lcd8_Display(0x8b,"PM ",2);/////////////////////////////////////////////////////////changed
	
}

}	




void set_mod2()
	
{
	
if(mode==1)
{
d=0;
		//hour=hour-12;

Lcd8_Display(0xcb,"AM ",2);/////////////////////////////////////////////////////////changed
}

if(mode==2)

{
	d=1;
	//hour=hour+12;
Lcd8_Display(0xcb,"PM ",2);/////////////////////////////////////////////////////////changed
	
}

}	







	void time_set()

{	

	blink_on();

 Lcd8_Command(Curser_On);

 Lcd8_Command(0x01);
 Lcd8_Display(0x84,"Set Time",8);
disp_time();


cur=4;
while(set)


{
		Lcd8_Command(0x0f);
Lcd8_Command(count[cur]);


if(mov==0)
{
while(!mov);
cur++;
blink_on();

if(cur==7)
cur=4;
}


else if(count[cur]==0xc2)
{
if(inc==0)
{
while(inc==0);
hour++;
		blink_on();
	Led8decimal2(hour);
	Lcd8_decimal2(0xc2,hour);



if(hour>=25)
hour=0;
}




else if(dec==0)
{
while(!dec);
hour--;

		blink_on();

	Led8decimal2(hour);
	Lcd8_decimal2(0xc2,hour);


if(hour==0)
hour=24;
}

}

else if(count[cur]==0xc5)
{
if(inc==0)
{
while(inc==0);
min++;
		blink_on();

Seg8_decimal2(min);
		Lcd8_decimal2(0xc5,min);


if(min>=60)
min=0;
}

else if(dec==0)
{
while(!dec);
min--;
		blink_on();

	Seg8_decimal2(min);
			Lcd8_decimal2(0xc5,min);


if(min==0xff)
min=31;
}

}


else if(count[cur]==0xcb)
{
if(inc==0)
{
while(!inc);
mode++;
set_mod();
Delay(6500);


blink_on();
//display_ampm();
if(mode>1)
mode=0;

}
}


}
									

hh=rly_hex(hour);
mm=rly_hex(min);


if(d==1)
	hh= hh | 0x60;
if(d==0)
	hh= hh | 0x40;


DS1307_settime(hh,mm,ss);

}
	

	void buzzer()
		
	{

	e4=0;
	e3=0;
P3=0xff;
e4=1;	
e3=1;
		  Delay(6500);
Led8decimal2(hour);

	}
	
	














void alarm_setsat()
	
{

	no_puls();
	cur4++;
 ahour=EEPROM_ReadByte(memo1[cur4]);
  cur4++;
 amin=EEPROM_ReadByte(memo1[cur4]);
	cur4++;
ahour1=EEPROM_ReadByte(memo1[cur4]);
	cur4++;

 amin1=EEPROM_ReadByte(memo1[cur4]);
Delay(10000);
	blink_on();


	Lcd8_Command(Curser_Off);

	Lcd8_Command(0x0f);
 
  Lcd8_Command(0x01);
	Lcd8_Display(0x88,":",1);
  	Lcd8_Display(0xc8,":",1);
		if(cur4<17)
		{	
						
  
  Lcd8_Display(0x82,"LB)",3);

	Lcd8_decimal2(0x86,ahour);
  Lcd8_decimal2(0x89,amin);
  Lcd8_Display(0xc2,"LB)",3);
  Lcd8_decimal2(0xc6,ahour1);
  Lcd8_decimal2(0xc9,amin1);
		}
else
		{	
  Lcd8_Display(0x82,"SB)",3);
  Lcd8_decimal2(0x86,ahour);
  Lcd8_decimal2(0x89,amin);
  Lcd8_Display(0xc2,"SB)",3);
  Lcd8_decimal2(0xc6,ahour1);
  Lcd8_decimal2(0xc9,amin1);
		}


cur1=0;

while(set)
{
Lcd8_Command(0x0f);
Lcd8_Command(count1[cur1]);
if(mov==0)
{
while(!mov);
cur1++;
if(cur1==4)
cur1=0;
}
else if(count1[cur1]==0x86)			                    ///1st line of lcd
{
if(inc==0)
{
while(inc==0);
ahour++;
	blink_on();

if(ahour>=24)
ahour=0;
Lcd8_decimal2(count1[cur1],ahour);
}

else if(dec==0)
{
while(!dec);
ahour--;
	blink_on();



if(ahour==0)
ahour=23;
Lcd8_decimal2(count1[cur1],ahour);

}

}
else if(count1[cur1]==0x89)
{
if(inc==0)
{
while(inc==0);
amin++;
	blink_on();

if(amin>=60)
amin=0;
Lcd8_decimal2(count1[cur1],amin);
}

else if(dec==0)
{
while(!dec);
amin--;
		blink_on();


if(amin==0)
amin=59;
Lcd8_decimal2(count1[cur1],amin);

}

}

else if(count1[cur1]==0xc6)
{
if(inc==0)
{
while(inc==0);
ahour1++;
	blink_on();

if(ahour1>=24)
ahour1=0;
Lcd8_decimal2(count1[cur1],ahour1);
}

else if(dec==0)
{
while(!dec);
ahour1--;
	blink_on();


if(ahour1==0)
ahour1=24;
Lcd8_decimal2(count1[cur1],ahour1);

}

}
else if(count1[cur1]==0xc9)
{
if(inc==0)
{
while(inc==0);
amin1++;
	blink_on();

if(amin1>=60)
amin1=0;
Lcd8_decimal2(count1[cur1],amin1);
}

else if(dec==0)
{
while(!dec);
amin1--;
	blink_on();

if(amin1==0)
amin1=60;
Lcd8_decimal2(count1[cur1],amin1);

}

}

}


Lcd8_Command(0x0c);
//Delay(65000);Delay(65000);
cur4--;
cur4--;
cur4--;



 EEPROM_WriteByte(memo1[cur4], ahour);
cur4++;
 EEPROM_WriteByte(memo1[cur4], amin);
cur4++;
 EEPROM_WriteByte(memo1[cur4], ahour1);
cur4++;
 EEPROM_WriteByte(memo1[cur4], amin1);

 Lcd8_Command(0x01);	                                       

if(cur4==36)
	
	nxta=1;

}








void alarm_set()
	
{


	no_puls();
	cur2++;
 ahour=EEPROM_ReadByte(memo[cur2]);
  cur2++;
 amin=EEPROM_ReadByte(memo[cur2]);
	cur2++;
ahour1=EEPROM_ReadByte(memo[cur2]);
	cur2++;

 amin1=EEPROM_ReadByte(memo[cur2]);
Delay(10000);
	blink_on();


	Lcd8_Command(Curser_Off);

	Lcd8_Command(0x0f);
 
  Lcd8_Command(0x01);
	Lcd8_Display(0x88,":",1);
  	Lcd8_Display(0xc8,":",1);
		if(cur2<17)
		{	
						
  
  Lcd8_Display(0x82,"LB)",3);

	Lcd8_decimal2(0x86,ahour);
  Lcd8_decimal2(0x89,amin);
  Lcd8_Display(0xc2,"LB)",3);
  Lcd8_decimal2(0xc6,ahour1);
  Lcd8_decimal2(0xc9,amin1);
		}
else
		{	
  Lcd8_Display(0x82,"SB)",3);
  Lcd8_decimal2(0x86,ahour);
  Lcd8_decimal2(0x89,amin);
  Lcd8_Display(0xc2,"SB)",3);
  Lcd8_decimal2(0xc6,ahour1);
  Lcd8_decimal2(0xc9,amin1);
		}


cur1=0;

while(set)
{
Lcd8_Command(0x0f);
Lcd8_Command(count1[cur1]);
if(mov==0)
{
while(!mov);
cur1++;
if(cur1==4)
cur1=0;
}
else if(count1[cur1]==0x86)			                    ///1st line of lcd
{
if(inc==0)
{
while(inc==0);
ahour++;
	blink_on();

if(ahour>=24)
ahour=0;
Lcd8_decimal2(count1[cur1],ahour);
}

else if(dec==0)
{
while(!dec);
ahour--;
	blink_on();



if(ahour==0)
ahour=23;
Lcd8_decimal2(count1[cur1],ahour);

}

}
else if(count1[cur1]==0x89)
{
if(inc==0)
{
while(inc==0);
amin++;
	blink_on();

if(amin>=60)
amin=0;
Lcd8_decimal2(count1[cur1],amin);
}

else if(dec==0)
{
while(!dec);
amin--;
		blink_on();


if(amin==0)
amin=59;
Lcd8_decimal2(count1[cur1],amin);

}

}

else if(count1[cur1]==0xc6)
{
if(inc==0)
{
while(inc==0);
ahour1++;
	blink_on();

if(ahour1>=24)
ahour1=0;
Lcd8_decimal2(count1[cur1],ahour1);
}

else if(dec==0)
{
while(!dec);
ahour1--;
	blink_on();


if(ahour1==0)
ahour1=24;
Lcd8_decimal2(count1[cur1],ahour1);

}

}
else if(count1[cur1]==0xc9)
{
if(inc==0)
{
while(inc==0);
amin1++;
	blink_on();

if(amin1>=60)
amin1=0;
Lcd8_decimal2(count1[cur1],amin1);
}

else if(dec==0)
{
while(!dec);
amin1--;
	blink_on();

if(amin1==0)
amin1=60;
Lcd8_decimal2(count1[cur1],amin1);

}

}

}


Lcd8_Command(0x0c);
//Delay(65000);Delay(65000);
cur2--;
cur2--;
cur2--;



 EEPROM_WriteByte(memo[cur2], ahour);
cur2++;
 EEPROM_WriteByte(memo[cur2], amin);
cur2++;
 EEPROM_WriteByte(memo[cur2], ahour1);
cur2++;
 EEPROM_WriteByte(memo[cur2], amin1);

 Lcd8_Command(0x01);	                                       

if(cur2==36)
	
	nxt=1;

}







void alarm_chk1()
{
	for(cur2=1;cur2<17;cur2++)
	{
ahour=EEPROM_ReadByte(memo[cur2]);
		cur2++;
		amin=EEPROM_ReadByte(memo[cur2]);
		asec=00;
 if(hour==ahour)
	 if(min==amin)
   if(sec==asec)
alarm_bell_HI();
else
rly=0;
}
}


void alarm_chk2()
{
		for(cur2=17;cur2<37;cur2++)
	{
ahour=EEPROM_ReadByte(memo[cur2]);
		cur2++;
		amin=EEPROM_ReadByte(memo[cur2]);
		asec=00;
 if(hour==ahour)
	 if(min==amin)
   if(sec==asec)
alarm_bell_LOW();
else
rly=0;
}

	
}




void alarm_chk3()
{
	for(cur4=1;cur4<17;cur4++)
	{
ahour=EEPROM_ReadByte(memo1[cur4]);
		cur4++;
		amin=EEPROM_ReadByte(memo1[cur4]);
		asec=00;
 if(hour==ahour)
	 if(min==amin)
   if(sec==asec)
alarm_bell_HI();
else
rly=0;
}
}


void alarm_chk4()
{
		for(cur4=17;cur4<37;cur4++)
	{
ahour=EEPROM_ReadByte(memo1[cur4]);
		cur4++;
		amin=EEPROM_ReadByte(memo1[cur4]);
		asec=00;
 if(hour==ahour)
	 if(min==amin)
   if(sec==asec)
alarm_bell_LOW();
else
rly=0;
}

	
}








void alarm_bell_HI()
{
	Lcd8_Command(0x01);

	Lcd8_Display(0xc0,"Bell ringing.. ",14);

rly=1;
  delay_ms(20000);            

rly=0;
	 Delay(65000);
   Delay(65000);

		 Lcd8_Command(0x01);

}

void alarm_bell_LOW()
{
			 Lcd8_Command(0x01);

		Lcd8_Display(0xc0,"Bell ringing.. ",14);

rly=1;
delay_ms(5000);            
rly=0;
	
	 Delay(65000);
   Delay(65000);

		 Lcd8_Command(0x01);

}












void Lcd8_Init()
{
Lcd8_Command(0x38); //to select function set
Lcd8_Command(0x06); //entry mode set
Lcd8_Command(0x0c); //display on
Lcd8_Command(0x01); //clear display
}

void Lcd8_Command(unsigned char com)
{
Data_Port=com;
Lcd_en=1;
Lcd_rs=0;
//Lcd_rw=0;

Delay(125);
Lcd_en=0;
Delay(125);
}

void Lcd8_Write(unsigned char com,unsigned char lr)
{
Lcd8_Command(com);
Data_Port=lr; // Data 
Lcd_en=Lcd_rs=1;
//Lcd_rw=0;
Delay(125);
Lcd_en=0;
Delay(125);
}

void Lcd8_Display(unsigned char com,const unsigned char *word,unsigned int n)
{
unsigned char Lcd_i;
for(Lcd_i=0;Lcd_i<n;Lcd_i++)
{ 
Lcd8_Write(com+Lcd_i,word[Lcd_i]);
}
}

void Lcd8_decimal2(unsigned char com,unsigned char val)
{
unsigned int Lcd_hr,Lcd_t,Lcd_o;

Lcd_hr=val%100;
Lcd_t=Lcd_hr/10;
Lcd_o=Lcd_hr%10;

Lcd8_Write(com,Lcd_t+0x30);
Lcd8_Write(com+1,Lcd_o+0x30);
}



void Delay(unsigned int del)
{
while(del--);
}



void Seg8_decimal2(min)

{
unsigned int Lcd_hr,Lcd_t,Lcd_o;

Lcd_hr=min%100;
Lcd_t=Lcd_hr/10;
Lcd_o=Lcd_hr%10;
e5=0;
P3=Lcd_t+0x30;
e5=1;
e6=0;
P3=Lcd_o+0x30;
e6=1;

}







void Led8decimal2(hour)
{
unsigned int Lcd_hr,Lcd_t,Lcd_o;

Lcd_hr=hour%100;
Lcd_t=Lcd_hr/10;
Lcd_o=Lcd_hr%10;
e4=0;
P3=Lcd_t+0x30;
e4=1;
e3=0;
P3=Lcd_o+0x30;
e3=1;
}


/*********************************LCD HEADER FILE END*************************************/



/*********************************RTC HEADER FILE START*********************************/


DS1307_get(unsigned char addr)
{
unsigned char ret;

Rtc_Start(); 
ret = Rtc_Read(addr);
Rtc_Stop();

return ret;
}

void DS1307_settime(unsigned char hh, unsigned char mm, unsigned char ss)
{
Rtc_Start(); 

Rtc_Write(0x00,ss); /* Write sec on RAM address 00H */
Rtc_Write(0x01,mm); /* Write min on RAM address 01H */
Rtc_Write(0x02,hh); /* Write hour on RAM address 02H */
	hh=hh& 0x1f;

Rtc_Stop(); /* Stop i2c bus */

}


void DS1307_setdate(unsigned char dd, unsigned char mm, unsigned char yy,unsigned char day)
{
Rtc_Start();

Rtc_Write(0x04,dd); /* Write date on RAM address 04H */
Rtc_Write(0x05,mm); /* Write month on RAM address 05H */
Rtc_Write(0x06,yy); /* Write year on RAM address 06H */
Rtc_Write(0x03,day); /* Write year on RAM address 03H */


Rtc_Stop(); /* Stop i2c bus */
}


Send2lcd(unsigned char value)
{
unsigned char buf1,buf2,buf = 0;

buf1 = value & 0xF0; /* Filter for high byte */
buf1 = (buf1>>4); /* Convert to ascii code */
buf2 = value & 0x0F; /* Filter for low byte */
buf=(buf1*10)+buf2;

return buf;
}


void Rtc_Init()//lower order 256 bytes of the chip
{
Rtc_add_wr=0xd0;
Rtc_add_rd=0xd1;
}


void Rtc_Write(unsigned char zig,unsigned char zag)// program to write to EEPROM
{
dat_rtc=zig;
temp_rtc=zag;
Rtc_rd_wr_sub();
above:
d_rtc=temp_rtc;
Rtc_Tx();
if (CY==1)goto above;
CY=0;
Rtc_Stop();
}


Rtc_Read(unsigned char zig)// program to read from EEPROM
{
dat_rtc=zig;
Rtc_rd_wr_sub();
Rtc_Start();
be:
d_rtc=Rtc_add_rd; // 0xd1 =Rtc_add_rd
Rtc_Tx();
if(CY==1)goto be;
Rtc_Rx();
Rtc_Ack();
CY=0;
Rtc_Stop();
return(datain_rtc);
}


void Rtc_Start()// must for any operation on EEPROM
{
sda_rtc=1;
scl_rtc=1;
sda_rtc=0;
scl_rtc=0;
}


void Rtc_Stop()// this is similar to the START operation whereas this should be performed after the completion of any operation
{
sda_rtc=0;
scl_rtc=1;
sda_rtc=1;
}


void Rtc_Tx()// program to send the device address, read/write address,data to be written
{
signed char i_rtc;
for(i_rtc=7;i_rtc>=0;i_rtc--)// should necessarily be initialised as signed char.
{
CY=(d_rtc>>i_rtc)&0x01;
sda_rtc=CY;
scl_rtc=1;// clock is essential inorder to write or read
scl_rtc=0;// clk should be alternated
}
sda_rtc=1;
scl_rtc=1;
CY=sda_rtc;
scl_rtc=0;
}


void Rtc_Rx()// program read the data from the EEPROM
{
unsigned char l_rtc;
sda_rtc=1;
for (l_rtc=0;l_rtc<=7;l_rtc++)
{
scl_rtc=1;
in_rtc=in_rtc<<1;
in_rtc|=sda_rtc;
scl_rtc=0;
}
datain_rtc=in_rtc;
in_rtc=0;
}


void Rtc_Ack()// this is to intimate the EEPROM that the read operation is over
{
sda_rtc=1;
scl_rtc=1;
scl_rtc=0;
}


void Rtc_rd_wr_sub()// this routine will be used by both the read & write operations to send the device address & the address at which the corresponding action is to be taken
{
Rtc_Start();
here1:
d_rtc=Rtc_add_wr;// 0xd0 device address is passed
Rtc_Tx();
if(CY==1)goto here1;
again1:
d_rtc=dat_rtc;// the address from which data is to be read/written is to be passed
Rtc_Tx();
if(CY==1)goto again1;
}

void EEPROM_WriteByte(unsigned char eeprom_Address, unsigned char eeprom_Data)
{
 
    I2C_Start();               // Start i2c communication
    I2C_Write(EEPROM_ID);      // connect to AT2404 by sending its ID on I2c Bus
    I2C_Ack();
    I2C_Write(eeprom_Address); // Select the Specified EEPROM address of AT2404
    I2C_Ack();
    I2C_Write(eeprom_Data);    // Write the data at specified address
    I2C_Ack();
    I2C_Stop();                // Stop i2c communication after Writing the data
    delay_ms(1);            // Write operation takes max 5ms, refer At2404 datasheet        
}
 
unsigned char EEPROM_ReadByte(unsigned char eeprom_Address)
{
  unsigned char eeprom_Data;
 
    I2C_Start();               // Start i2c communication
    I2C_Write(EEPROM_ID);      // connect to AT2404(write) by sending its ID on I2c Bus
    I2C_Ack();
    I2C_Write(eeprom_Address); // Select the Specified EEPROM address of AT2404
    I2C_Ack();
 
    I2C_Start();               // Start i2c communication
    I2C_Write(0xA1);           // connect to AT2404(read) by sending its ID on I2c Bus
    I2C_Ack();
   eeprom_Data = I2C_Read();  // Read the data from specified address
    I2C_NoAck();
    I2C_Stop();                // Stop i2c communication after Reading the data
    delay_us(10);
  return eeprom_Data;          // Return the Read data
 
}
void I2C_Start()
{
    SCL = 0;        // Pull SCL low
 
    SDA = 1;        // Pull SDA High
    delay_us(1);
 
    SCL = 1;        //Pull SCL high
    delay_us(1);
 
    SDA = 0;        //Now Pull SDA LOW, to generate the Start Condition
    delay_us(1);
 
    SCL = 0;        //Finally Clear the SCL to complete the cycle
}

void I2C_Stop(void)
{
    SCL = 0;            // Pull SCL low
    delay_us(1);
 
    SDA = 0;            // Pull SDA  low
    delay_us(1);
 
    SCL = 1;            // Pull SCL High
    delay_us(1);
 
    SDA = 1;            // Now Pull SDA High, to generate the Stop Condition
}

void I2C_Ack()
{
    SDA = 0;        //Pull SDA low to indicate Positive ACK
    I2C_Clock();    //Generate the Clock
    SDA = 1;        // Pull SDA back to High(IDLE state)
}

void I2C_NoAck()
{
    SDA = 1;        //Pull SDA high to indicate Negative/NO ACK
   I2C_Clock();     // Generate the Clock  
    SCL = 1;        // Set SCL */
}

void I2C_Write(unsigned char dat)
{
    unsigned char i;
 
    for(i=0;i<8;i++)         // loop 8 times to send 1-byte of data
     {
        SDA = dat & 0x80;    // Send Bit by Bit on SDA line
        I2C_Clock();         // Generate Clock at SCL
        dat = dat<<1;
      }
        SDA = 1;                 // Set SDA at last
}
 

unsigned char I2C_Read(void)
{
    unsigned char i, dat=0x00;
 
       SDA=1;               //Make SDA as I/P
    for(i=0;i<8;i++)        // loop 8times to read 1-byte of data
     {
       delay_us(1);
        SCL = 1;            // Pull SCL High
        delay_us(1);
 
        dat = dat<<1;       //dat is Shifted each time and
        dat = dat | SDA;    //ORed with the received bit to pack into byte
 
        SCL = 0;            // Clear SCL to complete the Clock
       }
   return dat;               // Finally return the received Byte*
}
 
 void delay_ms(unsigned int ms_count)
 {
        while(ms_count!=0)
         {
            delay_us(112);   //delay_us is called to generate 1ms delay
             ms_count--;
         }
   }
 

  void delay_us(unsigned int us_count)
 {  
    while(us_count!=0)
      {
         us_count--;
       }												   
   }
 
 void I2C_Clock(void)
{
    delay_us(1);
    SCL = 1;        // Wait for Some time and Pull the SCL line High
 
    delay_us(1);        // Wait for Some time
    SCL = 0;        // Pull back the SCL line low to Generate a clock pulse
}
A.circuit.jpgeeprom 24c04.JPG


I made array for seriel memory address in line 194 & 195 of code
 
Last edited by a moderator:

Hi,

your schematic symbol does not match with the datasheet.

--> read the datasheet
it says:
2.3 Chip Enable (E1, E2)
These input signals are used to set the value that is to be looked for on the two bits (b3, b2)
of the 7-bit device select code. These inputs must be tied to VCC or VSS to establish the
device select code as shown in Table 2. When not connected (left floating), these inputs are
read as low (0,0).

your code says:
SDA = 1; // Pull SDA High
...

SCL = 1; //Pull SCL high
--> Don´t ever drive I2C signals actively high. This has been discussed many times here. If your microcontroller supports HIGH-Z, then please use it.

***
dat = dat | SDA --> please check if this command is valid, because "dat" is a byte", whereas "SDA" is a bit only
SDA = dat & 0x80 --> please check if this command is valid, because "dat" is a byte", whereas "SDA" is a bit only

Klaus

- - - Updated - - -

Added:

General rule:
Don´t leave any unused input floating. No analog inputs and no digital inputs.
Especially in your schematic: all the ´574 ICs. The "LS" types won´t be that critical, but for the "HC" one it is a "no go".
(I wonder why there are 3 old fashioned "LS" types and one "HC" type...)

Klaus
 
  • Like
Reactions: tapu

    tapu

    Points: 2
    Helpful Answer Positive Rating
Thank you for replying betwixt & klausSt.
Here I inform you that same design works successfully with old 24c04(other brand).
 

Hi,

do you have a scop to trace the communicatio for both old and new device?

Klaus
 

Design is working since One year.but now I observed this error by purchasing new memory ic.eigther it is a defective device error or I have to change code according to new chip?
 

Thank you for helping.I am changing my design acording to datasheet of st24c04.
 

Dear all,
I have read datasheet of st24C04.But iam new in design I make connection as follow but again same error observed.
st24c04 circuit.JPG

Please reply.
 

Hi,

Please show a scope picture of a failed "read from 2404" communication.

Klaus
 

Hi,

A scope picture of your I2C communication.
2 Channels: SCL, SDA

Klaus
 

Dear sir, I do'nt have oscilloscope to observe waveform pictures.
Data sheet of at24C04 & st24C04 shows some difference between them.I am importing previous AT24C04 which was working.but how to make ST24C04 usefull.
 

The ST version has a maximim I2C SCL frequency of 100KHz but the Atmel device is specified to 400KHz, maybe that is the difference. Other than that, the two devices are virtually identical.

I assume you have the address pins set to some sensible fixed levels or the device address may be unstable.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top