// 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 } }
void displayState3(void) { ClearLCDScreen(); //kh?i t?o các bi?n l?u th? ngày tháng n?m unsigned int d; unsigned int m; unsigned int y; unsigned int w; d = (int) Get_DS1307_RTC_Date()[1]; m = (int) Get_DS1307_RTC_Date()[2]; y = (int) Get_DS1307_RTC_Date()[3]; w = (int) Get_DS1307_RTC_Date()[0]; if (!RA1) { state++; if (state == 5) { state = 1; } } while (1) { WriteCommandToLCD(0x80); WriteStringToLCD(" SETTING DATE "); WriteCommandToLCD(0xc0); WriteTempToLCD(d); WriteStringToLCD(":"); WriteTempToLCD(m); WriteStringToLCD(":"); WriteTempToLCD(y); WriteStringToLCD(" "); switch (w) { case Monday: WriteStringToLCD("MON"); break; case Tuesday: WriteStringToLCD("TUE"); break; case Wednesday: WriteStringToLCD("WED"); break; case Thursday: WriteStringToLCD("THU"); break; case Friday: WriteStringToLCD("FRI"); break; case Saturday: WriteStringToLCD("SAT"); break; case Sunday: WriteStringToLCD("SUN"); break; default: WriteStringToLCD("???"); break; } if (!RA1) break; while (1) { if (RA4 == 0) { switch_state++; if (switch_state == 4) { break; } } if (RA1 == 0) { state = 4; break; } switch (switch_state) { case 1: WriteCommandToLCD(0x80); WriteStringToLCD(" CHANGE DAY "); if (RA2 == 0 && d < 31) { d++; WriteCommandToLCD(0xc0); WriteTempToLCD(d); } if (RA3 == 0 && d > 0) { d--; WriteCommandToLCD(0xc0); WriteTempToLCD(d); } break; case 2: WriteCommandToLCD(0x80); WriteStringToLCD(" CHANGE MONTH "); if (RA2 == 0 && m < 12) { m++; WriteCommandToLCD(0xc0 + 3); WriteTempToLCD(m); } if (RA3 == 0 && m > 0) { m--; WriteCommandToLCD(0xc0 + 3); WriteTempToLCD(m); } break; case 3: WriteCommandToLCD(0x80); WriteStringToLCD(" CHANGE YEAR "); if (RA2 == 0) { y++; WriteCommandToLCD(0xc0 + 6); WriteTempToLCD(y); } if (RA3 == 0 && y > 0) { y--; WriteCommandToLCD(0xc0 + 6); WriteTempToLCD(y); } break; case 4: WriteCommandToLCD(0x80); WriteStringToLCD(" CHANGE WEEK DAY "); if (RA2 == 0 && w <= 7) { w++; } if (RA3 == 0 && w >= 1) { w--; } WriteCommandToLCD(0xc0 + 9); switch (w) { case Monday: WriteStringToLCD("MON"); break; case Tuesday: WriteStringToLCD("TUE"); break; case Wednesday: WriteStringToLCD("WED"); break; case Thursday: WriteStringToLCD("THU"); break; case Friday: WriteStringToLCD("FRI"); break; case Saturday: WriteStringToLCD("SAT"); break; case Sunday: WriteStringToLCD("SUN"); break; default: WriteStringToLCD("???"); break; } break; } Set_DS1307_RTC_Date(d, m, y, w); } } }