void DisplayTimeToLCD( unsigned char* pTimeArray ) // Displays time in HH:MM:SS AM/PM format { ClearLCDScreen(); // Move cursor to zero location and clear screen // Display Hour WriteDataToLCD( (pTimeArray[2]/10)+0x30 ); WriteDataToLCD( (pTimeArray[2]%10)+0x30 ); //Display ':' WriteDataToLCD(':'); //Display Minutes WriteDataToLCD( (pTimeArray[1]/10)+0x30 ); WriteDataToLCD( (pTimeArray[1]%10)+0x30 ); //Display ':' WriteDataToLCD(':'); //Display Seconds WriteDataToLCD( (pTimeArray[0]/10)+0x30 ); WriteDataToLCD( (pTimeArray[0]%10)+0x30 ); //Display Space WriteDataToLCD(' '); // Display mode switch(pTimeArray[3]) { case AM: WriteStringToLCD("AM"); break; case PM: WriteStringToLCD("PM"); break; default: WriteDataToLCD('H'); break; } }
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; } } }
void main() { P1=0x00; P2=0x00; SerialInput(); InitLCD(); EA=1; ES=1; EX1=1; while(1) { ClearLCDScreen(); WriteStringToLCD("IDLE"); delayms(100); } }
void DisplayDateOnLCD( unsigned char* pDateArray ) // Displays Date in DD:MM:YY @ Day format { WriteCommandToLCD(0xc0); // Move cursor to second line // Display Date WriteDataToLCD( (pDateArray[1]/10)+0x30 ); WriteDataToLCD( (pDateArray[1]%10)+0x30 ); //Display '/' WriteDataToLCD('/'); //Display Month WriteDataToLCD( (pDateArray[2]/10)+0x30 ); WriteDataToLCD( (pDateArray[2]%10)+0x30 ); //Display '/' WriteDataToLCD('/'); //Display Year WriteDataToLCD( (pDateArray[3]/10)+0x30 ); WriteDataToLCD( (pDateArray[3]%10)+0x30 ); //Display Space WriteDataToLCD(' '); // Display Day switch(pDateArray[0]) { 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; } }
void displayState4(void) { ClearLCDScreen(); unsigned int h; unsigned int m; unsigned int s; h = 0; m = 0; s = 0; if (!RA1) { state++; if (state == 5) { state = 1; } } while (1) { WriteCommandToLCD(0x80); WriteStringToLCD(" ALARM "); WriteCommandToLCD(0xc0); WriteTempToLCD(h); WriteStringToLCD(":"); WriteTempToLCD(m); WriteStringToLCD(":"); WriteTempToLCD(s); if (!RA1) { DisplayFirstTimeToLCD(Get_DS1307_RTC_Time()); //DisplayDateOnLCD(Get_DS1307_RTC_Date()); break; } while (1) { if (RA4 == 0) { switch_state++; if (switch_state == 4) { break; } } if (RA1 == 0) { state = 1; break; } switch (switch_state) { case 1: WriteCommandToLCD(0x80); WriteStringToLCD(" HOUR "); if (RA2 == 0 && h < 24) { h++; WriteCommandToLCD(0xc0); WriteTempToLCD(h); } if (RA3 == 0 && h > 0) { h--; WriteCommandToLCD(0xc0); WriteTempToLCD(h); } break; case 2: WriteCommandToLCD(0x80); WriteStringToLCD(" MINUTE "); if (RA2 == 0 && m < 60) { m++; WriteCommandToLCD(0xc0 + 3); WriteTempToLCD(m); } if (RA3 == 0 && m > 0) { m--; WriteCommandToLCD(0xc0 + 3); WriteTempToLCD(m); } break; case 3: WriteCommandToLCD(0x80); WriteStringToLCD(" SECOND "); if (RA2 == 0) { s++; WriteCommandToLCD(0xc0 + 6); WriteTempToLCD(s); } if (RA3 == 0 && s > 0) { s--; WriteCommandToLCD(0xc0 + 6); WriteTempToLCD(s); } break; } h_alarm = h; m_alarm = m; s_alarm = s; } } }
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); } } }
void displayState2(void) { ClearLCDScreen(); //Ba bi?n h,m,s l?u l?i th?i gian hi?n t?i unsigned int h; unsigned int m; unsigned int s; h = (int) Get_DS1307_RTC_Time()[2]; m = (int) Get_DS1307_RTC_Time()[1]; s = (int) Get_DS1307_RTC_Time()[0]; //B?m nút chuy?n tr?ng thái if (!RA1) { state++; if (state == 5) { state = 1; } } //S?a th?i gian while (1) { WriteCommandToLCD(0x80); WriteStringToLCD(" SETTING TIME"); WriteCommandToLCD(0xc0); WriteTempToLCD(h); WriteStringToLCD(":"); WriteTempToLCD(m); WriteStringToLCD(":"); WriteTempToLCD(s); if (!RA1) break; while (1) { //Khi nút switch ???c b?m s? chuy?n qua các ch? ?? ?i?u ch?nh khác if (RA4 == 0) { switch_state++; if (switch_state == 4) { break; } } //Chuy?n tr?ng thái if (RA1 == 0) { state = 3; break; } switch (switch_state) { case 1: WriteCommandToLCD(0x80); WriteStringToLCD(" CHANGE HOUR "); if (RA2 == 0 && h < 24) { h++; WriteCommandToLCD(0xc0); WriteTempToLCD(h); } if (RA3 == 0 && h > 0) { h--; WriteCommandToLCD(0xc0); WriteTempToLCD(h); } break; case 2: WriteCommandToLCD(0x80); WriteStringToLCD(" CHANGE MINUTE "); if (RA2 == 0 && m < 60) { m++; WriteCommandToLCD(0xc0 + 3); WriteTempToLCD(m); } if (RA3 == 0 && m > 0) { m--; WriteCommandToLCD(0xc0 + 3); WriteTempToLCD(m); } break; case 3: WriteCommandToLCD(0x80); WriteStringToLCD(" CHANGE SECOND "); if (RA2 == 0) { s++; WriteCommandToLCD(0xc0 + 6); WriteTempToLCD(s); } if (RA3 == 0 && s > 0) { s--; WriteCommandToLCD(0xc0 + 6); WriteTempToLCD(s); } break; } //L?u l?i th?i gian v?a thay ??i Set_DS1307_RTC_Time(PM_Time, h, m, s); } } }