// Main function void main(void) { InitLCD(); // Initialize LCD InitI2C(); // Initialize i2c pins // Set initial time Set_DS1307_RTC_Time(TwentyFourHoursMode, 12, 59, 50); // Set time 08:32:59 AM // Set initial date Set_DS1307_RTC_Date(15, 12, 12, Saturday); // Set 15-12-2012 @ Saturday while(1) { SetTime(); // Display RTC time on first line of LCD DisplayTimeToLCD(Get_DS1307_RTC_Time()); // Display RTC date on second line of LCD DisplayDateOnLCD(Get_DS1307_RTC_Date()); __delay_ms(100); // 1 second delay } }
void displayState1(void) { while (1) { // Hien thi thoi gian DisplayTimeToLCD(Get_DS1307_RTC_Time()); ADCinit(); ADCvalue = ReadADC(); //Hien thi ngày tháng t? giây 0->giây 40 if (Get_DS1307_RTC_Time()[0] > 40) { WriteCommandToLCD(0xc0); DisplayDateOnLCD(Get_DS1307_RTC_Date()); } //Hi?n th? nhi?t ?? t? giây 40->59 if (Get_DS1307_RTC_Time()[0] < 40) { voltage = (int) (5000.0f / 1023 * ADCvalue); f = voltage / 10; WriteCommandToLCD(0xc0); WriteStringToLCD("TEMP: "); WriteTempToLCD(f); WriteCommandToLCD(0xc8); WriteDataToLCD(0xdf); WriteStringToLCD("C"); } //WriteCommandToLCD(0xc0); //Nh?n nút chuy?n tr?ng thái if (!RA1) { state++; if (state == 5) { state = 1; } break; } //Báo th?c if (h_alarm == (int) Get_DS1307_RTC_Time()[2] && m_alarm == (int) Get_DS1307_RTC_Time()[1]) { RD0 = 0; } //T?t báo th?c if (!RA4) { RD0 = 1; h_alarm = 0; m_alarm = 0; } } }
// Main function void main() { InitLCD(); // Initialize LCD InitI2C(); // Initialize i2c pins // Set initial time Set_DS1307_RTC_Time(AM_Time, 8, 32, 59); // Set time 08:32:59 AM // Set initial date Set_DS1307_RTC_Date(2, 11, 12, Friday); // Set 02-11-2012 @ Friday while(1) { // Display RTC time on first line of LCD DisplayTimeToLCD(Get_DS1307_RTC_Time()); // Display RTC date on second line of LCD DisplayDateOnLCD(Get_DS1307_RTC_Date()); delay(65000); // Roughly about 1 second delay } }