Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1. /*********************************************************************
  2.  *
  3.  *   Functions for controlling blinds
  4.  *
  5.  *********************************************************************
  6.  * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canTemp/Source/blinds.c $
  7.  * Last changed:    $LastChangedDate: 2007-01-30 12:34:06 +0100 (Tue, 30 Jan 2007) $
  8.  * By:              $LastChangedBy: johboh $
  9.  * Revision:        $Revision: 275 $
  10.  ********************************************************************/
  11. #include <blinds.h>
  12.  
  13. #ifdef USE_BLINDS
  14.  
  15. typedef enum {OPEN=2,CLOSE=4} MODE;
  16.  
  17. MODE mode = OPEN;
  18. WORD numSteps = 0;
  19.  
  20. BYTE minCounter = 0;
  21.  
  22. /*
  23. *   Function: blindsInit
  24. *
  25. *   Input:  none.
  26. *   Output: none.
  27. *   Pre-conditions: none
  28. *   Affects: none.
  29. *   Depends: none.
  30. */
  31. void blindsInit()
  32. {
  33.     // setup timer one on 0.5ms.
  34.     // 16 bit write, system clock, prescale 2 bit, oscillator off,
  35.     T1CON = 0b11000001;
  36.     TMR1H=((TMR1_VAL&0xFF00)>>8);
  37.     TMR1L=(TMR1_VAL&0xFF);
  38.     PIR1bits.TMR1IF = 0;
  39.     PIE1bits.TMR1IE = 1;
  40.     IPR1bits.TMR1IP = 1; // high prior?
  41. }
  42.  
  43. /*
  44. *   Function: blindsClose
  45. *
  46. *   Input:  Number of steps to perform. 255 equals full close.
  47. *   Output: none.
  48. *   Pre-conditions: none
  49. *   Affects: none.
  50. *   Depends: none.
  51. */
  52. void blindsClose(WORD steps)
  53. {
  54.     mode = CLOSE;
  55.     minCounter = 0;
  56.     numSteps = steps;
  57. }
  58.  
  59. /*
  60. *   Function: blindsClose
  61. *
  62. *   Input:  Number of steps to perform. 255 equals full open.
  63. *   Output: none.
  64. *   Pre-conditions: none
  65. *   Affects: none.
  66. *   Depends: none.
  67. */
  68. void blindsOpen(WORD steps)
  69. {
  70.     mode = OPEN;
  71.     minCounter = 0;
  72.     numSteps = steps;
  73. }
  74.  
  75. /*
  76. *   Function: blindsStop
  77. *
  78. *   Input:  Stop blind at current position.
  79. *   Output: none.
  80. *   Pre-conditions: none
  81. *   Affects: none.
  82. *   Depends: none.
  83. */
  84. void blindsStop()
  85. {
  86.     numSteps = 0;
  87. }
  88.  
  89. /*
  90. *   Function: blindsStop
  91. *
  92. *   Input:  Stop blind at current position.
  93. *   Output: none.
  94. *   Pre-conditions: none
  95. *   Affects: none.
  96. *   Depends: none.
  97. */
  98. void blindsISR(void)
  99. {
  100.     if (PIR1bits.TMR1IF == 1 && PIE1bits.TMR1IE == 1)
  101.     {
  102.         TMR1H=((TMR1_VAL&0xFF00)>>8);
  103.         TMR1L=(TMR1_VAL&0xFF);
  104.  
  105.  
  106.        
  107.         if (numSteps>1)
  108.         {
  109.             if ((--minCounter)<1)
  110.             {
  111.                 numSteps--;
  112.                 BLINDS0_IO=~BLINDS0_IO;
  113.                 minCounter=mode;
  114.             }  
  115.         }
  116.  
  117.         PIR1bits.TMR1IF = 0;
  118.     }
  119. }
  120.  
  121. #endif
  122.