]> oss.titaniummirror.com Git - rgblamp.git/commitdiff
unused_init() properly configures unused pins
authorR. Steve McKown <rsmckown@gmail.com>
Tue, 6 Dec 2011 16:34:52 +0000 (09:34 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Tue, 6 Dec 2011 16:34:52 +0000 (09:34 -0700)
PortA unused pins are set as output high.
PortB can have unused pins as input with weak pull-ups enabled.

main.c
unused.h [new file with mode: 0644]

diff --git a/main.c b/main.c
index 9163c1c77e1a32af312c3d7a90e4b6a94eecb52f..ec3d4257dfc10595522972e879e35f2ca4c7656d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,7 +1,28 @@
 /*
  * File:   main.c
  *
- * Created on August 16, 2010, 12:09 PM
+ * PWM test program
+ *
+ * PIC resources in use, 18-pin DIP, by pin:
+ * - ( 1) RA2 - unused
+ * - ( 2) RA3 - CCP3 PWM for blu LED
+ * - ( 3) RA4 - CCP4 PWM for wht LED.  ICSP pin 6, PGM/LVP.
+ * - ( 4) RA5 -                        ICSP pin 1, MCLR#/Vpp
+ * - ( 5) Vss
+ * - ( 6) RB0 - pushbutton
+ * - ( 7) RB1 - unused
+ * - ( 8) RB2 - unused
+ * - ( 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
+ * - (14) Vdd
+ * - (15) RA6 - unused
+ * - (16) RA7 - CCP2 PWM for grn LED
+ * - (17) RA0 - unused
+ * - (18) RA1 - unused
+ *
  */
 
 #define RUNAT32MHZ /* else 16 MHz */
@@ -11,6 +32,7 @@
 #include "picinit.h"
 #include "buttons.h"
 #include "rgb.h"
+#include "unused.h"
 
 #define STEP_SIZE               32 /* ms */
 #define reset_steps()           do { incolor_steps = 1; fade_steps = 0; } \
@@ -57,10 +79,11 @@ int main(void)
     int fade_steps;
 
     pic_init();
+    unused_init();
     buttons_init();
     rgb_init();
-    reset_steps();
 
+    reset_steps();
     if (buttons_on())
       rgb_on();
 
diff --git a/unused.h b/unused.h
new file mode 100644 (file)
index 0000000..f11272e
--- /dev/null
+++ b/unused.h
@@ -0,0 +1,22 @@
+/*
+ * File:   unused.h
+ *
+ * Initialize unused resources
+ */
+
+
+#ifndef _UNUSED_H
+#define _UNUSED_H
+
+#include <htc.h>
+
+#define UNUSED_PORTA 0b00000000
+
+/* Initialize unused resources. */
+#define unused_init() do { \
+    nWPUEN = 0;             /* enable weak pull-ups on PortB */ \
+    PORTA |= UNUSED_PORTA;  /* set unused PortA pins ...     */ \
+    TRISA &= ~UNUSED_PORTA; /* ... to output high.           */ \
+} while (0)
+
+#endif