Subversion Repositories HomeAutomation

Rev

Rev 276 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 276 Rev 277
Line 2... Line 2...
2
 *
2
 *
3
 *   Functions for controlling blinds
3
 *   Functions for controlling blinds
4
 *
4
 *
5
 *********************************************************************
5
 *********************************************************************
6
 * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canTemp/Source/blinds.c $
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) $
7
 * Last changed:    $LastChangedDate: 2007-01-31 14:04:02 +0100 (Wed, 31 Jan 2007) $
8
 * By:              $LastChangedBy: johboh $
8
 * By:              $LastChangedBy: johboh $
9
 * Revision:        $Revision: 276 $
9
 * Revision:        $Revision: 277 $
10
 ********************************************************************/
10
 ********************************************************************/
11
#include <blinds.h>
11
#include <blinds.h>
12
 
12
 
13
#ifdef USE_BLINDS
13
#ifdef USE_BLINDS
14
 
14
 
15
BLINDS_DIR mode = MIDDLE;
-
 
16
WORD numSteps = 0;
-
 
17
 
-
 
18
BYTE minCounter = 0;
15
static unsigned int timerVal = 50536;
19
 
16
 
20
/*
17
/*
21
*   Function: blindsInit
18
*   Function: blindsInit
22
*
19
*
23
*   Input:  none.
20
*   Input:  none.
24
*   Output: none.
21
*   Output: none.
25
*   Pre-conditions: none
22
*   Pre-conditions: none
26
*   Affects: none.
23
*   Affects: none.
27
*   Depends: none.
24
*   Depends: none.
28
*/
25
*/
29
void blindsInit()
26
void blindsInit()
30
{
27
{
31
    // setup timer one on 0.5ms.
28
    // setup timer one on 0.5ms.
32
    // 16 bit write, system clock, prescale 2 bit, oscillator off, 
29
    // 16 bit write, system clock, prescale 2 bit, oscillator off, 
33
    T1CON = 0b11000001;
30
    T1CON = 0b11000001;
34
    TMR1H=((TMR1_VAL&0xFF00)>>8);
31
    TMR1H=((timerVal&0xFF00)>>8);
35
    TMR1L=(TMR1_VAL&0xFF);
32
    TMR1L=(timerVal&0xFF);
36
    PIR1bits.TMR1IF = 0;
33
    PIR1bits.TMR1IF = 0;
37
    PIE1bits.TMR1IE = 1;
34
    PIE1bits.TMR1IE = 1;
38
    IPR1bits.TMR1IP = 1; // high prior?
35
    IPR1bits.TMR1IP = 1; // high prior?
39
}
36
}
40
 
37
 
41
/*
38
/*
42
*   Function: blindsTurn
39
*   Function: blindsTurn
43
*
40
*
44
*   Input:  Direction and number of steps to perform.
41
*   Input:  Angle to turn to.
45
*   Output: none.
42
*   Output: none.
46
*   Pre-conditions: none
43
*   Pre-conditions: none
47
*   Affects: none.
44
*   Affects: none.
48
*   Depends: none.
45
*   Depends: none.
49
*/
46
*/
50
void blindsTurn(BLINDS_DIR dir, WORD steps)
47
void blindsTurn(signed int angle)
51
{
48
{
52
    mode = dir;
49
    // 65536-TIME/0,0000001
53
    minCounter = 0;
50
    // -90 0.5 ms = 60536 (5000)
54
    numSteps = steps;
51
    // 0   1.5 ms = 50536 (15000)
55
}
-
 
56
 
-
 
57
 
-
 
58
/*
-
 
59
*   Function: blindsStop
52
    // 90  2.5 ms = 40536 (25000)
60
*
53
 
61
*   Input:  Stop blind at current position.
54
    if (angle<-90) timerVal=60536;
62
*   Output: none.
-
 
63
*   Pre-conditions: none
55
    else if (angle>90) timerVal=40536;
64
*   Affects: none.
-
 
65
*   Depends: none.
56
    else
66
*/
57
    {
67
void blindsStop()
58
        timerVal=60536-((90+angle)*111.111);
68
{
59
    }
69
    numSteps = 0;
-
 
70
}
60
}
71
 
61
 
72
 
62
 
73
/*
63
/*
74
*   Function: blindsISR
64
*   Function: blindsISR
Line 81... Line 71...
81
*/
71
*/
82
void blindsISR(void)
72
void blindsISR(void)
83
{
73
{
84
    if (PIR1bits.TMR1IF == 1 && PIE1bits.TMR1IE == 1)
74
    if (PIR1bits.TMR1IF == 1 && PIE1bits.TMR1IE == 1)
85
    {
75
    {
86
        TMR1H=((TMR1_VAL&0xFF00)>>8);
76
        TMR1H=((timerVal&0xFF00)>>8);
87
        TMR1L=(TMR1_VAL&0xFF);
77
        TMR1L=(timerVal&0xFF);
88
 
78
 
89
 
-
 
90
       
-
 
91
        if (numSteps>1)
-
 
92
        {
-
 
93
            if ((--minCounter)<1)
-
 
94
            {
-
 
95
                numSteps--;
-
 
96
                BLINDS0_IO=~BLINDS0_IO;
79
        BLINDS0_IO=~BLINDS0_IO;
97
                minCounter=mode;
-
 
98
            }  
-
 
99
        }
-
 
100
 
80
 
101
        PIR1bits.TMR1IF = 0;
81
        PIR1bits.TMR1IF = 0;
102
    }
82
    }
103
}
83
}
104
 
84