i've change accordingly but it seems that error which lead to the hang of the clock is still there.
Inside my ,main i will do tis:
INTCONbits.GIE = 1; //Enable Global Interrupts
while(1) {
if (Flags.Bit.SecondTick){
Flags.Bit.SecondTick = 0;
INTCONbits.GIE = 0; // Disable Global Interrupts
if (GetTime_I2C()==0) // If no error
Display_Time(); // Display time
else {
I2C_STOP();
WrLCDControl4Bit(0x80);
Out_LCD(ROM_TYPE "GetTime Error");
}
INTCONbits.GIE = 1; // Enable Global Interrupts
}
Here is routine i call for my time:
////////////////////////////////////
// INITIALIZATION OF TIME & DATE //
////////////////////////////////////
char Init_Time(){
I2C_START();
if (I2C_WRITE(0b10100000))
return(-1);
if (I2C_WRITE(0b00000000))
return(-1);
if (I2C_WRITE(0b00000000))
return(-1);
if (I2C_WRITE(0b00000000))
return(-1);
if (I2C_WRITE(0b01010000))
return(-1);
if (I2C_WRITE(0b01011001))
return(-1);
if (I2C_WRITE(0b00100011))
return(-1);
if (I2C_WRITE(0b00110001))
return(-1);
if (I2C_WRITE(0b00010010))
return(-1);
I2C_STOP();
return(0);
}
////////////////////////////
// DISPLAY OF TIME & DATE //
////////////////////////////
void Display_Time() {
WrLCDControl4Bit(0x80);
date = year_date & 0b00111111;
Out_Hex_LCD (date);
month = weekday_month & 0b00011111;
if (month == 0b00000001)
Out_LCD(ROM_TYPE "Jan");
else if (month == 0b01000010)
Out_LCD(ROM_TYPE "Feb");
else if (month == 0b00000011)
Out_LCD(ROM_TYPE "Mar");
else if (month == 0b00000100)
Out_LCD(ROM_TYPE "Apr");
else if (month == 0b00000101)
Out_LCD(ROM_TYPE "May");
else if (month == 0b00000110)
Out_LCD(ROM_TYPE "Jun");
else if (month == 0b00000111)
Out_LCD(ROM_TYPE "Jul");
else if (month == 0b00001000)
Out_LCD(ROM_TYPE "Aug");
else if (month == 0b00001001)
Out_LCD(ROM_TYPE "Sep");
else if (month == 0b00010000)
Out_LCD(ROM_TYPE "Oct");
else if (month == 0b00010001)
Out_LCD(ROM_TYPE "Nov");
else if (month == 0b00010010)
Out_LCD(ROM_TYPE "Dec");
year = year_date & 0b11000000;
year =year>>6;
year +=8;
if (year<10){
Out_LCD(ROM_TYPE "0");
Out_Dec_LCD(year);
}
else
Out_Dec_LCD(year);
Out_LCD(ROM_TYPE " ");
Out_Hex_LCD(hour);
Out_LCD(ROM_TYPE ":");
Out_Hex_LCD(min);
Out_LCD(ROM_TYPE ":");
Out_Hex_LCD(sec);
}
/////////////////////
// I2C TIME & DATE //
/////////////////////
char GetTime_I2C(){
I2C_START();
if (I2C_WRITE(0b10100000))
return(-1);
if (I2C_WRITE(0b00000000))
return(-1);
I2C_RESTART();
if (I2C_WRITE(0b10100001))
return(-1);
control = I2C_READ();
I2C_ACK();
hsec = I2C_READ();
I2C_ACK();
sec = I2C_READ();
I2C_ACK();
min = I2C_READ();
I2C_ACK();
hour = I2C_READ();
I2C_ACK();
year_date = I2C_READ();
// if (!(year_date & 0x3F))
// return(-1);
I2C_ACK();
weekday_month = I2C_READ();
// if (!(weekday_month & 0x1F))
// return(-1);
I2C_NACK();
I2C_STOP(); // Stop the process
Delay_msec(2);
return(0);
}
When the LCD appear to be hang , the last display will always be 3f11 FF:FF:FF:12
or 0008 00:00:00:14
The last two digit is changing tentatively.
Here you can viewed the error signal when error msgshown on LCD:
https://photobucket.com/aprodite_star
Thx!