Subversion Repositories HomeAutomation

Rev

Rev 33 | Show entire file | Regard 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();
-
 
58
       
-
 
59
            // Send heartbeat
-
 
60
            cm.ident=0x00000666;
-
 
61
            cm.extended=FALSE;
-
 
62
            cm.data_length=1;
-
 
63
            cm.data[0]='H';
-
 
64
 
-
 
65
            while(!canSendMessage(cm));
-
 
66
 
-
 
67
           
-
 
68
        }
-
 
69
        #endif
-
 
70
    }
-
 
71
}
-
 
72
 
-
 
73
 
-
 
74
#pragma interruptlow HighISR
-
 
75
void HighISR(void)
-
 
76
{
-
 
77
    //if(ldc--<=1) {LED0_IO=~LED0_IO; ldc=50; }
-
 
78
 
-
 
79
    #ifdef USE_CAN
-
 
80
        canISR();
-
 
81
    #endif
-
 
82
 
-
 
83
    #ifdef USE_UART
-
 
84
        uartISR();
-
 
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;
56
       
96
 
57
            // Send heartbeat
97
            // Send heartbeat
58
            cm.ident=0x00000666;
98
            cm.ident=0x00000666;
59
            cm.extended=FALSE;
99
            cm.extended=FALSE;
60
            cm.data_length=1;
100
            cm.data_length=1;
61
            cm.data[0]='H';
101
            cm.data[0]='H';
62
 
102
 
63
            while(!canSendMessage(cm));
103
            while(!canSendMessage(cm));
64
 
-
 
65
           
104
           
66
        }
105
            t=tickGet();
67
    }
106
        }
68
}
-
 
69
 
-
 
70
 
107
 
71
#pragma interruptlow HighISR
-
 
72
void HighISR(void)
108
        INTCONbits.INT0IF=0;
73
{
109
    }
74
    #ifdef USE_CAN
-
 
75
        canISR();
-
 
76
    #endif
-
 
77
 
110
 
78
    #ifdef USE_UART
111
    //if (RCSTAbits.OERR) { RCSTAbits.CREN=0; RCSTAbits.CREN=1; }
79
        uartISR();
-
 
80
    #endif
-
 
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)
86
{
117
{
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 116... Line 147...
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;
-
 
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
   
125
 
165
 
126
}
166
}
127
 
167
 
128
/*
168
/*
129
*   Function: canParse
169
*   Function: canParse
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 210... Line 253...
210
 
253
 
211
        // extended
254
        // extended
212
        if(count>=4)
255
        if(count>=4)
213
        {
256
        {
214
            cm.extended=c;
257
            cm.extended=c;
215
            count++;
258
            count++;
216
            return;
259
            return;
217
        }
260
        }
218
 
261
 
219
        // ident
262
        // ident
220
        if(count>=0)
263
        if(count>=0)
221
        {
264
        {
222
            cm.ident+=((DWORD)c<<(count*8));
265
            cm.ident+=((DWORD)c<<(count*8));
223
            count++;
266
            count++;
224
            return;
267
            return;
225
        }
268
        }
226
   
269
   
227
    }
270
    }
228
 
271
 
229
 
272
 
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;