Subversion Repositories HomeAutomation

Rev

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

Rev 53 Rev 56
1
/*********************************************************************
1
/*********************************************************************
2
 *
2
 *
3
 *                  Main application
3
 *                  Main application
4
 *
4
 *
5
 *********************************************************************
5
 *********************************************************************
6
 * FileName:        Main.c
6
 * FileName:        Main.c
7
 *
7
 *
8
 * Author               Date    Comment
8
 * Author               Date    Comment
9
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10
 * Johan Böhlin     21-10-06    Original        (Rev 1.0)
10
 * Johan Böhlin     21-10-06    Original        (Rev 1.0)
11
 ********************************************************************/
11
 ********************************************************************/
12
 
12
 
13
#include <compiler.h>
13
#include <compiler.h>
14
#include <stackTasks.h>
14
#include <stackTasks.h>
15
 
15
 
16
#ifdef USE_CAN
16
#ifdef USE_CAN
17
    #include <CAN.h>
17
    #include <CAN.h>
18
#endif
18
#endif
19
 
19
 
20
static void mainInit(void);
20
static void mainInit(void);
21
 
21
 
22
void main()
22
void main()
23
{
23
{
24
 
24
 
25
    // Inits
25
    // Inits
26
 
26
 
27
    mainInit();
27
    mainInit();
28
 
28
 
29
    #ifdef USE_CAN
29
    #ifdef USE_CAN
30
        canInit();
30
        canInit();
31
    #endif
31
    #endif
32
 
32
 
33
 
33
 
34
    while(1)
34
    while(1)
35
    {
35
    {
36
    }
36
    }
37
}
37
}
38
 
38
 
39
 
39
 
40
#pragma interruptlow HighISR
40
#pragma interruptlow HighISR
41
void HighISR(void)
41
void HighISR(void)
42
{
42
{
43
 
43
 
44
 
44
 
45
    #ifdef USE_CAN
45
    #ifdef USE_CAN
46
        canISR();
46
        canISR();
47
    #endif
47
    #endif
48
 
48
 
49
}
49
}
50
#pragma code highVector=0x08
50
#pragma code highVector=0x08
51
void HighVector (void)
51
void HighVector (void)
52
{
52
{
53
    _asm goto HighISR _endasm
53
    _asm goto HighISR _endasm
54
}
54
}
55
#pragma code // Return to default code section
55
#pragma code // Return to default code section
56
 
56
 
57
 
57
 
58
 
58
 
59
#pragma interruptlow LowISR
59
#pragma interruptlow LowISR
60
void LowISR(void)
60
void LowISR(void)
61
{
61
{
62
 
62
 
63
}
63
}
64
#pragma code lowVector=0x18
64
#pragma code lowVector=0x18
65
void LowVector (void)
65
void LowVector (void)
66
{
66
{
67
    _asm goto LowISR _endasm
67
    _asm goto LowISR _endasm
68
}
68
}
69
#pragma code // Return to default code section
69
#pragma code // Return to default code section
70
 
70
 
71
 
71
 
72
/*
72
/*
73
*   Function: mainInit
73
*   Function: mainInit
74
*
74
*
75
*   Input:  none
75
*   Input:  none
76
*   Output: none
76
*   Output: none
77
*   Pre-conditions: none
77
*   Pre-conditions: none
78
*   Affects: Se code
78
*   Affects: Se code
79
*   Depends: none.
79
*   Depends: none.
80
*/
80
*/
81
void mainInit()
81
void mainInit()
82
{
82
{
83
    LED0_TRIS=0;   
83
    LED0_TRIS=0;   
84
 
84
 
85
    // Enable internal PORTB pull-ups
85
    // Enable internal PORTB pull-ups
86
    INTCON2bits.RBPU = 0;
86
    INTCON2bits.RBPU = 0;
87
   
87
   
88
    // Enable Interrupts
88
    // Enable Interrupts
89
    INTCONbits.GIEH = 1;
89
    INTCONbits.GIEH = 1;
90
    INTCONbits.GIEL = 1;
90
    INTCONbits.GIEL = 1;
91
 
91
 
92
    // Enable interrupt prirority
92
    // Enable interrupt prirority
93
    RCONbits.IPEN=1;
93
    RCONbits.IPEN=1;
94
   
94
   
95
 
95
 
96
}
96
}
97
 
97
 
98
/*
98
/*
99
*   Function: canParse
99
*   Function: canParse
100
*
100
*
101
*   Input:  Received can message
101
*   Input:  Received can message
102
*   Output: none
102
*   Output: none
103
*   Pre-conditions: canInit and received packet.
103
*   Pre-conditions: canInit and received packet.
104
*   Affects: Sensors/actuators/etc. See code.
104
*   Affects: Sensors/actuators/etc. See code.
105
*   Depends: none.
105
*   Depends: none.
106
*/
106
*/
107
#ifdef USE_CAN
107
#ifdef USE_CAN
108
void canParse(CAN_MESSAGE cm)
108
void canParse(CAN_MESSAGE cm)
109
{
109
{
110
 
-
 
-
 
110
    LED0_IO=~LED0_IO;
111
}
111
}
112
#endif
112
#endif
113
 
113
 
114
 
114