Subversion Repositories HomeAutomation

Rev

Rev 357 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 357 Rev 358
Line 2... Line 2...
2
 *
2
 *
3
 *                  Main application
3
 *                  Main application
4
 *
4
 *
5
 *********************************************************************
5
 *********************************************************************
6
 * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canLCD/Source/Main.c $
6
 * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canLCD/Source/Main.c $
7
 * Last changed:    $LastChangedDate: 2007-03-04 12:01:27 +0100 (Sun, 04 Mar 2007) $
7
 * Last changed:    $LastChangedDate: 2007-03-04 14:49:20 +0100 (Sun, 04 Mar 2007) $
8
 * By:              $LastChangedBy: johboh $
8
 * By:              $LastChangedBy: johboh $
9
 * Revision:        $Revision: 357 $
9
 * Revision:        $Revision: 358 $
10
 ********************************************************************/
10
 ********************************************************************/
11
 
11
 
12
 
12
 
13
#include <compiler.h>
13
#include <compiler.h>
14
#include <stackTasks.h>
14
#include <stackTasks.h>
Line 17... Line 17...
17
#include <CAN.h>
17
#include <CAN.h>
18
#include "..\canBoot\Include\boot.h"
18
#include "..\canBoot\Include\boot.h"
19
 
19
 
20
#ifdef USE_GLCD
20
#ifdef USE_GLCD
21
    #include "glcd.h"
21
    #include "glcd.h"
-
 
22
#endif
-
 
23
 
-
 
24
#ifdef USE_ADC
-
 
25
    #include <adc.h>
22
#endif
26
#endif
23
 
27
 
24
#ifdef USE_GLCD
28
#ifdef USE_GLCD
25
    const rom BYTE pic[]={
29
    const rom BYTE pic[]={
26
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
30
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
Line 115... Line 119...
115
0x00,0x78,0x81,0x81,0x81,0x89,0x89,0x76,
119
0x00,0x78,0x81,0x81,0x81,0x89,0x89,0x76,
116
0x89,0x76,0x00,0x81,0x00,0x00,0x00,0x00,
120
0x89,0x76,0x00,0x81,0x00,0x00,0x00,0x00,
117
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
121
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
118
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
122
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
119
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
123
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
120
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
124
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
121
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
125
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
122
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
126
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
123
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
127
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
124
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
128
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
125
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
129
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
126
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
130
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
127
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
131
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
128
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
132
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
129
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
133
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
130
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
134
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
131
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
135
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
132
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
136
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
133
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
137
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
134
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
138
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
135
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
139
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
136
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
140
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
137
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
141
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
138
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
142
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
139
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
143
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
140
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
144
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
141
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
145
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
142
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
146
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
143
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
147
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
144
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
148
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
145
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
149
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
146
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
150
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
147
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
151
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
148
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
152
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
149
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
153
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
150
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
154
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
151
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
155
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
152
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
156
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
153
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
157
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
154
};
158
};
155
 
159
 
156
const rom BYTE pic2[] = {
160
const rom BYTE pic2[] = {
157
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
161
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
Line 176... Line 180...
176
0x00,0x00,0x00,0xf0,0xfe,0x1f,0x00,0x00,
180
0x00,0x00,0x00,0xf0,0xfe,0x1f,0x00,0x00,
177
0x00,0x00,0x00,0xf0,0xf1,0x1f,0x00,0x00,
181
0x00,0x00,0x00,0xf0,0xf1,0x1f,0x00,0x00,
178
0x00,0x00,0x00,0xf0,0xc7,0x1f,0x00,0x00,
182
0x00,0x00,0x00,0xf0,0xc7,0x1f,0x00,0x00,
179
0x00,0x00,0x00,0xf0,0x3f,0x1f,0x00,0x00,
183
0x00,0x00,0x00,0xf0,0x3f,0x1f,0x00,0x00,
180
0x00,0x00,0x00,0xf0,0xff,0x0f,0x00,0x00,
184
0x00,0x00,0x00,0xf0,0xff,0x0f,0x00,0x00,
181
0x00,0x00,0x00,0xf0,0xff,0x0f,0x00,0x00,
185
0x00,0x00,0x00,0xf0,0xff,0x0f,0x00,0x00,
182
0x00,0x00,0x00,0xe0,0xff,0x0f,0x00,0x00,
186
0x00,0x00,0x00,0xe0,0xff,0x0f,0x00,0x00,
183
0x00,0x00,0xc0,0x83,0xff,0x07,0x00,0x00,
187
0x00,0x00,0xc0,0x83,0xff,0x07,0x00,0x00,
184
0x00,0x00,0xc0,0x3f,0xfc,0x03,0x00,0x00,
188
0x00,0x00,0xc0,0x3f,0xfc,0x03,0x00,0x00,
185
0x00,0x00,0xc0,0xff,0x01,0x00,0x00,0x00,
189
0x00,0x00,0xc0,0xff,0x01,0x00,0x00,0x00,
186
0x00,0x00,0xc0,0xff,0x1f,0x00,0x00,0x00,
190
0x00,0x00,0xc0,0xff,0x1f,0x00,0x00,0x00,
Line 206... Line 210...
206
0x00,0x00,0xe0,0xc1,0x3f,0x00,0x00,0x00,
210
0x00,0x00,0xe0,0xc1,0x3f,0x00,0x00,0x00,
207
0x00,0x00,0xe0,0x07,0x1c,0x00,0x00,0x00,
211
0x00,0x00,0xe0,0x07,0x1c,0x00,0x00,0x00,
208
0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
212
0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
209
0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
213
0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
210
0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
214
0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
211
0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
215
0x00,0x00,0xe0,0xff,0x3f,0x00,0x00,0x00,
212
0x00,0x00,0xc0,0xff,0x1f,0x00,0x00,0x00,
216
0x00,0x00,0xc0,0xff,0x1f,0x00,0x00,0x00,
213
0x00,0x00,0x00,0xe0,0x0f,0x00,0x00,0x00,
217
0x00,0x00,0x00,0xe0,0x0f,0x00,0x00,0x00,
214
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
218
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
215
0x00,0x00,0x80,0xff,0x07,0x00,0x00,0x00,
219
0x00,0x00,0x80,0xff,0x07,0x00,0x00,0x00,
216
0x00,0x00,0xc0,0xff,0x0f,0x00,0x00,0x00,
220
0x00,0x00,0xc0,0xff,0x0f,0x00,0x00,0x00,
Line 397... Line 401...
397
'\xff','\xff','\xff','\xff','\xff','\xff','\x3f','\xc0',
401
'\xff','\xff','\xff','\xff','\xff','\xff','\x3f','\xc0',
398
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
402
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
399
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
403
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
400
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
404
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
401
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
405
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
402
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
406
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
403
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
407
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xff',
404
'\xff','\xff','\xff','\xff','\xff','\xff','\x7f','\xff',
408
'\xff','\xff','\xff','\xff','\xff','\xff','\x7f','\xff',
405
'\xff','\xff','\xff','\xff','\xff','\xff','\x7f','\xff',
409
'\xff','\xff','\xff','\xff','\xff','\xff','\x7f','\xff',
406
'\xff','\xff','\xff','\xff','\xff','\xff','\x7f','\xff',
410
'\xff','\xff','\xff','\xff','\xff','\xff','\x7f','\xff',
407
'\xff','\xff','\xff','\xff','\xff','\xff','\x7f','\xce',
411
'\xff','\xff','\xff','\xff','\xff','\xff','\x7f','\xce',
408
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xc0',
412
'\xff','\xff','\xff','\xff','\xff','\xff','\xbf','\xc0',
Line 416... Line 420...
416
};
420
};
417
 
421
 
418
 
422
 
419
 
423
 
420
 
424
 
421
rom BYTE str[] = "Johboh är bäst! ;)";
425
rom BYTE str[] = "Johboh är bäst! ;)";
422
 
426
 
423
#endif
427
#endif
424
 
428
 
425
static void mainInit(void);
429
static void mainInit(void);
426
 
430
 
427
 
431
 
428
 
432
 
429
 
433
 
430
 
434
 
431
void main()
435
void main()
432
{
436
{
433
    // Inits
437
    // Inits
434
    mainInit();
438
    mainInit();
435
    canInit();
439
    canInit();
Line 437... Line 441...
437
 
441
 
438
    #ifdef USE_GLCD
442
    #ifdef USE_GLCD
439
        GLCD_CS_IO = 0;
443
        GLCD_CS_IO = 0;
440
        glcdInit();
444
        glcdInit();
441
        GLCD_CS_IO = 1;
445
        GLCD_CS_IO = 1;
-
 
446
    #endif
-
 
447
 
-
 
448
    #ifdef USE_ADC
-
 
449
        adcInit(TRUE,0b1011);
442
    #endif
450
    #endif
443
 
451
 
444
    while(1)
452
    while(1)
445
    {
453
    {
446
        TICK currentTick = tickGet();
454
        TICK currentTick = tickGet();
447
        static TICK tick_led = 0;
455
        static TICK tick_led = 0;
448
        static TICK tick_pic = 0;
456
        static TICK tick_pic = 0;
-
 
457
        static TICK tick_temperature = 0;
-
 
458
        static TICK tick_door = 0;
-
 
459
        static TICK bounce_door = 0;
-
 
460
       
-
 
461
        static BOOL lastDoorValue = FALSE;
-
 
462
        static BOOL getNewTemperature = TRUE;
449
 
463
 
450
        static BYTE picCnt = 0;
464
        static BYTE picCnt = 0;
451
 
465
 
452
        if ((currentTick-tick_led)>(1*TICK_1S))
466
        if ((currentTick-tick_led)>(1*TICK_1S))
453
        {
467
        {
Line 455... Line 469...
455
            tick_led = currentTick;
469
            tick_led = currentTick;
456
        }
470
        }
457
 
471
 
458
        #ifdef USE_GLCD
472
        #ifdef USE_GLCD
459
        if ((currentTick-tick_pic)>(5*TICK_1S))
473
        if ((currentTick-tick_pic)>(5*TICK_1S))
460
        {
474
        {
461
            CAN_PACKET outCp;  
475
            CAN_PACKET outCp;  
462
 
476
 
463
            GLCD_CS_IO = 0;
477
            GLCD_CS_IO = 0;
464
            glcdSetStartLine(0x00);
478
            glcdSetStartLine(0x00);
465
            glcdClearScr();
479
            glcdClearScr();
466
            if (picCnt==0) glcdDisplayPic(0,0,pic);
480
            if (picCnt==0) glcdDisplayPic(0,0,pic);
467
            else if (picCnt==1) glcdDisplayPic(0,0,pic2);
481
            else if (picCnt==1) glcdDisplayPic(0,0,pic2);
Line 472... Line 486...
472
            outCp.type      = ptPGM;
486
            outCp.type      = ptPGM;
473
            outCp.pgm.class = pcSENSOR;
487
            outCp.pgm.class = pcSENSOR;
474
            outCp.pgm.id    = pstIR;
488
            outCp.pgm.id    = pstIR;
475
            outCp.length    = 1;
489
            outCp.length    = 1;
476
            outCp.data[0]   = picCnt;
490
            outCp.data[0]   = picCnt;
477
            while(!canSendMessage(outCp,PRIO_HIGH));
491
            while(!canSendMessage(outCp,PRIO_HIGH));
478
 
492
 
479
 
493
 
480
            if (++picCnt>3) picCnt=0;
494
            if (++picCnt>3) picCnt=0;
481
 
495
 
482
            tick_pic = currentTick;
496
            tick_pic = currentTick;
483
        }
497
        }
-
 
498
        #endif
-
 
499
 
-
 
500
        #ifdef USE_ADC
-
 
501
        if ((currentTick-tick_temperature)>(2*TICK_1S) && getNewTemperature==TRUE) // Each 2 second, read temperature.
-
 
502
        {
-
 
503
            adcConvert(TEMPERATURE_OUTSIDE);
-
 
504
            getNewTemperature=FALSE;
-
 
505
            tick_temperature = currentTick;
-
 
506
        }
-
 
507
        #endif
-
 
508
 
-
 
509
        #ifdef USE_ADC
-
 
510
        if (adcDone()) // Has temperature, send it to the bus
-
 
511
        {
-
 
512
            CAN_PACKET outCp;
-
 
513
            BYTE decimal;
-
 
514
            signed char tenth;
-
 
515
 
-
 
516
            temperatureRead(&tenth,&decimal);
-
 
517
           
-
 
518
            outCp.type=ptPGM;
-
 
519
            outCp.pgm.class =pcSENSOR;
-
 
520
            outCp.pgm.id    = pstTEMP_DOOR_OUTSIDE;
-
 
521
            outCp.length    =2;
-
 
522
            outCp.data[1]   = tenth; //  signed 10 an 1 decimal.
-
 
523
            outCp.data[0]   = decimal; //  Decimal value, 0-9
-
 
524
            while(!canSendMessage(outCp,PRIO_HIGH));
-
 
525
 
-
 
526
            getNewTemperature=TRUE;
-
 
527
            tick_temperature = currentTick;
-
 
528
        }
-
 
529
        #endif
-
 
530
 
-
 
531
        #ifdef USE_DOOR_SW
-
 
532
        if ((currentTick-bounce_door)>(3*TICK_100MS) && lastDoorValue != SW1_IO)
-
 
533
        {
-
 
534
            lastDoorValue = SW1_IO;
-
 
535
            tick_door = 0;
-
 
536
            bounce_door = currentTick;
-
 
537
        }
-
 
538
 
-
 
539
        if ((currentTick-tick_door)>(3*TICK_1S))
-
 
540
        {
-
 
541
            CAN_PACKET outCp;  
-
 
542
            outCp.type      = ptPGM;
-
 
543
            outCp.pgm.class = pcSENSOR;
-
 
544
            outCp.pgm.id    = pstDOOR_OUTSIDE;
-
 
545
            outCp.length    = 1;
-
 
546
            outCp.data[0]   = SW1_IO;
-
 
547
            while(!canSendMessage(outCp,PRIO_HIGH));
-
 
548
 
-
 
549
            tick_door = currentTick;
-
 
550
        }
484
        #endif
551
        #endif
-
 
552
 
485
 
553
 
486
    }
554
    }
487
}
555
}
488
 
556
 
489
 
557
 
490
#pragma interrupt high_isr
558
#pragma interrupt high_isr
491
void high_isr(void)
559
void high_isr(void)
492
{
560
{
493
    canISR();
561
    canISR();
-
 
562
 
-
 
563
    #ifdef USE_ROTARY
-
 
564
        if (INTCONbits.INT0IE == 1 && INTCONbits.INT0IF == 1)
-
 
565
        {
-
 
566
            // ROTARY_A_IO panel (nobuss)
-
 
567
            // ROTARY_B_IO panel (nobuss)
-
 
568
            static TICK tick_lastRotation = 0;
-
 
569
 
-
 
570
            if ((tickGet()-tick_lastRotation)>(5*TICK_100MS))
-
 
571
            {  
-
 
572
                 if (ROTARY_A_IO==1 && ROTARY_B_IO==0)
-
 
573
                {
-
 
574
                    // action
-
 
575
                    // left
-
 
576
                }
-
 
577
                else if (ROTARY_A_IO==0 && ROTARY_B_IO==1)
-
 
578
                {
-
 
579
                    // action
-
 
580
                    // Right
-
 
581
                }
-
 
582
                tick_lastRotation=tickGet();
-
 
583
            }
-
 
584
               
-
 
585
            INTCONbits.INT0IF = 0;
-
 
586
        }
-
 
587
    #endif
-
 
588
 
-
 
589
    #ifdef USE_ADC
-
 
590
        adcISR();
-
 
591
    #endif
-
 
592
 
494
}
593
}
495
 
594
 
496
 
595
 
497
#pragma interrupt low_isr
596
#pragma interrupt low_isr
498
void low_isr(void)
597
void low_isr(void)
499
{
598
{
-
 
599
    #ifdef USE_PANEL_SW
-
 
600
        if (INTCON3bits.INT1IE == 1 && INTCON3bits.INT1IF == 1)
-
 
601
        {
-
 
602
            // SW0_IO == panel (nobuss)
-
 
603
            // ROTARY_SW_IO == panel (nobuss)
-
 
604
 
-
 
605
            TICK currentTick = tickGet();
-
 
606
            static TICK tick_lastPanelSw = 0;
-
 
607
            static TICK tick_lastRotSw   = 0;
-
 
608
               
-
 
609
            if (SW0_IO == 0 && (currentTick-tick_lastPanelSw)>(5*TICK_100MS))
-
 
610
            {
-
 
611
                // action
-
 
612
                tick_lastPanelSw = currentTick;
-
 
613
            }
-
 
614
            else if (ROTARY_SW_IO == 0 && (currentTick-tick_lastRotSw)>(5*TICK_100MS))
-
 
615
            {
-
 
616
                // action
-
 
617
                tick_lastRotSw = currentTick;
-
 
618
            }
500
 
619
 
-
 
620
            INTCON3bits.INT1IF = 0;
-
 
621
        }
-
 
622
    #endif
501
}
623
}
502
 
624
 
503
 
625
 
504
 
626
 
505
/*
627
/*
506
*   Function: mainInit
628
*   Function: mainInit
Line 512... Line 634...
512
*   Depends: none.
634
*   Depends: none.
513
*/
635
*/
514
void mainInit()
636
void mainInit()
515
{
637
{
516
    LED0_TRIS=0;   
638
    LED0_TRIS=0;   
517
 
639
 
518
    // Enable Interrupts
640
    // Enable Interrupts
519
    INTCONbits.GIEH = 1;
641
    INTCONbits.GIEH = 1;
520
    INTCONbits.GIEL = 1;
642
    INTCONbits.GIEL = 1;
521
 
643
 
522
    // Enable interrupt prirority
644
    // Enable interrupt prirority
523
    RCONbits.IPEN=1;
645
    RCONbits.IPEN=1;
524
   
646
   
-
 
647
    #ifdef USE_ROTARY
-
 
648
        ROTARY_A_TRIS = 1;
-
 
649
        ROTARY_B_TRIS = 1;
-
 
650
        INTCONbits.INT0IF  = 0;
-
 
651
        INTCONbits.INT0IE  = 1;
-
 
652
        INTCON2bits.INTEDG0 = 1; // rising
-
 
653
        // Always high prio
-
 
654
    #endif
-
 
655
 
-
 
656
    #ifdef USE_PANEL_SW
-
 
657
        ROTARY_SW_TRIS = 1;
-
 
658
        SW0_TRIS = 1;
-
 
659
        INTCON3bits.INT1IF = 0;
-
 
660
        INTCON3bits.INT1IE = 1;
-
 
661
        INTCON2bits.INTEDG1 = 0; // falling
-
 
662
        INTCON3bits.INT1IP  = 0; // low
-
 
663
    #endif
-
 
664
 
-
 
665
 
-
 
666
    #ifdef USE_DOOR_SW
-
 
667
        SW1_TRIS = 1;
-
 
668
    #endif
525
 
669
 
526
}
670
}
527
 
671
 
528
/*
672
/*
529
*   Function: canParse
673
*   Function: canParse