aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Harrington <kb0iic@berzerkula.org>2019-07-31 21:40:49 -0500
committerWilliam Harrington <kb0iic@berzerkula.org>2019-07-31 21:40:49 -0500
commitbf173a814803310b77da3e0d9ef3d0c345421789 (patch)
treef160dfe7707df8a6e14f5a7da3eed1d1fbc9000f
parentea6bafc1320bec14e79b97aad8f072146a11583c (diff)
Add Date to debug output. Use new Get_DayOfWeek function when setting Day of Week. Reduce time between LCD Intro and Layout to 1 second.
-rwxr-xr-xmain.c44
-rwxr-xr-xmain.h8
2 files changed, 27 insertions, 25 deletions
diff --git a/main.c b/main.c
index b7b2a48..d2d6354 100755
--- a/main.c
+++ b/main.c
@@ -13,16 +13,16 @@
#endif
unsigned int Adc_Read(unsigned int channel) {
- ADFM = 1; // results right justified
- ADCS0 = 1; //conversion speed = 64*Tosc
+ ADFM = 1; // results right justified
+ ADCS0 = 1; //conversion speed = 64*Tosc
ADCS1 = 1;
- ADCS2 = 1;
+ ADCS2 = 1; //For 16F877
ADCON0bits.CHS = channel;
- ADON = 1; // Turn on ADC
+ ADON = 1; // Turn on ADC
__delay_ms(1);
GO_DONE = 1;
- while(ADCON0bits.GO_DONE == 1);
- return((ADRESH << 8) + ADRESL); // ex 1024
+ while (ADCON0bits.GO_DONE == 1);
+ return ((ADRESH << 8) + ADRESL); // ex 1024
}
int main() {
@@ -68,7 +68,7 @@ int main() {
// Set an initial date time
//Set_Time();
//Set_Date();
- //Set_DayOfWeek();
+ //Set_DayOfWeek(Get_DayOfWeek(year, month, date));
// Write default alarm values
@@ -113,11 +113,11 @@ int main() {
//#endif
format_Temperature();
- // Determine day of the week
+ // Determine day of the week from Calendar Date
//#ifdef DEBUG
// UART_send_string("Determining day of week");
//#endif
- getWeekDay(dayOfWeek);
+ getWeekDay(Get_DayOfWeek(year, month, date));
// Enter loop and update display if sec changes from DS3231
if (sec_chg != sec) {
@@ -126,19 +126,19 @@ int main() {
// Set temp_sec to current sec from DS3231
sec_chg = sec;
+ }
- // Get current LDR reading
- ldr = Adc_Read(0);
+ // Get current LDR reading
+ ldr = Adc_Read(0);
- if (ldr_chg != ldr) {
- Vfd_Set_Brightness(3 - ((1024 / ldr) - 1));
- ldr_chg = ldr;
- }
+ if (ldr_chg != ldr) {
+ Vfd_Set_Brightness(ldr / 256);
+ ldr_chg = ldr;
#ifdef DEBUG
UART_send_string(CURSOR(19, 1));
- sprintf(buf, "%sTIME:%s\t%02d:%02d:%02d\r\n", YELLOW, CLRATTR,
- hour, min, sec);
+ sprintf(buf, "%sTIME:%s\t%02d:%02d:%02d\t%sDATE:%s\t%02d/%02d/%02d\r\n", YELLOW, CLRATTR,
+ hour, min, sec, YELLOW, CLRATTR, date, month, year);
UART_send_string(buf);
sprintf(buf, "%sAL1:%s\t%02d:%02d:%02d\t%sSTATUS:%s %d\r\n", YELLOW,
CLRATTR, alarm1_hour, alarm1_min, alarm1_sec, YELLOW,
@@ -149,11 +149,11 @@ int main() {
alarm2_status);
UART_send_string(buf);
sprintf(buf, "%sWKDAY:%s\t%d\t\t%sDAY:%s\t%s\r\n", YELLOW, CLRATTR,
- dayOfWeek, YELLOW, CLRATTR, weekday);
+ day, YELLOW, CLRATTR, weekday);
UART_send_string(buf);
sprintf(buf, "%sTEMP:\t%s%c%c%c.%c%cC%s\t\t%sLDR:%s\t\%04d %d\r\n",
YELLOW, CLRATTR, temp_sign, temp_2, temp_1, temp_0, 0xB0,
- CLRATTR, YELLOW, CLRATTR, ldr, ((3 - (1024 / ldr))) - 1);
+ CLRATTR, YELLOW, CLRATTR, ldr, ldr / 256);
UART_send_string(buf);
#endif
}
@@ -251,6 +251,8 @@ void getWeekDay(unsigned int dayOfWeek) {
case 7:
weekday = "Sat";
break;
+ default:
+ break;
}
}
@@ -268,7 +270,7 @@ void display_Intro() {
Lcd_Write_String("RTC/LCD with PIC");
Lcd_Set_Cursor(2, 1);
Lcd_Write_String(" Circuit Digest");
- __delay_ms(2000); //display for 1sec
+ __delay_ms(1000); //display for 1sec
}
void display_Lcd_Layout() {
@@ -280,7 +282,7 @@ void display_Lcd_Layout() {
Lcd_Write_Char('C');
Lcd_Set_Cursor(2, 1);
Lcd_Write_String("ddd, DD/MM/YY ");
- __delay_ms(2000);
+ __delay_ms(1000);
}
void update_Display() {
diff --git a/main.h b/main.h
index 0b0ce43..f26b600 100755
--- a/main.h
+++ b/main.h
@@ -4,10 +4,10 @@ unsigned int ldr_chg = 0;
// Initialize variables for date time and alarms
unsigned int sec = 0;
-unsigned int min = 45;
-unsigned int hour = 16;
-unsigned int dayOfWeek = 1;
-unsigned int date = 28;
+unsigned int min = 37;
+unsigned int hour = 21;
+unsigned int day = 4;
+unsigned int date = 31;
unsigned int month = 7;
unsigned int year = 19;
unsigned int century = 20;