Rev 130 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 130 | Rev 243 | ||
---|---|---|---|
Line 50... | Line 50... | ||
50 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | #include "main.h" |
52 | #include "main.h" |
Line 53... | Line 53... | ||
53 | 53 | ||
- | 54 | unsigned char EEPromArray[E2END+1] EEMEM; |
|
Line 54... | Line 55... | ||
54 | unsigned char EEPromArray[E2END+1] EEMEM; |
55 | unsigned char PlatinenVersion = 10; |
55 | 56 | ||
56 | // -- Parametersatz aus EEPROM lesen --- |
57 | // -- Parametersatz aus EEPROM lesen --- |
57 | // number [0..5] |
58 | // number [0..5] |
Line 65... | Line 66... | ||
65 | 66 | ||
66 | // -- Parametersatz ins EEPROM schreiben --- |
67 | // -- Parametersatz ins EEPROM schreiben --- |
67 | // number [0..5] |
68 | // number [0..5] |
68 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
69 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
69 | { |
70 | { |
70 | if (number > 5) number = 5; |
71 | if(number > 5) number = 5; |
Line 71... | Line 72... | ||
71 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * number], length); |
72 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * number], length); |
72 | 73 | ||
Line 73... | Line 74... | ||
73 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
74 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
74 | } |
75 | } |
- | 76 | ||
75 | 77 | unsigned char GetActiveParamSetNumber(void) |
|
- | 78 | { |
|
- | 79 | unsigned char set; |
|
- | 80 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
|
- | 81 | if(set > 5) |
|
- | 82 | { |
|
- | 83 | set = 2; |
|
76 | unsigned char GetActiveParamSetNumber(void) |
84 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], set); // diesen Parametersatz als aktuell merken |
Line 77... | Line 85... | ||
77 | { |
85 | } |
78 | return(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET])); |
86 | return(set); |
79 | } |
87 | } |
80 | 88 | ||
81 | //############################################################################ |
89 | //############################################################################ |
82 | //Hauptprogramm |
90 | //Hauptprogramm |
83 | int main (void) |
91 | int main (void) |
84 | //############################################################################ |
- | |
- | 92 | //############################################################################ |
|
- | 93 | { |
|
- | 94 | unsigned int timer; |
|
- | 95 | unsigned int timer2 = 0; |
|
85 | { |
96 | DDRB = 0x00; |
86 | unsigned int timer; |
97 | PORTB = 0x00; |
87 | unsigned int timer2 = 0; |
98 | for(timer = 0; timer < 1000; timer++); // verzögern |
88 | 99 | if(PINB & 0x01) PlatinenVersion = 11; else PlatinenVersion = 10; |
|
89 | DDRC = 0x01; // SCL |
100 | DDRC = 0x81; // SCL |
90 | PORTC = 0xff; // Pullup SDA |
101 | PORTC = 0xff; // Pullup SDA |
Line 91... | Line 102... | ||
91 | DDRB = 0x1B; // LEDs und Druckoffset |
102 | DDRB = 0x1B; // LEDs und Druckoffset |
92 | PORTB = 0x01; // LED_Rot |
103 | PORTB = 0x01; // LED_Rot |
Line 93... | Line 104... | ||
93 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
104 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
94 | DDRD |=0x80; // J7 |
105 | DDRD |=0x80; // J7 |
95 | 106 | ||
Line 116... | Line 127... | ||
116 | 127 | ||
117 | VersionInfo.Hauptversion = VERSION_HAUPTVERSION; |
128 | VersionInfo.Hauptversion = VERSION_HAUPTVERSION; |
118 | VersionInfo.Nebenversion = VERSION_NEBENVERSION; |
129 | VersionInfo.Nebenversion = VERSION_NEBENVERSION; |
Line 119... | Line 130... | ||
119 | VersionInfo.PCKompatibel = VERSION_KOMPATIBEL; |
130 | VersionInfo.PCKompatibel = VERSION_KOMPATIBEL; |
120 | 131 | ||
121 | printf("\n\rFlightControl V%d.%d ", VERSION_HAUPTVERSION, VERSION_NEBENVERSION); |
132 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d ",PlatinenVersion/10,PlatinenVersion%10, VERSION_HAUPTVERSION, VERSION_NEBENVERSION); |
Line -... | Line 133... | ||
- | 133 | printf("\n\r=============================="); |
|
122 | printf("\n\r=============================="); |
134 | GRN_ON; |
123 | GRN_ON; |
135 | |
124 | 136 | #define EE_DATENREVISION 62 // wird angepasst, wenn sich die EEPROM-Daten geändert haben |
|
125 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != 59) // seit V 0.60 |
137 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
126 | { |
138 | { |
127 | printf("\n\rInit. EEPROM: Generiere Default-Parameter..."); |
139 | printf("\n\rInit. EEPROM: Generiere Default-Parameter..."); |
128 | DefaultKonstanten1(); |
140 | DefaultKonstanten1(); |
129 | for (unsigned char i=0;i<6;i++) |
141 | for (unsigned char i=0;i<6;i++) |
130 | { |
142 | { |
131 | if(i==2) DefaultKonstanten2(); |
143 | if(i==2) DefaultKonstanten2(); |
132 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
144 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
133 | } |
145 | } |
Line 134... | Line 146... | ||
134 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], 1); |
146 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], 2); |
135 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], 59); |
147 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
Line 136... | Line 148... | ||
136 | } |
148 | } |
137 | 149 | ||
138 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
150 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
139 | printf("\n\rBenutze Parametersatz %d", GetActiveParamSetNumber()); |
151 | printf("\n\rBenutze Parametersatz %d", GetActiveParamSetNumber()); |
140 | 152 | ||
141 | 153 | ||
142 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
154 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
143 | { |
155 | { |
Line 162... | Line 174... | ||
162 | else printf("Neutral"); |
174 | else printf("Neutral"); |
Line 163... | Line 175... | ||
163 | 175 | ||
Line 164... | Line 176... | ||
164 | printf("\n\n\r"); |
176 | printf("\n\n\r"); |
- | 177 | ||
165 | 178 | LcdClear(); |
|
166 | LcdClear(); |
179 | I2CTimeout = 5000; |
167 | while (1) |
- | |
168 | { |
180 | while (1) |
169 | 181 | { |
|
170 | if (UpdateMotor) // ReglerIntervall |
182 | if (UpdateMotor) // ReglerIntervall |
171 | { |
183 | { |
172 | UpdateMotor=0; |
184 | UpdateMotor=0; |
173 | MotorRegler(); |
185 | MotorRegler(); |
174 | SendMotorData(); |
186 | SendMotorData(); |
175 | ROT_OFF; |
- | |
176 | if(PcZugriff) PcZugriff--; |
187 | ROT_OFF; |
177 | - | ||
178 | if(SenderOkay) SenderOkay--; |
188 | if(PcZugriff) PcZugriff--; |
179 | 189 | if(SenderOkay) SenderOkay--; |
|
180 | if (UBat < EE_Parameter.UnterspannungsWarnung) |
190 | if(!I2CTimeout) |
181 | { |
191 | { |
182 | beeptime = 2000; |
- | |
183 | } |
192 | I2CTimeout = 5; |
184 | 193 | i2c_reset(); |
|
- | 194 | if((BeepMuster == 0xffff) && MotorenEin) |
|
- | 195 | { |
|
185 | if(!Timeout) |
196 | beeptime = 10000; |
186 | { |
197 | BeepMuster = 0x0080; |
187 | i2c_init(); |
198 | } |
188 | } |
199 | } |
- | 200 | else |
|
189 | else |
201 | { |
190 | { |
202 | I2CTimeout--; |
191 | ROT_OFF; |
203 | ROT_OFF; |
192 | } |
- | |
193 | } |
- | |
194 | 204 | } |
|
195 | 205 | } |
|
196 | if(SIO_DEBUG) |
206 | if(SIO_DEBUG) |
197 | { |
207 | { |
198 | DatenUebertragung(); |
208 | DatenUebertragung(); |
199 | BearbeiteRxDaten(); |
209 | BearbeiteRxDaten(); |
200 | } |
210 | } |
201 | else BearbeiteRxDaten(); |
211 | else BearbeiteRxDaten(); |
202 | if(CheckDelay(timer2)) |
212 | if(CheckDelay(timer)) |
- | 213 | { |
|
- | 214 | if(UBat < EE_Parameter.UnterspannungsWarnung) |
|
- | 215 | { |
|
- | 216 | if(BeepMuster == 0xffff) |
|
- | 217 | { |
|
- | 218 | beeptime = 6000; |
|
- | 219 | BeepMuster = 0x0300; |
|
203 | { |
220 | } |
204 | if(MotorenEin) PORTC ^= 0x10; else PORTC &= ~0x10; |
221 | } |
205 | timer = SetDelay(500); |
222 | timer = SetDelay(100); |
206 | } |
223 | } |
207 | } |
224 | } |