// PIC12F675 Configuration Bit Settings #pragma config FOSC = INTRCIO // INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT, GP5/OSC1/CLKIN) #pragma config WDTE = OFF // WDT disabled #pragma config PWRTE = ON // PWRT enabled #pragma config MCLRE = ON // GP3/MCLR pin function is MCLR #pragma config BOREN = ON // BOD enabled #pragma config CP = OFF // Program Memory code protection is disabled #pragma config CPD = OFF // Data memory code protection is disabled #include #include #define _XTAL_FREQ 4000000U #define STEP_DELAY_MS 20000U #define STARTUP_PATTERNS 2U #define REGULAR_PATTERNS 3U #define TOTAL_PATTERNS (STARTUP_PATTERNS + REGULAR_PATTERNS) // Fan transistor controls on GPIO 2/4/5 const uint8_t pattern[TOTAL_PATTERNS] = { // First two are the gentle startup 0b000000, 0b000100, // These are the regular repeating pattern 0b010100, 0b110000, 0b100100 }; // For shutting down the old fan *before* turning on the new const uint8_t prePattern[TOTAL_PATTERNS] = { 0b000000, 0b000000, 0b000100, 0b010000, 0b100000 }; // Set GPIO 2/4/5 as digital outputs void setup(void) { ANSEL = 0; CMCON = 7; TRISIO = 0b001011; } void main(void) { uint8_t currentStep = 0; setup(); for ( ; ; ) { // This will take long enough to ensure the transistor response GPIO = prePattern[currentStep]; GPIO = pattern[currentStep]; __delay_ms(STEP_DELAY_MS); ++currentStep; if (TOTAL_PATTERNS == currentStep) { // Cycle through regular patterns only currentStep = STARTUP_PATTERNS; } } return; }