Rev 260 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 260 | Rev 275 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 |
|
1 | /********************************************************************* |
| 2 | * |
2 | * |
| 3 | * Main application |
3 | * Main application |
| 4 | * |
4 | * |
| 5 | ********************************************************************* |
5 | ********************************************************************* |
| 6 | * FileName: $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canTemp/Source/Main.c $ |
6 | * FileName: $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canTemp/Source/Main.c $ |
| 7 | * Last changed: $LastChangedDate: 2007-01- |
7 | * Last changed: $LastChangedDate: 2007-01-30 12:34:06 +0100 (Tue, 30 Jan 2007) $ |
| 8 | * By: $LastChangedBy: johboh $ |
8 | * By: $LastChangedBy: johboh $ |
| 9 | * Revision: $Revision: |
9 | * Revision: $Revision: 275 $ |
| 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 | 18 | ||
| 19 | 19 | ||
| 20 | #ifdef USE_ADC |
20 | #ifdef USE_ADC |
| 21 | #include <adc.h> |
21 | #include <adc.h> |
| - | 22 | #endif |
|
| - | 23 | ||
| - | 24 | #ifdef USE_BLINDS |
|
| - | 25 | #include <blinds.h> |
|
| 22 | #endif |
26 | #endif |
| 23 | 27 | ||
| 24 | static void mainInit(void); |
28 | static void mainInit(void); |
| 25 | - | ||
| 26 | 29 | ||
| 27 | void main() |
30 | void main() |
| 28 | { |
31 | { |
| - | 32 | ||
| 29 | static TICK t = 0; |
33 | static TICK t = 0; |
| 30 | CAN_MESSAGE outCm; |
34 | CAN_MESSAGE outCm; |
| - | 35 | ||
| 31 | 36 | ||
| 32 | // Inits |
37 | // Inits |
| 33 | mainInit(); |
38 | mainInit(); |
| - | 39 | ||
| 34 | canInit(); |
40 | canInit(); |
| 35 | 41 | ||
| 36 | #ifdef USE_ADC |
42 | #ifdef USE_ADC |
| 37 | adcInit(TRUE,0b1011); |
43 | adcInit(TRUE,0b1011); |
| 38 | #endif |
44 | #endif |
| - | 45 | ||
| - | 46 | #ifdef USE_BLINDS |
|
| - | 47 | blindsInit(); |
|
| - | 48 | #endif |
|
| 39 | 49 | ||
| 40 | 50 | ||
| 41 | while(1) |
51 | while(1) |
| 42 | { |
52 | { |
| 43 | static TICK t = 0; |
53 | static TICK t = 0; |
| 44 | static TICK temperature = 0; |
54 | static TICK temperature = 0; |
| 45 | static BYTE lastTemperature = TEMPERATURE_INSIDE; |
55 | static BYTE lastTemperature = TEMPERATURE_INSIDE; |
| 46 | 56 | ||
| - | 57 | static TICK blinds = 0; |
|
| 47 | 58 | ||
| 48 | if ((tickGet()-t)>TICK_SECOND) |
59 | if ((tickGet()-t)>TICK_SECOND) |
| 49 | { |
60 | { |
| 50 | LED0_IO=~LED0_IO; |
61 | LED0_IO=~LED0_IO; |
| 51 | t = tickGet(); |
62 | t = tickGet(); |
| 52 | } |
63 | } |
| - | 64 | ||
| - | 65 | if ((tickGet()-blinds)>2*TICK_SECOND) |
|
| - | 66 | { |
|
| - | 67 | //blindsOpen(3000); |
|
| - | 68 | blinds = tickGet(); |
|
| - | 69 | } |
|
| - | 70 | ||
| - | 71 | ||
| 53 | 72 | ||
| 54 | #ifdef USE_ADC |
73 | #ifdef USE_ADC |
| 55 | if ((tickGet()-temperature)>TICK_SECOND*2) // Each 2 second, read temperature. |
74 | if ((tickGet()-temperature)>TICK_SECOND*2) // Each 2 second, read temperature. |
| 56 | { |
75 | { |
| 57 | if (lastTemperature==TEMPERATURE_INSIDE) lastTemperature=TEMPERATURE_OUTSIDE; else lastTemperature=TEMPERATURE_INSIDE; |
76 | if (lastTemperature==TEMPERATURE_INSIDE) lastTemperature=TEMPERATURE_OUTSIDE; else lastTemperature=TEMPERATURE_INSIDE; |
| 58 | adcConvert(lastTemperature); |
77 | adcConvert(lastTemperature); |
| 59 | temperature = tickGet(); |
78 | temperature = tickGet(); |
| 60 | } |
79 | } |
| 61 | #endif |
80 | #endif |
| 62 | 81 | ||
| 63 | 82 | ||
| 64 | #ifdef USE_ADC |
83 | #ifdef USE_ADC |
| 65 | if (adcDone()) // Has temperature, send it to the bus |
84 | if (adcDone()) // Has temperature, send it to the bus |
| 66 | { |
85 | { |
| 67 | BYTE decimal; |
86 | BYTE decimal; |
| 68 | signed char tenth; |
87 | signed char tenth; |
| Line 73... | Line 92... | ||
| 73 | outCm.data_length = 2; |
92 | outCm.data_length = 2; |
| 74 | outCm.data[1] = tenth; // signed 10 an 1 decimal. |
93 | outCm.data[1] = tenth; // signed 10 an 1 decimal. |
| 75 | outCm.data[0] = decimal; // Decimal value, 0-9 |
94 | outCm.data[0] = decimal; // Decimal value, 0-9 |
| 76 | while(!canSendMessage(outCm,PRIO_HIGH)); |
95 | while(!canSendMessage(outCm,PRIO_HIGH)); |
| 77 | } |
96 | } |
| 78 | #endif |
97 | #endif |
| 79 | 98 | ||
| 80 | } |
99 | } |
| 81 | } |
100 | } |
| 82 | 101 | ||
| 83 | 102 | ||
| 84 | #pragma interrupt high_isr |
103 | #pragma interrupt high_isr |
| 85 | void high_isr(void) |
104 | void high_isr(void) |
| 86 | { |
105 | { |
| 87 | canISR(); |
106 | canISR(); |
| - | 107 | ||
| - | 108 | #ifdef USE_BLINDS |
|
| - | 109 | blindsISR(); |
|
| - | 110 | #endif |
|
| 88 | } |
111 | } |
| 89 | 112 | ||
| 90 | 113 | ||
| 91 | #pragma interrupt low_isr |
114 | #pragma interrupt low_isr |
| 92 | void low_isr(void) |
115 | void low_isr(void) |
| Line 108... | Line 131... | ||
| 108 | * Depends: none. |
131 | * Depends: none. |
| 109 | */ |
132 | */ |
| 110 | void mainInit() |
133 | void mainInit() |
| 111 | { |
134 | { |
| 112 | LED0_TRIS=0; |
135 | LED0_TRIS=0; |
| - | 136 | BLINDS0_TRIS=0; |
|
| 113 | 137 | ||
| 114 | // Enable Interrupts |
138 | // Enable Interrupts |
| 115 | INTCONbits.GIEH = 1; |
139 | INTCONbits.GIEH = 1; |
| 116 | INTCONbits.GIEL = 1; |
140 | INTCONbits.GIEL = 1; |
| 117 | 141 | ||