Subversion Repositories HomeAutomation

Rev

Rev 86 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*********************************************************************
  2.  *
  3.  *                  Ticker module service
  4.  *
  5.  *********************************************************************
  6.  * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canBase/Source/Tick.c $
  7.  * Last changed:    $LastChangedDate: 2007-03-03 19:07:14 +0100 (Sat, 03 Mar 2007) $
  8.  * By:              $LastChangedBy: johboh $
  9.  * Revision:        $Revision: 353 $
  10.  ********************************************************************/
  11.  
  12. #define TICK_INCLUDE
  13.  
  14. #include <Tick.h>
  15.  
  16.  
  17. static TICK TickCount = 0;  // 10ms/unit
  18.  
  19.  
  20. /*
  21. *   Function: TickInit
  22. *
  23. *   Input:  none
  24. *   Output: Tick manager is initialized.
  25. *   Pre-conditions: TickInit
  26. *   Affects: none
  27. *   Depends: none
  28. */
  29.  
  30. void tickInit(void)
  31. {
  32.     T0CON = 0b10000000 | TICK_PRESCALE;
  33.     TMR0H = (BYTE)((TICK_COUNTER & 0xFF00)>>8);
  34.     TMR0L = (TICK_COUNTER & 0xFF);
  35.  
  36.     INTCONbits.TMR0IF = 0;
  37.     INTCONbits.TMR0IE = 1;
  38.     INTCON2bits.TMR0IP = 1;
  39.  
  40.     TickCount = 0;
  41. }
  42.  
  43. /*
  44. *   Function: TickGet
  45. *
  46. *   Input:  none
  47. *   Output: Current tick value is given, 1 tick represents approximately 10ms
  48. *   Pre-conditions: TickInit
  49. *   Affects: none
  50. *   Depends: none
  51. */
  52. TICK tickGet(void)
  53. {
  54.     return TickCount;
  55. }
  56.  
  57.  
  58. /*
  59. *   Function: tickUpdate
  60. *
  61. *   Input:  none
  62. *   Output: none
  63. *   Pre-conditions: TickInit
  64. *   Affects: none
  65. *   Depends: none
  66. */
  67. void tickUpdate(void)
  68. {
  69.     if(INTCONbits.TMR0IF==1 && INTCONbits.TMR0IE==1)
  70.     {
  71.         TMR0H = (BYTE)((TICK_COUNTER & 0xFF00)>>8);
  72.         TMR0L = (TICK_COUNTER & 0xFF);
  73.  
  74.         TickCount++;
  75.  
  76.         INTCONbits.TMR0IF = 0;
  77.     }
  78. }
  79.