diff options
| -rwxr-xr-x | main.c | 18 | ||||
| -rwxr-xr-x | main.h | 5 | 
2 files changed, 14 insertions, 9 deletions
| @@ -1,5 +1,3 @@ -#include <stdio.h>                         // 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
      }
 @@ -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 <stdio.h>                         // included for sprintf
  // Initialize a variable to use as a buffer for sprintf
  char buf[40];
  #endif
 | 
