Subversion Repositories HomeAutomation

Rev

Rev 33 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 33 Rev 48
Line 25... Line 25...
25
 
25
 
26
 
26
 
27
static void mainInit(void);
27
static void mainInit(void);
28
 
28
 
29
static BOOL heartBeatEnabled = FALSE;
29
static BOOL heartBeatEnabled = FALSE;
-
 
30
BYTE ldc = 50;
30
 
31
 
31
void main()
32
void main()
32
{
33
{
33
    static TICK t = 0;
34
    static TICK t = 0;
34
 
35
 
Line 46... Line 47...
46
 
47
 
47
    tickInit();
48
    tickInit();
48
 
49
 
49
    while(1)
50
    while(1)
50
    {
51
    {
-
 
52
        #ifdef USE_CAN
51
        if ((tickGet()-t)>=5*TICK_SECOND && heartBeatEnabled==TRUE)
53
        if ((tickGet()-t)>=5*TICK_SECOND && heartBeatEnabled==TRUE)
52
        {
54
        {
53
            CAN_MESSAGE cm;
55
            CAN_MESSAGE cm;
54
 
56
 
55
            t = tickGet();
57
            t = tickGet();
Line 62... Line 64...
62
 
64
 
63
            while(!canSendMessage(cm));
65
            while(!canSendMessage(cm));
64
 
66
 
65
           
67
           
66
        }
68
        }
-
 
69
        #endif
67
    }
70
    }
68
}
71
}
69
 
72
 
70
 
73
 
71
#pragma interruptlow HighISR
74
#pragma interruptlow HighISR
72
void HighISR(void)
75
void HighISR(void)
73
{
76
{
-
 
77
    //if(ldc--<=1) {LED0_IO=~LED0_IO; ldc=50; }
-
 
78
 
74
    #ifdef USE_CAN
79
    #ifdef USE_CAN
75
        canISR();
80
        canISR();
76
    #endif
81
    #endif
77
 
82
 
78
    #ifdef USE_UART
83
    #ifdef USE_UART
79
        uartISR();
84
        uartISR();
80
    #endif
85
    #endif
-
 
86
 
-
 
87
    if (INTCONbits.INT0IE && INTCONbits.INT0IF)
-
 
88
    {
-
 
89
        static TICK t = 0;
-
 
90
        CAN_MESSAGE cm;
-
 
91
 
-
 
92
        if ((tickGet()-t)>TICK_SECOND/2)
-
 
93
        {
-
 
94
 
-
 
95
            LED0_IO=~LED0_IO;
-
 
96
 
-
 
97
            // Send heartbeat
-
 
98
            cm.ident=0x00000666;
-
 
99
            cm.extended=FALSE;
-
 
100
            cm.data_length=1;
-
 
101
            cm.data[0]='H';
-
 
102
 
-
 
103
            while(!canSendMessage(cm));
-
 
104
           
-
 
105
            t=tickGet();
-
 
106
        }
-
 
107
 
-
 
108
        INTCONbits.INT0IF=0;
-
 
109
    }
-
 
110
 
-
 
111
    //if (RCSTAbits.OERR) { RCSTAbits.CREN=0; RCSTAbits.CREN=1; }
81
 
112
 
82
    tickUpdate();
113
    tickUpdate();
83
}
114
}
84
#pragma code highVector=0x08
115
#pragma code highVector=0x08
85
void HighVector (void)
116
void HighVector (void)
Line 87... Line 118...
87
    _asm goto HighISR _endasm
118
    _asm goto HighISR _endasm
88
}
119
}
89
#pragma code // Return to default code section
120
#pragma code // Return to default code section
90
 
121
 
91
 
122
 
92
 
123
 
93
#pragma interruptlow LowISR
124
#pragma interruptlow LowISR
94
void LowISR(void)
125
void LowISR(void)
95
{
126
{
96
 
127
 
97
}
128
}
98
#pragma code lowVector=0x18
129
#pragma code lowVector=0x18
99
void LowVector (void)
130
void LowVector (void)
100
{
131
{
101
    _asm goto LowISR _endasm
132
    _asm goto LowISR _endasm
102
}
133
}
103
#pragma code // Return to default code section
134
#pragma code // Return to default code section
104
 
135
 
105
 
136
 
Line 113... Line 144...
113
*   Depends: none.
144
*   Depends: none.
114
*/
145
*/
115
void mainInit()
146
void mainInit()
116
{
147
{
117
    LED0_TRIS=0;   
148
    LED0_TRIS=0;   
118
 
149
 
119
    // Enable internal PORTB pull-ups
150
    // Enable internal PORTB pull-ups
120
    INTCON2bits.RBPU = 0;
151
    INTCON2bits.RBPU = 0;
121
   
152
   
122
    // Enable Interrupts
153
    // Enable Interrupts
123
    INTCONbits.GIEH = 1;
154
    INTCONbits.GIEH = 1;
124
    INTCONbits.GIEL = 1;
155
    INTCONbits.GIEL = 1;
125
 
156
 
-
 
157
 
-
 
158
    // RB0 interrupt
-
 
159
    INTCON2bits.INTEDG0 = 1; //rising edge
-
 
160
    INTCONbits.INT0IE = 1; 
-
 
161
 
-
 
162
    // Enable interrupt prirority
-
 
163
    RCONbits.IPEN=1;
-
 
164
   
-
 
165
 
126
}
166
}
127
 
167
 
128
/*
168
/*
129
*   Function: canParse
169
*   Function: canParse
130
*
170
*
131
*   Input:  Received can message
171
*   Input:  Received can message
132
*   Output: none
172
*   Output: none
Line 169... Line 209...
169
    unsigned int wait = 0;
209
    unsigned int wait = 0;
170
    CAN_MESSAGE cm;
210
    CAN_MESSAGE cm;
171
    static BOOL waitingMessage = FALSE;
211
    static BOOL waitingMessage = FALSE;
172
    static TICK timeout=0;
212
    static TICK timeout=0;
173
    static BYTE count=0;
213
    static BYTE count=0;
-
 
214
 
174
 
215
 
175
    if (waitingMessage==TRUE && (tickGet()-timeout)>TICK_SECOND/20)
216
    if (waitingMessage==TRUE && (tickGet()-timeout)>TICK_SECOND/20)
176
    {
217
    {
177
        waitingMessage=FALSE;
218
        waitingMessage=FALSE;
178
    }
219
    }
-
 
220
 
179
 
221
 
180
    if (waitingMessage==TRUE)
222
    if (waitingMessage==TRUE)
181
    {
223
    {
-
 
224
 
182
        timeout=tickGet();
225
        timeout=tickGet();
183
 
226
 
184
        // UART END
227
        // UART END
185
        if(count>=14)
228
        if(count>=14)
186
        {
229
        {
Line 233... Line 276...
233
            timeout=tickGet();
276
            timeout=tickGet();
234
            count=0;
277
            count=0;
235
            cm.ident=0;
278
            cm.ident=0;
236
            return;
279
            return;
237
    }
280
    }
238
   
-
 
239
 
281
 
240
    if(c=='1' && waitingMessage==FALSE)
282
    if(c=='1' && waitingMessage==FALSE)
241
    {  
283
    {  
242
            cm.ident=0x00000123;
284
            cm.ident=0x00000123;
243
            cm.extended=FALSE;
285
            cm.extended=FALSE;
Line 280... Line 322...
280
            cm.data[0]='0';
322
            cm.data[0]='0';
281
 
323
 
282
            while(!canSendMessage(cm));
324
            while(!canSendMessage(cm));
283
    }
325
    }
284
 
326
 
285
   
327
 
286
 
328
 
287
}
329
}
288
#endif
330
#endif