Advertisement
igendel

PIC12F675 3-fan cooling pad controller

Feb 3rd, 2019
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.78 KB | None | 0 0
  1. // PIC12F675 Configuration Bit Settings
  2. #pragma config FOSC = INTRCIO   // INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT, GP5/OSC1/CLKIN)
  3. #pragma config WDTE = OFF       // WDT disabled
  4. #pragma config PWRTE = ON       // PWRT enabled
  5. #pragma config MCLRE = ON       // GP3/MCLR pin function is MCLR
  6. #pragma config BOREN = ON       // BOD enabled
  7. #pragma config CP = OFF         // Program Memory code protection is disabled
  8. #pragma config CPD = OFF        // Data memory code protection is disabled
  9.  
  10. #include <xc.h>
  11. #include <stdint.h>
  12.  
  13. #define _XTAL_FREQ 4000000U
  14. #define STEP_DELAY_MS 20000U
  15.  
  16. #define STARTUP_PATTERNS 2U
  17. #define REGULAR_PATTERNS 3U
  18. #define TOTAL_PATTERNS (STARTUP_PATTERNS + REGULAR_PATTERNS)
  19.  
  20. // Fan transistor controls on GPIO 2/4/5
  21. const uint8_t pattern[TOTAL_PATTERNS] = {
  22.     // First two are the gentle startup
  23.     0b000000, 0b000100,
  24.     // These are the regular repeating pattern
  25.     0b010100, 0b110000, 0b100100
  26. };
  27.  
  28. // For shutting down the old fan *before* turning on the new
  29. const uint8_t prePattern[TOTAL_PATTERNS] = {
  30.     0b000000, 0b000000,
  31.     0b000100, 0b010000, 0b100000
  32. };
  33.  
  34. // Set GPIO 2/4/5 as digital outputs
  35. void setup(void) {
  36.    
  37.     ANSEL = 0;
  38.     CMCON = 7;
  39.     TRISIO = 0b001011;
  40.    
  41. }
  42.  
  43. void main(void) {
  44.    
  45.     uint8_t currentStep = 0;
  46.    
  47.     setup();
  48.    
  49.     for ( ; ; ) {
  50.        
  51.         // This will take long enough to ensure the transistor response
  52.         GPIO = prePattern[currentStep];
  53.        
  54.         GPIO = pattern[currentStep];
  55.        
  56.         __delay_ms(STEP_DELAY_MS);
  57.        
  58.         ++currentStep;
  59.         if (TOTAL_PATTERNS == currentStep) {
  60.             // Cycle through regular patterns only
  61.             currentStep = STARTUP_PATTERNS;
  62.         }
  63.    
  64.     }    
  65.    
  66.     return;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement