From 452ecb5e9c0ad214cab6617c1a54a2edc55a6cd3 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Thu, 1 Aug 2019 00:33:08 -0500 Subject: Adjust debug screen, change ldr to brtlvl and add brtlvl_chg to compare. Add macro for brtlvl to translate brightness levels 0-3. --- main.c | 18 ++++++++++-------- main.h | 5 ++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index 8bb8554..c5235d1 100755 --- a/main.c +++ b/main.c @@ -1,5 +1,3 @@ -#include // included for sprintf - #include "conf.h" //Configuration settings #include "main.h" //Declarations for main #include "lcd.h" //Declaratons for LCD @@ -19,6 +17,10 @@ void main(void) { TRISA0 = 0x01; // RA is input (ADC) + + TRISBbits.TRISB0 = 0; // Set RB0 as output + PORTBbits.RB0 = 0; // Set RB0 low + TRISC = 0x00; // Set PORTC as outputs PORTC = 0x00; // Set all PORTC pins LOW @@ -54,7 +56,7 @@ void main(void) { Lcd_Init(); #ifdef DEBUG - UART_send_string(CURSOR(15, 23)); // Set cursor at line 15, column 23 + UART_send_string(CURSOR(15, 24)); // Set cursor at line 15, column 24 UART_send_string(GREEN); // Set Green UART_send_string("LCD Module Initialized and active\r\n"); UART_send_string(CLRATTR); // No color @@ -132,11 +134,11 @@ void main(void) { #ifdef ADC // Get current LDR reading and calculate for brightness levels 0 - 3 - ldr = Adc_Read(0) / 256; + ldr = Adc_Read(0); - if (ldr_chg != ldr) { - Vfd_Set_Brightness(ldr); - ldr_chg = ldr; + if (brtlvl_chg != brtlvl) { + Vfd_Set_Brightness(brtlvl); + brtlvl_chg = brtlvl; } #endif @@ -158,7 +160,7 @@ void main(void) { 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); + CLRATTR, YELLOW, CLRATTR, ldr, brtlvl); UART_send_string(buf); #endif } diff --git a/main.h b/main.h index 39ca8b2..f7c707d 100755 --- a/main.h +++ b/main.h @@ -1,9 +1,11 @@ #ifdef ADC // Initialize variable for LDR unsigned int ldr = 0; -unsigned int ldr_chg = 0; #endif +#define brtlvl ldr/256 +int brtlvl_chg = 0; + // Initialize variables for date time and alarms unsigned int sec = 0; unsigned int min = 37; @@ -42,6 +44,7 @@ alarm1_hour_0, alarm1_hour_1; unsigned char alarm2_min_0, alarm2_min_1, alarm2_hour_0, alarm2_hour_1; #ifdef DEBUG +#include // included for sprintf // Initialize a variable to use as a buffer for sprintf char buf[40]; #endif -- cgit v1.2.3-54-g00ecf