From 69da989ff2f0fa877055a6aa697dde9577950991 Mon Sep 17 00:00:00 2001 From: "R. Steve McKown" Date: Tue, 6 Dec 2011 09:34:52 -0700 Subject: [PATCH] unused_init() properly configures unused pins PortA unused pins are set as output high. PortB can have unused pins as input with weak pull-ups enabled. --- main.c | 27 +++++++++++++++++++++++++-- unused.h | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 unused.h diff --git a/main.c b/main.c index 9163c1c..ec3d425 100644 --- 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 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 + +#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 -- 2.39.2