Subversion Repositories HomeAutomation

Rev

Rev 276 | 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-31 14:04:02 +0100 (Wed, 31 Jan 2007) $
  8.  * By:              $LastChangedBy: johboh $
  9.  * Revision:        $Revision: 277 $
  10.  ********************************************************************/
  11. #include <blinds.h>
  12.  
  13. #ifdef USE_BLINDS
  14.  
  15. static unsigned int timerVal = 50536;
  16.  
  17. /*
  18. *   Function: blindsInit
  19. *
  20. *   Input:  none.
  21. *   Output: none.
  22. *   Pre-conditions: none
  23. *   Affects: none.
  24. *   Depends: none.
  25. */
  26. void blindsInit()
  27. {
  28.     // setup timer one on 0.5ms.
  29.     // 16 bit write, system clock, prescale 2 bit, oscillator off,
  30.     T1CON = 0b11000001;
  31.     TMR1H=((timerVal&0xFF00)>>8);
  32.     TMR1L=(timerVal&0xFF);
  33.     PIR1bits.TMR1IF = 0;
  34.     PIE1bits.TMR1IE = 1;
  35.     IPR1bits.TMR1IP = 1; // high prior?
  36. }
  37.  
  38. /*
  39. *   Function: blindsTurn
  40. *
  41. *   Input:  Angle to turn to.
  42. *   Output: none.
  43. *   Pre-conditions: none
  44. *   Affects: none.
  45. *   Depends: none.
  46. */
  47. void blindsTurn(signed int angle)
  48. {
  49.     // 65536-TIME/0,0000001
  50.     // -90 0.5 ms = 60536 (5000)
  51.     // 0   1.5 ms = 50536 (15000)
  52.     // 90  2.5 ms = 40536 (25000)
  53.  
  54.     if (angle<-90) timerVal=60536;
  55.     else if (angle>90) timerVal=40536;
  56.     else
  57.     {
  58.         timerVal=60536-((90+angle)*111.111);
  59.     }
  60. }
  61.  
  62.  
  63. /*
  64. *   Function: blindsISR
  65. *
  66. *   Input:  none.
  67. *   Output: none.
  68. *   Pre-conditions: none
  69. *   Affects: none.
  70. *   Depends: none.
  71. */
  72. void blindsISR(void)
  73. {
  74.     if (PIR1bits.TMR1IF == 1 && PIE1bits.TMR1IE == 1)
  75.     {
  76.         TMR1H=((timerVal&0xFF00)>>8);
  77.         TMR1L=(timerVal&0xFF);
  78.  
  79.         BLINDS0_IO=~BLINDS0_IO;
  80.  
  81.         PIR1bits.TMR1IF = 0;
  82.     }
  83. }
  84.  
  85. #endif
  86.