From dc4ed0a6b74e1b787fe7efa2ba3eab9fb38dece6 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Wed, 31 Jul 2019 23:14:43 -0500 Subject: Add ifdef for ADC option around ADC related source. --- main.c | 64 +++++++++++++++++++++++++++++++++++++++------------------------- main.h | 2 ++ 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/main.c b/main.c index b63803d..c59970e 100755 --- a/main.c +++ b/main.c @@ -5,7 +5,11 @@ #include "lcd.h" //Declaratons for LCD #include "i2c.h" #include "ds3231.h" //Declarations for RTC + +#ifdef ADC #include "adc.h" //Declarations for ADC +#endif + #include "beep.h" //Declarations for BEEP #ifdef DEBUG @@ -13,7 +17,7 @@ #include "term.h" //Declarations for Escape codes #endif -int main() { +void main(void) { TRISA0 = 0x01; // RA is input (ADC) TRISC = 0x00; // Set PORTC as outputs PORTC = 0x00; // Set all PORTC pins LOW @@ -32,15 +36,25 @@ int main() { I2C_Master_Init(100000); // Init I2C Master with 100KHz Clock #ifdef DEBUG - UART_send_string(CURSOR(13, 23)); // Set cursor at line 13, column 23 + UART_send_string(CURSOR(13, 24)); // Set cursor at line 13, column 24 UART_send_string(GREEN); // Set Green UART_send_string("I2C Module Initialized and active\r\n"); UART_send_string(CLRATTR); // No color #endif +#ifdef ADC + Adc_Init(); // Init I2C Master with 100KHz Clock +#ifdef DEBUG + UART_send_string(CURSOR(14, 24)); // Set cursor at line 14, column 24 + UART_send_string(GREEN); // Set Green + UART_send_string("ADC Module Initialized and active\r\n"); + UART_send_string(CLRATTR); // No color +#endif +#endif + Lcd_Init(); #ifdef DEBUG - UART_send_string(CURSOR(14, 23)); // Set cursor at line 14, column 23 + UART_send_string(CURSOR(15, 23)); // Set cursor at line 15, column 23 UART_send_string(GREEN); // Set Green UART_send_string("LCD Module Initialized and active\r\n"); UART_send_string(CLRATTR); // No color @@ -116,38 +130,38 @@ int main() { sec_chg = sec; } +#ifdef ADC // Get current LDR reading ldr = Adc_Read(0); if (ldr_chg != ldr) { Vfd_Set_Brightness(ldr / 256); ldr_chg = ldr; + } +#endif #ifdef DEBUG - UART_send_string(CURSOR(19, 1)); - 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, - CLRATTR, alarm1_status); - UART_send_string(buf); - sprintf(buf, "%sAL2:%s\t%02d:%02d\t\t%sSTATUS:%s %d\r\n", YELLOW, - CLRATTR, alarm2_hour, alarm2_min, YELLOW, CLRATTR, - alarm2_status); - UART_send_string(buf); - sprintf(buf, "%sWKDAY:%s\t%d\t\t%sDAY:%s\t%s\r\n", YELLOW, CLRATTR, - 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, ldr / 256); - UART_send_string(buf); + UART_send_string(CURSOR(19, 1)); + 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, + CLRATTR, alarm1_status); + UART_send_string(buf); + sprintf(buf, "%sAL2:%s\t%02d:%02d\t\t%sSTATUS:%s %d\r\n", YELLOW, + CLRATTR, alarm2_hour, alarm2_min, YELLOW, CLRATTR, + alarm2_status); + UART_send_string(buf); + sprintf(buf, "%sWKDAY:%s\t%d\t\t%sDAY:%s\t%s\r\n", YELLOW, CLRATTR, + 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, ldr / 256); + UART_send_string(buf); #endif - } } - - return 0; } // Format unsigned int to unsigned chars diff --git a/main.h b/main.h index 39ffa7d..39ca8b2 100755 --- a/main.h +++ b/main.h @@ -1,6 +1,8 @@ +#ifdef ADC // Initialize variable for LDR unsigned int ldr = 0; unsigned int ldr_chg = 0; +#endif // Initialize variables for date time and alarms unsigned int sec = 0; -- cgit v1.2.3-54-g00ecf