Subversion Repositories HomeAutomation

Rev

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

Rev Author Line No. Line
140 johboh 1
/*********************************************************************
129 johboh 2
 *
3
 *                  Main application
4
 *
5
 *********************************************************************
6
 * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canLCD/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
 
140 johboh 19
#ifdef USE_LCD
20
    #include "lcd.h"
21
#endif
22
 
129 johboh 23
 
24
static void mainInit(void);
25
 
26
 
27
void main()
28
{
29
    static TICK t = 0;
30
    CAN_MESSAGE outCm;
31
 
32
    // Inits
33
    mainInit();
260 johboh 34
    canInit();
129 johboh 35
 
36
 
140 johboh 37
    #ifdef USE_LCD
38
        lcdInit();
39
        lcdClear();
40
        lcdPutrs("Welcome!");
41
    #endif
42
 
129 johboh 43
    while(1)
44
    {
45
        static TICK t = 0;
46
 
47
        if ((tickGet()-t)>TICK_SECOND)
48
        {
49
            LED0_IO=~LED0_IO;
50
            t = tickGet();
51
        }
52
    }
53
}
54
 
55
 
56
#pragma interrupt high_isr
57
void high_isr(void)
58
{
260 johboh 59
    canISR();
129 johboh 60
}
61
 
62
 
63
#pragma interrupt low_isr
64
void low_isr(void)
65
{
66
 
67
}
68
 
69
 
70
 
71
/*
72
*   Function: mainInit
73
*
74
*   Input:  none
75
*   Output: none
76
*   Pre-conditions: none
77
*   Affects: Se code
78
*   Depends: none.
79
*/
80
void mainInit()
81
{
82
    LED0_TRIS=0;   
83
 
84
    // Enable Interrupts
85
    INTCONbits.GIEH = 1;
86
    INTCONbits.GIEL = 1;
87
 
88
    // Enable interrupt prirority
89
    RCONbits.IPEN=1;
90
 
91
 
92
}
93
 
94
/*
95
*   Function: canParse
96
*
97
*   Input:  Received can message
98
*   Output: none
99
*   Pre-conditions: canInit and received packet.
100
*   Affects: Sensors/actuators/etc. See code.
101
*   Depends: none.
102
*/
103
void canParse(CAN_MESSAGE cm)
104
{
105
    CAN_MESSAGE outCm;
106
}
107
 
108
 
109
// Below are mandantory when using bootloader
110
// define DEBUG_MODE to use without bootloader.
111
 
112
#ifndef DEBUG_MODE
113
extern void _startup (void);
114
#pragma code _RESET_INTERRUPT_VECTOR = 0x001000
115
void _reset (void)
116
{
117
    _asm goto _startup _endasm
118
}
119
#pragma code
120
#endif
121
 
122
#pragma code _HIGH_INTERRUPT_VECTOR = 0x001008
123
void _high_ISR (void)
124
{
125
    _asm GOTO high_isr _endasm
126
}
127
#pragma code
128
 
129
#pragma code _LOW_INTERRUPT_VECTOR = 0x001018
130
void _low_ISR (void)
131
{
132
    _asm GOTO low_isr _endasm
133
}
134
#pragma code