]> oss.titaniummirror.com Git - rgblamp.git/blobdiff - main.c
Use bit defs and some aesthetic cleanup
[rgblamp.git] / main.c
diff --git a/main.c b/main.c
index 8f51cf26e926ab289e9713ddb08e74afa8226db5..fbf88d349a10c7e8b9e04c295c1a16f7abfa17c4 100644 (file)
--- a/main.c
+++ b/main.c
@@ -15,8 +15,8 @@
  * - ( 9) RB3 - CCP1 PWM for red LED
  * - (10) RB4 - rocker switch position B (right)
  * - (11) RB5 - rocker switch position A (left)
- * - (12) RB6 - unused
- * - (13) RB7 - unused
+ * - (12) RB6 - unused (future crystal)
+ * - (13) RB7 - unused (future crystal)
  * - (14) Vdd
  * - (15) RA6 - unused
  * - (16) RA7 - CCP2 PWM for grn LED
 #include "buttons.h"
 #include "rgb.h"
 #include "timer.h"
+#include "adc_random.h"
 
 #define AUTO_OFF_COUNT          549316UL /* 5 hrs in 32.768 ms units */
 #define reset_steps()           do { incolor_steps = 1; fade_steps = 0; } \
-                                  while (0)
+                                    while (0)
 #define rand_u8()               (rand() & 0xff)
 #define rand_u16()              ((rand() << 8) + rand_u8())
 #define rand_incolor_steps(s)   (min_incolor_steps[s & 3] + \
 #define rand_fade_steps(s)      (min_fade_steps[s & 3] + \
                                     (rand() % range_fade_steps[s & 3]))
 #define leds_set(r,g,b,w)       rgb_set((r).value >> 7, \
-                                  (g).value >> 7, \
-                                  (b).value >> 7, \
-                                  0)
-
-#define dbgpin_init() \
-do { \
-  /* Set RA2 as output low */ \
-  PORTA &= ~0x04; \
-  TRISA &= ~0x04; \
-} while (0)
-
-#define dbgpin_high() PORTA |= 0x04;
-#define dbgpin_low()  PORTA &= ~0x04;
+                                    (g).value >> 7, \
+                                    (b).value >> 7, \
+                                    0)
+#define dbgpin_init()           do { \
+                                    /* Set RA2 as output low */ \
+                                    RA2 = 0; \
+                                    TRISA2 = 0; \
+                                } while (0)
+#define dbgpin_high() RA2 = 1;
+#define dbgpin_low()  RA2 = 0;
 
 typedef struct {
   int value;
   int increment;
-  char remainder;
+  signed char remainder;
 } led_t;
 #define INIT_LED { 0, 0, 0 }
 
@@ -88,7 +86,6 @@ int main(void)
     int fade_steps;
     unsigned long auto_off = 0;
 
-
     pic_init();
     unused_init();
     buttons_init();
@@ -96,6 +93,7 @@ int main(void)
     timer_init();
     dbgpin_init();
 
+    srand((adc_random() << 8) + adc_random());
     reset_steps();
     if (buttons_on())
       rgb_on();
@@ -147,7 +145,7 @@ int main(void)
               }
               leds_set(red, grn, blu, wht);
             } else if (--incolor_steps == 0) {
-              int newr, newg, newb, neww, tmp;
+              int newr, newg, newb, neww;
 
               /* Next led color.  All off is not a valid option.
                * RGB values are stored and processed as 15-bit non-negative