Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
129 johboh 1
/*********************************************************************
2
 *
3
 *                  Main application
4
 *
5
 *********************************************************************
6
 * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canDimmer/Source/Main.c $
7
 * Last changed:    $LastChangedDate: 2007-01-28 14:58:11 +0100 (Sun, 28 Jan 2007) $
8
 * By:              $LastChangedBy: johboh $
9
 * Revision:        $Revision: 260 $
10
 ********************************************************************/
11
 
12
 
13
#include <compiler.h>
14
#include <stackTasks.h>
15
#include <Tick.h>
16
#include <funcdefs.h>
260 johboh 17
#include <CAN.h>
129 johboh 18
 
19
static void mainInit(void);
20
 
21
 
260 johboh 22
/*
23
    Features (support upto 8 dimmers).
129 johboh 24
 
260 johboh 25
    need to define funcc to each channel.
26
    need to define funcc to all in this node.
27
 
28
    channel = 0 to 7
29
    value = 0 to 255
30
    place = 1 to 10
31
 
32
    NO FADE
33
    set channel to value.
34
    set channel off.
35
    set channel last.
36
    set channel on.
37
    set all to value.
38
    set all off.
39
    set all last.
40
    set all on.
41
 
42
    FADE
43
    fade channel to value.
44
    fade channel off.
45
    fade channel last.
46
    fade channel on.
47
    fade all to value.
48
    fade all off.
49
    fade all last.
50
    fade all on.
51
 
52
    MEMORY:
53
    Save current values to M[place].
54
    Set current values to M[place].
55
    Fade current values to M[place].
56
 
57
 
58
    settings:
59
    buttons, default fadespeed, stepping. (Get and set)
60
*/
61
 
62
 
63
 
129 johboh 64
void main()
65
{
66
    static TICK t = 0;
67
    CAN_MESSAGE outCm;
68
 
69
    // Inits
70
    mainInit();
71
 
260 johboh 72
    canInit();
129 johboh 73
 
74
 
75
    while(1)
76
    {
77
        static TICK t = 0;
78
 
79
        if ((tickGet()-t)>TICK_SECOND)
80
        {
81
            LED0_IO=~LED0_IO;
82
            t = tickGet();
83
        }
84
    }
85
}
86
 
87
 
88
#pragma interrupt high_isr
89
void high_isr(void)
90
{
260 johboh 91
    canISR();
129 johboh 92
}
93
 
94
 
95
#pragma interrupt low_isr
96
void low_isr(void)
97
{
98
 
99
}
100
 
101
 
102
 
103
/*
104
*   Function: mainInit
105
*
106
*   Input:  none
107
*   Output: none
108
*   Pre-conditions: none
109
*   Affects: Se code
110
*   Depends: none.
111
*/
112
void mainInit()
113
{
114
    LED0_TRIS=0;   
115
 
116
    // Enable Interrupts
117
    INTCONbits.GIEH = 1;
118
    INTCONbits.GIEL = 1;
119
 
120
    // Enable interrupt prirority
121
    RCONbits.IPEN=1;
122
 
123
 
124
}
125
 
126
/*
127
*   Function: canParse
128
*
129
*   Input:  Received can message
130
*   Output: none
131
*   Pre-conditions: canInit and received packet.
132
*   Affects: Sensors/actuators/etc. See code.
133
*   Depends: none.
134
*/
135
void canParse(CAN_MESSAGE cm)
136
{
137
    CAN_MESSAGE outCm;
138
 
139
}
140
 
141
 
142
// Below are mandantory when using bootloader
143
// define DEBUG_MODE to use without bootloader.
144
 
145
#ifndef DEBUG_MODE
146
extern void _startup (void);
147
#pragma code _RESET_INTERRUPT_VECTOR = 0x001000
148
void _reset (void)
149
{
150
    _asm goto _startup _endasm
151
}
152
#pragma code
153
#endif
154
 
155
#pragma code _HIGH_INTERRUPT_VECTOR = 0x001008
156
void _high_ISR (void)
157
{
158
    _asm GOTO high_isr _endasm
159
}
160
#pragma code
161
 
162
#pragma code _LOW_INTERRUPT_VECTOR = 0x001018
163
void _low_ISR (void)
164
{
165
    _asm GOTO low_isr _endasm
166
}
167
#pragma code