/*
* 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 */
-
#include <htc.h>
#include <stdlib.h>
#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; } \
const static int range_fade_steps[4] = { 1, 1, 1, 1 };
#endif
+#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;
+
int main(void)
{
led_t red = INIT_LED;
int fade_steps;
pic_init();
+ unused_init();
buttons_init();
rgb_init();
- reset_steps();
+ dbgpin_init();
+ reset_steps();
if (buttons_on())
rgb_on();
+ dbgpin_high();
while (1) {
unsigned char buttons = buttons_read();
wht.increment = (neww - wht.value) / fade_steps;
wht.remainder = neww - (wht.value + wht.increment * fade_steps);
}
+ dbgpin_low();
__delay_ms(STEP_SIZE); /* step should be start to start... */
+ dbgpin_high();
} else {
rgb_off();
+ dbgpin_low();
buttons_sleep();
+ dbgpin_high();
reset_steps();
rgb_on();
red.value = 0;