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.

[SOLVED] problom in loading program on 89c52.

Status
Not open for further replies.
Yes hex file is same.
you need to select the particular controller in compiler while building the hex file.for example if for 89c51 select the device 89c51 if you using keil. and do same for rest of two and try to load the respective hex generated for same device.
 

Thank you for replies.I will select in keil then load.
 

I wonder if the problem explanations in this thread are right.

If you get
''write...error at:0000:FF''
it means that the programmer already fails to program the very first flash location (reset code) to a non-blank value.

This won't depend on having code for a different x51 chip, the chip not or not completely erased etc. It just means total programming failure, either defective programmer, defective or unsupported chip, chip wrongly inserted, whatsoever.

Getting apparent programming success when arbitrarily selecting a different chip must not mean much.

Similarly, a code compiled for 8051 would run on a downwards compatible chip like 8052 or 8055.
 
  • Like
Reactions: ud23

    ud23

    Points: 2
    Helpful Answer Positive Rating
Hello FvM,Here both 89c52 & 89c55 chips are new purchased & shows same error. I think both controller can't be defective.
 

The program does not run in actual board in 89c52 which is 6.7kb.But running successfully in proteus-simulation. another testing program(2.1kb) is running on board in same chip.
 

what do you mean by not working ? check your hardware(board) and Proteus simulation connections are same.
 

Both connections are same.As I load testing code then board runs same to simulation.But my actual project does not run on board.
 

show us your schematic and protus circuit to help you.
 

Dear ud.Here I uploaded both files.You may check. View attachment zak.jpeg zak1.jpeg
 

The program does not run in actual board in 89c52 which is 6.7kb.But running successfully in proteus-simulation. another testing program(2.1kb) is running on board in same chip.Both connections are same.As I load testing code then runs on board & simulate.But my actual project does not run on board.schematic have uploaded in previous post.
 

Dear all,

Acording to the previous post please reply that what is a problom.

thanks & regards,
tapu
 

your both circuit looks ok. check your real hardware connection.loose wire ,dry solder or faulty IC.many reason debug it.
 

Dear sir,Hardware is verified & tested by another sample program of 2.1kb.But Actual program which is 6.7kb does not run.will you check code?Or I have to change setting of keil for 6.7kb code?
 

Hardware is verified & tested by another sample program of 2.1kb

we don't know what is your sample program which part you tested?and If your device selection and clock setting fine i don't think code size matters up to 8kb.

will you check code

you don't post your code yet.
 

I have set clock to 11.0592 mhz & selected 89c52 in keil.

- - - Updated - - -

I have selected 89c52 & set clock to 11.0592 in keil for 6.7kb of code.is it OK? & I selected 89LS52 in programmer & write.
 
Last edited:

Try to load the code with same device selection and program and try to load program using other programmer and other IC and check.If it is working fine in simulation and hardware tested ok then no problem with code then their is problem with programmer as already suggested respected FvM sir try to load with other controller IC or new programmer.
 

Dear sir acording to fvm sir device can be defective i will check programmer also.then Now i load my program in AT89c55 then LCD shows initial message as on program but keypad is not working.As I have checked connection of switches which is according to code.

- - - Updated - - -
 

zip and post your code you are testing.
 

Here I post a code which is working in proteus but in board keypad is not working & lcd shows initial message according to cod .As connections are checked which according to program.please reply.


Code:
#include <REGX55.H>



sbit set=P1^0;
sbit mov=P1^1;
sbit inc=P1^2;
sbit rly=P1^3;
sbit ent=P1^4;
sbit e5=P1^5;//3rd e5
sbit e6=P2^3;//4th	e6

sbit e4=P1^7;//1st e4
sbit e3=P1^6;//2nd e3
sbit SDA=P2^6;
sbit SCL=P2^7;


sbit alarmset=P3^7;

void all_disp();
void time_set();

void alarm_set1();
void alarm_set2();
void alarm_set3();
void alarm_set4();
void alarm_set5();
void alarm_set6();
void alarm_set7();
void alarm_set8();


void alarm_chk1();
void alarm_chk2();

void alarm_ring_HI();
void alarm_ring_LOW();
void display_day();




#define First_Line 0x80
#define Second_Line 0xc0
#define Curser_On 0x0f
#define Curser_Off 0x0c
#define Clear_Display 0x01

#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);
void Delay(unsigned int);
void del();

 bit f;
void Seg8_decimal2(min);

void Led8decimal2(hour);
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);




#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 friday 6



DS1307_get(unsigned char);
void DS1307_settime(unsigned char, unsigned char, unsigned char);
void DS1307_setdate(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();

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;
unsigned char sec,hour,min,date,day,month,year,sec1,hour1,min1,sec2,hour2,min2,hh,mm,ss,dd,mn,yy,ahour,amin,asec,amin1,ahour1,ahour2,amin2,ahour3,amin3;
unsigned char amin4,ahour4,ahour5,amin5,amin6,ahour6,ahour7,amin7,ahour8,amin8,ahour9,amin9,amin10,ahour10,ahour11,amin11; 

unsigned char count[8]={0x82,0x85,0x8a,0x8d,0xc2,0xc5,0xca,0xcd};

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);
date = DS1307_get(DATE);
day = DS1307_get(DAY);
month = DS1307_get(MONTH);
year = DS1307_get(YEAR);
min=Send2lcd(min);
hour=Send2lcd(hour);
day=Send2lcd(day);

Seg8_decimal2(min);
Led8decimal2(hour);
display_day();



}
void main()
{

Lcd8_Init();
Lcd8_Display(0x80,"RTC TESTING: ",12);
Delay(65000);
Delay(65000);
Lcd8_Command(0x01);
Lcd8_Display(0xc0,"alarm can set:",14);
Rtc_Init();

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

while(1)
{


all_disp();
if(day==friday)
alarm_chk2();
else
alarm_chk1();

if(!set)
time_set();
if(alarmset==1)
{
alarm_set1();
alarm_set2();
alarm_set3();
alarm_set4();
alarm_set5();
alarm_set6();
alarm_set7();
alarm_set8();

}
}
}

void display_day()
{

 if(day==0x01)
Lcd8_Display(0x84,"SUNDAY: ",7);

 if(day==0x02)
Lcd8_Display(0x84,"MONDAY: ",7);
 if(day==0x03)
Lcd8_Display(0x84,"TUESDAY: ",8);
 if(day==0x04)
Lcd8_Display(0x84,"WEDNESDAY: ",9);
 if(day==0x05)
Lcd8_Display(0x84,"THURSDAY: ",8);
 if(day==0x06)
Lcd8_Display(0x84,"FRIDAY: ",6);
 if(day==0x07)
Lcd8_Display(0x84,"SATURDAY: ",8);

}


void time_set()
{
all_disp();
cur=1;
while(ent)
{
if(mov==0)
{
while(!mov);
cur++;
if(cur==2)
cur=0;
}


else if(count[cur]==0x82)
{
if(inc==0)
{
while(inc==0);
hour++;
Led8decimal2(hour);

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

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

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

}
									


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

DS1307_settime(hh,mm,ss);
DS1307_setdate(dd,mn,yy); 
}














void alarm_set1()
{


 Lcd8_Command(0x01);
 Lcd8_Display(0x84,"NOW set",7);
 Lcd8_Display(0xc0,"Regular schedule",17);
 Delay(65000);
 Delay(65000);
 Lcd8_Command(0x01);
 Lcd8_Display(0xc0,"Long ringl times",15);
  Delay(65000);
  Delay(65000);

 
  Lcd8_Command(0x01);
  Lcd8_Display(0x80,"1:",2);
  Lcd8_decimal2(0x82,ahour);
  Lcd8_decimal2(0x85,amin);
  Lcd8_Display(0x88,"2:",2);
  Lcd8_decimal2(0x8a,ahour1);
  Lcd8_decimal2(0x8d,amin1);

  Lcd8_Display(0xc0,"3:",2);
  Lcd8_decimal2(0xc2,ahour2);
  Lcd8_decimal2(0xc5,amin2);
  Lcd8_Display(0xc8,"4:",2);
  Lcd8_decimal2(0xca,ahour3);
  Lcd8_decimal2(0xcd,amin3);

cur=0;

while(ent)
{
Lcd8_Command(0x0f);
Lcd8_Command(count[cur]);
if(mov==0)
{
while(!mov);
cur++;
if(cur==8)
cur=0;
}
else if(count[cur]==0x82)			                    ///1st line of lcd
{
if(inc==0)
{
while(inc==0);
ahour++;
if(ahour>=24)
ahour=0;
Lcd8_decimal2(count[cur],ahour);
}
}
else if(count[cur]==0x85)
{
if(inc==0)
{
while(inc==0);
amin++;
if(amin>=60)
amin=0;
Lcd8_decimal2(count[cur],amin);
}
}
else if(count[cur]==0x8a)
{
if(inc==0)
{
while(inc==0);
ahour1++;
if(ahour1>=60)
ahour1=0;
Lcd8_decimal2(count[cur],ahour1);
}
}
else if(count[cur]==0x8d)
{
if(inc==0)
{
while(inc==0);
amin1++;
if(amin1>=60)
amin1=0;
Lcd8_decimal2(count[cur],amin1);
}
}
else if(count[cur]==0xc2)
{
if(inc==0)
{
while(inc==0);
ahour2++;
if(ahour2>=60)
ahour2=0;
Lcd8_decimal2(count[cur],ahour2);
}
}
else if(count[cur]==0xc5)
{
if(inc==0)
{
while(inc==0);
amin2++;
if(amin2>=60)
amin2=0;
Lcd8_decimal2(count[cur],amin2);
}
}
else if(count[cur]==0xca)
{
if(inc==0)
{
while(inc==0);
ahour3++;
if(ahour3>=60)
ahour3=0;
Lcd8_decimal2(count[cur],ahour3);
}
}
else if(count[cur]==0xcd)
{
if(inc==0)
{
while(inc==0);
amin3++;
if(amin3>=60)
amin3=0;
Lcd8_decimal2(count[cur],amin3);
}
}

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

 EEPROM_WriteByte(0x01, ahour);
 EEPROM_WriteByte(0x02, amin);
 EEPROM_WriteByte(0x03, ahour1);
 EEPROM_WriteByte(0x04, amin1);
 EEPROM_WriteByte(0x05, ahour2);
 EEPROM_WriteByte(0x06, amin2);
 EEPROM_WriteByte(0x07, ahour3);
 EEPROM_WriteByte(0x08, amin3);

 Lcd8_Command(0x01);	                                       

}
void alarm_set2()
{
ahour4=EEPROM_ReadByte(0x09);
 amin4=EEPROM_ReadByte(0x10);
ahour5=EEPROM_ReadByte(0x11);
 amin5=EEPROM_ReadByte(0x12);

  Lcd8_Command(0x01);
  Lcd8_Display(0x80,"5:",2);
  Lcd8_decimal2(0x82,ahour4);
  Lcd8_decimal2(0x85,amin4);
  Lcd8_Display(0x88,"6:",2);
  Lcd8_decimal2(0x8a,ahour5);
  Lcd8_decimal2(0x8d,amin5);

 cur=0;

while(ent)
{
Lcd8_Command(0x0f);
Lcd8_Command(count[cur]);
if(mov==0)
{
while(!mov);
cur++;
if(cur==8)
cur=0;
}
else if(count[cur]==0x82)			                    ///1st line of lcd
{
if(inc==0)
{
while(inc==0);
ahour4++;
if(ahour4>=24)
ahour4=0;
Lcd8_decimal2(count[cur],ahour4);
}
}
else if(count[cur]==0x85)
{
if(inc==0)
{
while(inc==0);
amin4++;
if(amin4>=60)
amin4=0;
Lcd8_decimal2(count[cur],amin4);
}
}
else if(count[cur]==0x8a)
{
if(inc==0)
{
while(inc==0);
ahour5++;
if(ahour5>=60)
ahour5=0;
Lcd8_decimal2(count[cur],ahour5);
}
}
else if(count[cur]==0x8d)
{
if(inc==0)
{
while(inc==0);
amin5++;
if(amin5>=60)
amin5=0;
Lcd8_decimal2(count[cur],amin5);
}
}
}

Lcd8_Command(0x0c);
Delay(65000);Delay(65000);

 EEPROM_WriteByte(0x09, ahour4);
 EEPROM_WriteByte(0x10, amin4);
 EEPROM_WriteByte(0x11, ahour5);
 EEPROM_WriteByte(0x12, amin5);
  Lcd8_Command(0x01);	                                       

}
void alarm_set3()
{
ahour6=EEPROM_ReadByte(0x13);
 amin6=EEPROM_ReadByte(0x14);
ahour7=EEPROM_ReadByte(0x15);
 amin7=EEPROM_ReadByte(0x16);
ahour8=EEPROM_ReadByte(0x17);
 amin8=EEPROM_ReadByte(0x18);
ahour9=EEPROM_ReadByte(0x19);
 amin9=EEPROM_ReadByte(0x20);

 Lcd8_Command(0x01);
 Lcd8_Display(0xc0,"short ringl times",15);
  Delay(65000);
  Delay(65000);

 
  Lcd8_Command(0x01);
  Lcd8_Display(0x80,"1:",2);
  Lcd8_decimal2(0x82,ahour6);
  Lcd8_decimal2(0x85,amin6);
  Lcd8_Display(0x88,"2:",2);
  Lcd8_decimal2(0x8a,ahour7);
  Lcd8_decimal2(0x8d,amin7);

  Lcd8_Display(0xc0,"3:",2);
  Lcd8_decimal2(0xc2,ahour8);
  Lcd8_decimal2(0xc5,amin8);
  Lcd8_Display(0xc8,"4:",2);
  Lcd8_decimal2(0xca,ahour9);
  Lcd8_decimal2(0xcd,amin9);

cur=0;

while(ent)
{
Lcd8_Command(0x0f);
Lcd8_Command(count[cur]);
if(mov==0)
{
while(!mov);
cur++;
if(cur==8)
cur=0;
}
else if(count[cur]==0x82)			                    ///1st line of lcd
{
if(inc==0)
{
while(inc==0);
ahour6++;
if(ahour6>=24)
ahour6=0;
Lcd8_decimal2(count[cur],ahour6);
}
}
else if(count[cur]==0x85)
{
if(inc==0)
{
while(inc==0);
amin6++;
if(amin6>=60)
amin6=0;
Lcd8_decimal2(count[cur],amin6);
}
}
else if(count[cur]==0x8a)
{
if(inc==0)
{
while(inc==0);
ahour7++;
if(ahour7>=60)
ahour7=0;
Lcd8_decimal2(count[cur],ahour7);
}
}
else if(count[cur]==0x8d)
{
if(inc==0)
{
while(inc==0);
amin7++;
if(amin7>=60)
amin7=0;
Lcd8_decimal2(count[cur],amin7);
}
}
else if(count[cur]==0xc2)
{
if(inc==0)
{
while(inc==0);
ahour8++;
if(ahour8>=60)
ahour8=0;
Lcd8_decimal2(count[cur],ahour8);
}
}
else if(count[cur]==0xc5)
{
if(inc==0)
{
while(inc==0);
amin8++;
if(amin8>=60)
amin8=0;
Lcd8_decimal2(count[cur],amin8);
}
}
else if(count[cur]==0xca)
{
if(inc==0)
{
while(inc==0);
ahour9++;
if(ahour9>=60)
ahour9=0;
Lcd8_decimal2(count[cur],ahour9);
}
}
else if(count[cur]==0xcd)
{
if(inc==0)
{
while(inc==0);
amin9++;
if(amin9>=60)
amin9=0;
Lcd8_decimal2(count[cur],amin9);
}
}

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

 EEPROM_WriteByte(0x13, ahour6);
 EEPROM_WriteByte(0x14, amin6);
 EEPROM_WriteByte(0x15, ahour7);
 EEPROM_WriteByte(0x16, amin7);
 EEPROM_WriteByte(0x17, ahour8);
 EEPROM_WriteByte(0x18, amin8);
 EEPROM_WriteByte(0x19, ahour9);
 EEPROM_WriteByte(0x20, amin9);

 Lcd8_Command(0x01);	                                       

}

 void alarm_set4()
{
ahour10=EEPROM_ReadByte(0x21);
 amin10=EEPROM_ReadByte(0x22);
ahour11=EEPROM_ReadByte(0x23);
 amin11=EEPROM_ReadByte(0x24);

{
  Lcd8_Command(0x01);
  Lcd8_Display(0x80,"5:",2);
  Lcd8_decimal2(0x82,ahour10);
  Lcd8_decimal2(0x85,amin10);
  Lcd8_Display(0x88,"6:",2);
  Lcd8_decimal2(0x8a,ahour11);
  Lcd8_decimal2(0x8d,amin11);

 cur=0;

while(ent)
{
Lcd8_Command(0x0f);
Lcd8_Command(count[cur]);
if(mov==0)
{
while(!mov);
cur++;
if(cur==8)
cur=0;
}
else if(count[cur]==0x82)			                    ///1st line of lcd
{
if(inc==0)
{
while(inc==0);
ahour10++;
if(ahour10>=24)
ahour10=0;
Lcd8_decimal2(count[cur],ahour10);
}
}
else if(count[cur]==0x85)
{
if(inc==0)
{
while(inc==0);
amin10++;
if(amin11>=60)
amin10=0;
Lcd8_decimal2(count[cur],amin10);
}
}
else if(count[cur]==0x8a)
{
if(inc==0)
{
while(inc==0);
ahour11++;
if(ahour11>=60)
ahour11=0;
Lcd8_decimal2(count[cur],ahour11);
}
}
else if(count[cur]==0x8d)
{
if(inc==0)
{
while(inc==0);
amin11++;
if(amin11>=60)
amin11=0;
Lcd8_decimal2(count[cur],amin11);
}
}
}
}
Lcd8_Command(0x0c);
Delay(65000);Delay(65000);

 EEPROM_WriteByte(0x21, ahour10);
 EEPROM_WriteByte(0x22, amin10);
 EEPROM_WriteByte(0x23, ahour11);
 EEPROM_WriteByte(0x24, amin11);
  Lcd8_Command(0x01);	                                       

}



void alarm_set5()
{

ahour=EEPROM_ReadByte(0x25);
 amin=EEPROM_ReadByte(0x26);
ahour1=EEPROM_ReadByte(0x27);
 amin1=EEPROM_ReadByte(0x28);
ahour2=EEPROM_ReadByte(0x29);
 amin2=EEPROM_ReadByte(0x30);
ahour3=EEPROM_ReadByte(0x31);
 amin3=EEPROM_ReadByte(0x32);


 Lcd8_Command(0x01);
 Lcd8_Display(0x84,"NOW set",7);
 Lcd8_Display(0xc0,"Regular schedule",17);
 Delay(65000);
 Delay(65000);
 Lcd8_Command(0x01);
 Lcd8_Display(0xc0,"Long ringl times",15);
  Delay(65000);
  Delay(65000);

 
  Lcd8_Command(0x01);
  Lcd8_Display(0x80,"1:",2);
  Lcd8_decimal2(0x82,ahour);
  Lcd8_decimal2(0x85,amin);
  Lcd8_Display(0x88,"2:",2);
  Lcd8_decimal2(0x8a,ahour1);
  Lcd8_decimal2(0x8d,amin1);

  Lcd8_Display(0xc0,"3:",2);
  Lcd8_decimal2(0xc2,ahour2);
  Lcd8_decimal2(0xc5,amin2);
  Lcd8_Display(0xc8,"4:",2);
  Lcd8_decimal2(0xca,ahour3);
  Lcd8_decimal2(0xcd,amin3);

cur=0;

while(ent)
{
Lcd8_Command(0x0f);
Lcd8_Command(count[cur]);
if(mov==0)
{
while(!mov);
cur++;
if(cur==8)
cur=0;
}
else if(count[cur]==0x82)			                    ///1st line of lcd
{
if(inc==0)
{
while(inc==0);
ahour++;
if(ahour>=24)
ahour=0;
Lcd8_decimal2(count[cur],ahour);
}
}
else if(count[cur]==0x85)
{
if(inc==0)
{
while(inc==0);
amin++;
if(amin>=60)
amin=0;
Lcd8_decimal2(count[cur],amin);
}
}
else if(count[cur]==0x8a)
{
if(inc==0)
{
while(inc==0);
ahour1++;
if(ahour1>=60)
ahour1=0;
Lcd8_decimal2(count[cur],ahour1);
}
}
else if(count[cur]==0x8d)
{
if(inc==0)
{
while(inc==0);
amin1++;
if(amin1>=60)
amin1=0;
Lcd8_decimal2(count[cur],amin1);
}
}
else if(count[cur]==0xc2)
{
if(inc==0)
{
while(inc==0);
ahour2++;
if(ahour2>=60)
ahour2=0;
Lcd8_decimal2(count[cur],ahour2);
}
}
else if(count[cur]==0xc5)
{
if(inc==0)
{
while(inc==0);
amin2++;
if(amin2>=60)
amin2=0;
Lcd8_decimal2(count[cur],amin2);
}
}
else if(count[cur]==0xca)
{
if(inc==0)
{
while(inc==0);
ahour3++;
if(ahour3>=60)
ahour3=0;
Lcd8_decimal2(count[cur],ahour3);
}
}
else if(count[cur]==0xcd)
{
if(inc==0)
{
while(inc==0);
amin3++;
if(amin3>=60)
amin3=0;
Lcd8_decimal2(count[cur],amin3);
}
}

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

 EEPROM_WriteByte(0x25, ahour);
 EEPROM_WriteByte(0x26, amin);
 EEPROM_WriteByte(0x27, ahour1);
 EEPROM_WriteByte(0x28, amin1);
 EEPROM_WriteByte(0x29, ahour2);
 EEPROM_WriteByte(0x30, amin2);
 EEPROM_WriteByte(0x31, ahour3);
 EEPROM_WriteByte(0x32, amin3);

 Lcd8_Command(0x01);	                                       

}
void alarm_set6()
{
ahour4=EEPROM_ReadByte(0x33);
 amin4=EEPROM_ReadByte(0x34);
ahour5=EEPROM_ReadByte(0x35);
 amin5=EEPROM_ReadByte(0x36);

  Lcd8_Command(0x01);
  Lcd8_Display(0x80,"5:",2);
  Lcd8_decimal2(0x82,ahour4);
  Lcd8_decimal2(0x85,amin4);
  Lcd8_Display(0x88,"6:",2);
  Lcd8_decimal2(0x8a,ahour5);
  Lcd8_decimal2(0x8d,amin5);

 cur=0;

while(ent)
{
Lcd8_Command(0x0f);
Lcd8_Command(count[cur]);
if(mov==0)
{
while(!mov);
cur++;
if(cur==8)
cur=0;
}
else if(count[cur]==0x82)			                    ///1st line of lcd
{
if(inc==0)
{
while(inc==0);
ahour4++;
if(ahour4>=24)
ahour4=0;
Lcd8_decimal2(count[cur],ahour4);
}
}
else if(count[cur]==0x85)
{
if(inc==0)
{
while(inc==0);
amin4++;
if(amin4>=60)
amin4=0;
Lcd8_decimal2(count[cur],amin4);
}
}
else if(count[cur]==0x8a)
{
if(inc==0)
{
while(inc==0);
ahour5++;
if(ahour5>=60)
ahour5=0;
Lcd8_decimal2(count[cur],ahour5);
}
}
else if(count[cur]==0x8d)
{
if(inc==0)
{
while(inc==0);
amin5++;
if(amin5>=60)
amin5=0;
Lcd8_decimal2(count[cur],amin5);
}
}
}

Lcd8_Command(0x0c);
Delay(65000);Delay(65000);

 EEPROM_WriteByte(0x33, ahour4);
 EEPROM_WriteByte(0x34, amin4);
 EEPROM_WriteByte(0x35, ahour5);
 EEPROM_WriteByte(0x36, amin5);
  Lcd8_Command(0x01);	                                       

}
void alarm_set7()
{
ahour6=EEPROM_ReadByte(0x37);
 amin6=EEPROM_ReadByte(0x38);
ahour7=EEPROM_ReadByte(0x39);
 amin7=EEPROM_ReadByte(0x40);
ahour8=EEPROM_ReadByte(0x41);
 amin8=EEPROM_ReadByte(0x42);
ahour9=EEPROM_ReadByte(0x43);
 amin9=EEPROM_ReadByte(0x44);

 Lcd8_Command(0x01);
 Lcd8_Display(0xc0,"short ringl times",15);
  Delay(65000);
  Delay(65000);

 
  Lcd8_Command(0x01);
  Lcd8_Display(0x80,"1:",2);
  Lcd8_decimal2(0x82,ahour6);
  Lcd8_decimal2(0x85,amin6);
  Lcd8_Display(0x88,"2:",2);
  Lcd8_decimal2(0x8a,ahour7);
  Lcd8_decimal2(0x8d,amin7);

  Lcd8_Display(0xc0,"3:",2);
  Lcd8_decimal2(0xc2,ahour8);
  Lcd8_decimal2(0xc5,amin8);
  Lcd8_Display(0xc8,"4:",2);
  Lcd8_decimal2(0xca,ahour9);
  Lcd8_decimal2(0xcd,amin9);

cur=0;

while(ent)
{
Lcd8_Command(0x0f);
Lcd8_Command(count[cur]);
if(mov==0)
{
while(!mov);
cur++;
if(cur==8)
cur=0;
}
else if(count[cur]==0x82)			                    ///1st line of lcd
{
if(inc==0)
{
while(inc==0);
ahour6++;
if(ahour6>=24)
ahour6=0;
Lcd8_decimal2(count[cur],ahour6);
}
}
else if(count[cur]==0x85)
{
if(inc==0)
{
while(inc==0);
amin6++;
if(amin6>=60)
amin6=0;
Lcd8_decimal2(count[cur],amin6);
}
}
else if(count[cur]==0x8a)
{
if(inc==0)
{
while(inc==0);
ahour7++;
if(ahour7>=60)
ahour7=0;
Lcd8_decimal2(count[cur],ahour7);
}
}
else if(count[cur]==0x8d)
{
if(inc==0)
{
while(inc==0);
amin7++;
if(amin7>=60)
amin7=0;
Lcd8_decimal2(count[cur],amin7);
}
}
else if(count[cur]==0xc2)
{
if(inc==0)
{
while(inc==0);
ahour8++;
if(ahour8>=60)
ahour8=0;
Lcd8_decimal2(count[cur],ahour8);
}
}
else if(count[cur]==0xc5)
{
if(inc==0)
{
while(inc==0);
amin8++;
if(amin8>=60)
amin8=0;
Lcd8_decimal2(count[cur],amin8);
}
}
else if(count[cur]==0xca)
{
if(inc==0)
{
while(inc==0);
ahour9++;
if(ahour9>=60)
ahour9=0;
Lcd8_decimal2(count[cur],ahour9);
}
}
else if(count[cur]==0xcd)
{
if(inc==0)
{
while(inc==0);
amin9++;
if(amin9>=60)
amin9=0;
Lcd8_decimal2(count[cur],amin9);
}
}

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

 EEPROM_WriteByte(0x37, ahour6);
 EEPROM_WriteByte(0x38, amin6);
 EEPROM_WriteByte(0x39, ahour7);
 EEPROM_WriteByte(0x40, amin7);
 EEPROM_WriteByte(0x41, ahour8);
 EEPROM_WriteByte(0x42, amin8);
 EEPROM_WriteByte(0x43, ahour9);
 EEPROM_WriteByte(0x44, amin9);

 Lcd8_Command(0x01);	                                       

}

 void alarm_set8()
{
ahour10=EEPROM_ReadByte(0x45);
 amin10=EEPROM_ReadByte(0x46);
ahour11=EEPROM_ReadByte(0x47);
 amin11=EEPROM_ReadByte(0x48);

{
  Lcd8_Command(0x01);
  Lcd8_Display(0x80,"5:",2);
  Lcd8_decimal2(0x82,ahour10);
  Lcd8_decimal2(0x85,amin10);
  Lcd8_Display(0x88,"6:",2);
  Lcd8_decimal2(0x8a,ahour11);
  Lcd8_decimal2(0x8d,amin11);

 cur=0;

while(ent)
{
Lcd8_Command(0x0f);
Lcd8_Command(count[cur]);
if(mov==0)
{
while(!mov);
cur++;
if(cur==8)
cur=0;
}
else if(count[cur]==0x82)			                    ///1st line of lcd
{
if(inc==0)
{
while(inc==0);
ahour10++;
if(ahour10>=24)
ahour10=0;
Lcd8_decimal2(count[cur],ahour10);
}
}
else if(count[cur]==0x85)
{
if(inc==0)
{
while(inc==0);
amin10++;
if(amin11>=60)
amin10=0;
Lcd8_decimal2(count[cur],amin10);
}
}
else if(count[cur]==0x8a)
{
if(inc==0)
{
while(inc==0);
ahour11++;
if(ahour11>=60)
ahour11=0;
Lcd8_decimal2(count[cur],ahour11);
}
}
else if(count[cur]==0x8d)
{
if(inc==0)
{
while(inc==0);
amin11++;
if(amin11>=60)
amin11=0;
Lcd8_decimal2(count[cur],amin11);
}
}
}
}
Lcd8_Command(0x0c);
Delay(65000);Delay(65000);

 EEPROM_WriteByte(0x45, ahour10);
 EEPROM_WriteByte(0x46, amin10);
 EEPROM_WriteByte(0x47, ahour11);
 EEPROM_WriteByte(0x48, amin11);
  Lcd8_Command(0x01);	                                       

}





void alarm_chk1()
{
 ahour=EEPROM_ReadByte(0x01);
 amin=EEPROM_ReadByte(0x02);
 ahour1=EEPROM_ReadByte(0x03);
 amin1=EEPROM_ReadByte(0x04);
 ahour2=EEPROM_ReadByte(0x05);
 amin2=EEPROM_ReadByte(0x06);
 ahour3=EEPROM_ReadByte(0x07);
 amin3=EEPROM_ReadByte(0x08);
 ahour4=EEPROM_ReadByte(0x09);
 amin4=EEPROM_ReadByte(0x10);
 ahour5=EEPROM_ReadByte(0x11);
 amin5=EEPROM_ReadByte(0x12);
 ahour6=EEPROM_ReadByte(0x13);
 amin6=EEPROM_ReadByte(0x14);
 ahour7=EEPROM_ReadByte(0x15);
 amin7=EEPROM_ReadByte(0x16);
 ahour8=EEPROM_ReadByte(0x17);
 amin8=EEPROM_ReadByte(0x18);
 ahour9=EEPROM_ReadByte(0x19);
 amin9=EEPROM_ReadByte(0x20);
 ahour10=EEPROM_ReadByte(0x21);
 amin10=EEPROM_ReadByte(0x22);
 ahour11=EEPROM_ReadByte(0x23);
 amin11=EEPROM_ReadByte(0x24);



if(hour==ahour)
if(min==amin)
if(sec==asec)
alarm_ring_HI();
else
rly=1;

if(hour==ahour1)
if(min==amin1)
if(sec==asec)
alarm_ring_HI();
else
rly=1;
if(hour==ahour2)
if(min==amin2)
if(sec==asec)
alarm_ring_HI();
else
rly=1;
if(hour==ahour3)
if(min==amin3)
if(sec==asec)
alarm_ring_HI();
else
rly=1;
if(hour==ahour4)
if(min==amin4)
if(sec==asec)
alarm_ring_HI();
else
rly=1;
if(hour==ahour5)
if(min==amin5)
if(sec==asec)
alarm_ring_HI();
else
rly=1;
if(hour==ahour6)
if(min==amin6)
if(sec==asec)
alarm_ring_LOW();
else
rly=1;
if(hour==ahour7)
if(min==amin7)
if(sec==asec)
alarm_ring_LOW();
else
rly=1;
if(hour==ahour8)
if(min==amin8)
if(sec==asec)
alarm_ring_LOW();

else
rly=1;
if(hour==ahour9)
if(min==amin9)
if(sec==asec)
alarm_ring_LOW();

else
rly=1;
if(hour==ahour10)
if(min==amin10)
if(sec==asec)
alarm_ring_LOW();

else
rly=1;
if(hour==ahour11)
if(min==amin11)
if(sec==asec)
alarm_ring_LOW();

else
rly=1;


}

void alarm_chk2()
{
 ahour=EEPROM_ReadByte(0x25);
 amin=EEPROM_ReadByte(0x26);
 ahour1=EEPROM_ReadByte(0x27);
 amin1=EEPROM_ReadByte(0x28);
 ahour2=EEPROM_ReadByte(0x29);
 amin2=EEPROM_ReadByte(0x30);
 ahour3=EEPROM_ReadByte(0x31);
 amin3=EEPROM_ReadByte(0x32);
 ahour4=EEPROM_ReadByte(0x33);
 amin4=EEPROM_ReadByte(0x34);
 ahour5=EEPROM_ReadByte(0x35);
 amin5=EEPROM_ReadByte(0x36);
 ahour6=EEPROM_ReadByte(0x37);
 amin6=EEPROM_ReadByte(0x38);
 ahour7=EEPROM_ReadByte(0x39);
 amin7=EEPROM_ReadByte(0x40);
 ahour8=EEPROM_ReadByte(0x41);
 amin8=EEPROM_ReadByte(0x42);
 ahour9=EEPROM_ReadByte(0x43);
 amin9=EEPROM_ReadByte(0x44);
 ahour10=EEPROM_ReadByte(0x45);
 amin10=EEPROM_ReadByte(0x46);
 ahour11=EEPROM_ReadByte(0x47);
 amin11=EEPROM_ReadByte(0x48);

 if(hour==ahour)
if(min==amin)
if(sec==asec)
alarm_ring_HI();
else
rly=1;

if(hour==ahour1)
if(min==amin1)
if(sec==asec)
alarm_ring_HI();
else
rly=1;
if(hour==ahour2)
if(min==amin2)
if(sec==asec)
alarm_ring_HI();
else
rly=1;
if(hour==ahour3)
if(min==amin3)
if(sec==asec)
alarm_ring_HI();
else
rly=1;
if(hour==ahour4)
if(min==amin4)
if(sec==asec)
alarm_ring_HI();
else
rly=1;
if(hour==ahour5)
if(min==amin5)
if(sec==asec)
alarm_ring_HI();
else
rly=1;
if(hour==ahour6)
if(min==amin6)
if(sec==asec)
alarm_ring_LOW();
else
rly=1;
if(hour==ahour7)
if(min==amin7)
if(sec==asec)
alarm_ring_LOW();
else
rly=1;
if(hour==ahour8)
if(min==amin8)
if(sec==asec)
alarm_ring_LOW();

else
rly=1;
if(hour==ahour9)
if(min==amin9)
if(sec==asec)
alarm_ring_LOW();

else
rly=1;
if(hour==ahour10)
if(min==amin10)
if(sec==asec)
alarm_ring_LOW();

else
rly=1;
if(hour==ahour11)
if(min==amin11)
if(sec==asec)
alarm_ring_LOW();

else
rly=1;


}


void alarm_ring_HI()
{
rly=0;
 Delay(65000);Delay(65000);
 Delay(65000);Delay(65000);
 Delay(65000);Delay(65000);

rly=1;
}

void alarm_ring_LOW()
{
rly=0;
 Delay(65000);Delay(65000);
rly=1;
}












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=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 */

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


void DS1307_setdate(unsigned char dd, unsigned char mm, unsigned char yy)
{
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_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
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top