signed char Hour_ON1;
signed char Min_ON1;
signed char Hour_OFF1;
signed char MIN_OFF1;
signed char YEAR_SET = 20;
unsigned char MONTH_SET = 1;
unsigned char Day_SET = 1;
unsigned char HOUR_SET = 0;
unsigned char MIN_SET = 0;
unsigned char SEC_SET = 0;
unsigned char WK_DAY_SET = 0;
unsigned char RLY_PATTERN = 0;
unsigned char BLINKFLAG = 0;
void DATE_TIME_SET_ADD() {
//Setting Date and time
if ((Rly_No == 10) && (Comb_No == 1)) {
Day_SET++;
if (Day_SET > 31) {
Day_SET = 1;
}
LEDBuffer_1[1] = DISPTABLE[Day_SET / 10];
LEDBuffer_1[0] = DISPTABLE[Day_SET % 10];
} else if ((Rly_No == 10) && (Comb_No == 2)) {
MONTH_SET++;
if (MONTH_SET > 12) {
MONTH_SET = 1;
}
LEDBuffer_1[1] = DISPTABLE[MONTH_SET / 10];
LEDBuffer_1[0] = DISPTABLE[MONTH_SET % 10];
} else if ((Rly_No == 10) && (Comb_No == 3)) {
YEAR_SET++;
if (YEAR_SET > 99) {
YEAR_SET = 0;
}
LEDBuffer_1[1] = DISPTABLE[YEAR_SET / 10];
LEDBuffer_1[0] = DISPTABLE[YEAR_SET % 10];
} else if ((Rly_No == 10) && (Comb_No == 4)) {
WK_DAY_SET++;
if (WK_DAY_SET > 60) {
WK_DAY_SET = 1;
}
LEDBuffer_1[1] = DISPTABLE[WK_DAY_SET / 10];
LEDBuffer_1[0] = DISPTABLE[WK_DAY_SET % 10];
} else if ((Rly_No == 10) && (Comb_No == 5)) {
HOUR_SET++;
if (HOUR_SET > 24) {
WK_DAY_SET = 0;
}
LEDBuffer_1[1] = DISPTABLE[HOUR_SET / 10];
LEDBuffer_1[0] = DISPTABLE[HOUR_SET % 10];
} else if ((Rly_No == 10) && (Comb_No == 6)) {
MIN_SET++;
if (MIN_SET > 59) {
MIN_SET = 0;
}
LEDBuffer_1[1] = DISPTABLE[MIN_SET / 10];
LEDBuffer_1[0] = DISPTABLE[MIN_SET % 10];
} else if ((Rly_No == 10) && (Comb_No == 7)) {
SEC_SET++;
if (SEC_SET > 59) {
SEC_SET = 0;
}
LEDBuffer_1[1] = DISPTABLE[SEC_SET / 10];
LEDBuffer_1[0] = DISPTABLE[SEC_SET % 10];
}
}
//===========================================================================================
// Display_RTC_Clock
//
//===========================================================================================
void Display_RTC_Clock() {
unsigned char Index = 0, Temp_Runner = 0, Temp1;
unsigned char Temp2;
unsigned char Temp3;
unsigned char Temp4;
Temp1 = sec & 0x0f;
Temp2 = sec >> 4;
LEDBuffer_1[0] = DISPTABLE[Temp1];
LEDBuffer_1[1] = DISPTABLE[Temp2];
Temp3 = min & 0x0f;
Temp4 = min >> 4;
LEDBuffer_1[2] = DISPTABLE[Temp3];
LEDBuffer_1[3] = DISPTABLE[Temp4];
LEDBuffer_1[0] = DISPTABLE[22]; // display R
}
void main(void) {
// Initialize the device
SYSTEM_Initialize();
I2C1_Initialize();
I2C1_Write1ByteRegister(0x68, 0x00, 0x30);
I2C1_Write1ByteRegister(0x68, 0x01, 0x30);
I2C1_Write1ByteRegister(0x68, 0x02, 0x05);
I2C1_Write1ByteRegister(0x68, 0x03, 0x01);
I2C1_Write1ByteRegister(0x68, 0x04, 0x02);
I2C1_Write1ByteRegister(0x68, 0x05, 0x03);
I2C1_Write1ByteRegister(0x68, 0x06, 0x10);
DgtSel = 1;
GIE = 1;
while (1) {
if (pgm_run == 1) {
__delay_ms(10);
start = 0;
if (Pgm_Mode_Entry == 0) {
Pgm_Mode_Cnng_Over = 0;
Update_Rly_Power_on(0x00);
Rly_No = 1;
Comb_No = 1;
BLINKSEGMENT = 0;
SELECTPRESS = 0;
BLINKFLAG = 0;
run_Mode_Entry = 0;
RLY_PATTERN = 0;
Eprom_reads();
Pgm_Mode_Entry = 1;
}
KeyCheck();
} else if (pgm_run == 0) {
if (RTC_Write == 1) {
I2C1_Write1ByteRegister(0x68, 0x00, SEC_SET);
I2C1_Write1ByteRegister(0x68, 0x01, MIN_SET);
I2C1_Write1ByteRegister(0x68, 0x02, HOUR_SET);
I2C1_Write1ByteRegister(0x68, 0x03, WK_DAY_SET);
I2C1_Write1ByteRegister(0x68, 0x04, Day_SET);
I2C1_Write1ByteRegister(0x68, 0x05, MONTH_SET);
I2C1_Write1ByteRegister(0x68, 0x06, YEAR_SET);
}
sec = I2C1_Read1ByteRegister(0x68, 0x00);
min = I2C1_Read1ByteRegister(0x68, 0x01);
Hour = I2C1_Read1ByteRegister(0x68, 0x02);
Display_RTC_Clock();
}
}
}