Subversion Repositories HomeAutomation

Rev

Rev 277 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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