Subversion Repositories HomeAutomation

Rev

Rev 275 | 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:53:25 +0100 (Tue, 30 Jan 2007) $
  8.  * By:              $LastChangedBy: johboh $
  9.  * Revision:        $Revision: 276 $
  10.  ********************************************************************/
  11. #include <blinds.h>
  12.  
  13. #ifdef USE_BLINDS
  14.  
  15. BLINDS_DIR mode = MIDDLE;
  16. WORD numSteps = 0;
  17.  
  18. BYTE minCounter = 0;
  19.  
  20. /*
  21. *   Function: blindsInit
  22. *
  23. *   Input:  none.
  24. *   Output: none.
  25. *   Pre-conditions: none
  26. *   Affects: none.
  27. *   Depends: none.
  28. */
  29. void blindsInit()
  30. {
  31.     // setup timer one on 0.5ms.
  32.     // 16 bit write, system clock, prescale 2 bit, oscillator off,
  33.     T1CON = 0b11000001;
  34.     TMR1H=((TMR1_VAL&0xFF00)>>8);
  35.     TMR1L=(TMR1_VAL&0xFF);
  36.     PIR1bits.TMR1IF = 0;
  37.     PIE1bits.TMR1IE = 1;
  38.     IPR1bits.TMR1IP = 1; // high prior?
  39. }
  40.  
  41. /*
  42. *   Function: blindsTurn
  43. *
  44. *   Input:  Direction and number of steps to perform.
  45. *   Output: none.
  46. *   Pre-conditions: none
  47. *   Affects: none.
  48. *   Depends: none.
  49. */
  50. void blindsTurn(BLINDS_DIR dir, WORD steps)
  51. {
  52.     mode = dir;
  53.     minCounter = 0;
  54.     numSteps = steps;
  55. }
  56.  
  57.  
  58. /*
  59. *   Function: blindsStop
  60. *
  61. *   Input:  Stop blind at current position.
  62. *   Output: none.
  63. *   Pre-conditions: none
  64. *   Affects: none.
  65. *   Depends: none.
  66. */
  67. void blindsStop()
  68. {
  69.     numSteps = 0;
  70. }
  71.  
  72.  
  73. /*
  74. *   Function: blindsISR
  75. *
  76. *   Input:  none.
  77. *   Output: none.
  78. *   Pre-conditions: none
  79. *   Affects: none.
  80. *   Depends: none.
  81. */
  82. void blindsISR(void)
  83. {
  84.     if (PIR1bits.TMR1IF == 1 && PIE1bits.TMR1IE == 1)
  85.     {
  86.         TMR1H=((TMR1_VAL&0xFF00)>>8);
  87.         TMR1L=(TMR1_VAL&0xFF);
  88.  
  89.  
  90.        
  91.         if (numSteps>1)
  92.         {
  93.             if ((--minCounter)<1)
  94.             {
  95.                 numSteps--;
  96.                 BLINDS0_IO=~BLINDS0_IO;
  97.                 minCounter=mode;
  98.             }  
  99.         }
  100.  
  101.         PIR1bits.TMR1IF = 0;
  102.     }
  103. }
  104.  
  105. #endif
  106.