Subversion Repositories FlightCtrl

Rev

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

Rev 885 Rev 886
Line 1... Line 1...
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) 04.2007 Holger Buss
2
// + Copyright (c) 04.2007 Holger Buss
3
// + Nur für den privaten Gebrauch
3
// + Nur für den privaten Gebrauch
4
// + www.MikroKopter.com
4
// + www.MikroKopter.com
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
7
// + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist. 
7
// + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist.
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
9
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
11
// + Verkauf von Luftbildaufnahmen, usw.
11
// + Verkauf von Luftbildaufnahmen, usw.
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
18
// + eindeutig als Ursprung verlinkt und genannt werden
18
// + eindeutig als Ursprung verlinkt und genannt werden
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
21
// + Benutzung auf eigene Gefahr
21
// + Benutzung auf eigene Gefahr
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
25
// + mit unserer Zustimmung zulässig
25
// + mit unserer Zustimmung zulässig
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
30
// + this list of conditions and the following disclaimer.
30
// + this list of conditions and the following disclaimer.
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
32
// +     from this software without specific prior written permission.
32
// +     from this software without specific prior written permission.
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet 
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
34
// +     for non-commercial use (directly or indirectly)
34
// +     for non-commercial use (directly or indirectly)
35
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
35
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
36
// +     with our written permission
36
// +     with our written permission
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
38
// +     clearly linked as origin 
38
// +     clearly linked as origin
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Line 45... Line 45...
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50
// +  POSSIBILITY OF SUCH DAMAGE. 
50
// +  POSSIBILITY OF SUCH DAMAGE.
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52
#include "main.h"
52
#include <avr/boot.h>
53
 
-
 
54
unsigned char EEPromArray[E2END+1] EEMEM;
-
 
55
unsigned char PlatinenVersion = 10;
-
 
56
unsigned char SendVersionToNavi = 1;
-
 
57
// -- Parametersatz aus EEPROM lesen ---
-
 
58
// number [0..5]   
-
 
59
void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
-
 
60
{
-
 
61
   if (number > 5) number = 5;
-
 
62
   eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * number], length);
-
 
63
}
-
 
64
 
-
 
Line 65... Line -...
65
 
-
 
66
// -- Parametersatz ins EEPROM schreiben ---
53
 
67
// number [0..5]   
-
 
68
void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
-
 
69
{
54
#include <avr/io.h>
70
   if(number > 5) number = 5;  
-
 
71
   eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * number], length);
-
 
72
   eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number);                              // diesen Parametersatz als aktuell merken
-
 
Line -... Line 55...
-
 
55
#include <avr/interrupt.h>
-
 
56
 
-
 
57
#include "main.h"
-
 
58
#include "timer0.h"
73
}
59
#include "timer2.h"
-
 
60
#include "uart.h"
74
 
61
#if defined (__AVR_ATmega644P__)
-
 
62
#include "uart1.h"
-
 
63
#endif
-
 
64
#include "led.h"
-
 
65
#include "menu.h"
75
unsigned char GetActiveParamSetNumber(void)
66
#include "fc.h"
-
 
67
#include "rc.h"
76
{
68
#include "analog.h"
77
 unsigned char set;
69
#include "printf_P.h"
78
 set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]);
70
#ifdef USE_KILLAGREG
-
 
71
#include "mm3.h"
-
 
72
#endif
79
 if(set > 5)
73
#ifdef USE_NAVICTRL
80
  {
74
#include "spi.h"
-
 
75
#endif
81
   set = 2;  
76
#if !defined (USE_KILLAGREG) && !defined (USE_NAVICTRL)
82
   eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], set);                                 // diesen Parametersatz als aktuell merken
77
#include "mk3mag.h"
83
  }
78
#endif
-
 
79
#include "twimaster.h"
Line 84... Line -...
84
 return(set);
-
 
85
}
-
 
86
 
-
 
Line 87... Line -...
87
void CalMk3Mag(void)
-
 
88
{
-
 
89
 static unsigned char stick = 1;
-
 
90
 
-
 
91
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
-
 
92
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
-
 
93
  {
-
 
94
   stick = 1;
-
 
95
   WinkelOut.CalcState++;
80
#include "eeprom.h"
96
   if(WinkelOut.CalcState > 4)
-
 
97
    {
-
 
98
//     WinkelOut.CalcState = 0; // in Uart.c
-
 
99
     beeptime = 1000;
-
 
100
    }
-
 
Line 101... Line 81...
101
   else Piep(WinkelOut.CalcState);
81
#include "_Settings.h"
102
  }
82
 
103
  DebugOut.Analog[19] = WinkelOut.CalcState;
83
 
104
}
84
uint8_t BoardRelease = 10;
105
 
85
 
106
 
86
 
Line 107... Line 87...
107
//############################################################################
87
//############################################################################
-
 
88
//Hauptprogramm
-
 
89
int main (void)
-
 
90
//############################################################################
108
//Hauptprogramm
91
{
109
int main (void)
92
        unsigned int timer;
110
//############################################################################
93
 
111
{
94
        // disable interrupts global
112
        unsigned int timer;
95
        cli();
-
 
96
 
113
 
97
        // get board release
114
        //unsigned int timer2 = 0;
98
    DDRB  = 0x00;
115
    DDRB  = 0x00;
99
    PORTB = 0x00;
116
    PORTB = 0x00;
-
 
117
    for(timer = 0; timer < 1000; timer++); // verzögern
100
    for(timer = 0; timer < 1000; timer++); // make some delay
118
    if(PINB & 0x01) PlatinenVersion = 11; else PlatinenVersion = 10;
101
    if(PINB & (1<<PINB0)) BoardRelease = 11;
119
    DDRC  = 0x81; // SCL
102
    else BoardRelease = 10;
120
    PORTC = 0xff; // Pullup SDA
-
 
121
    DDRB  = 0x1B; // LEDs und Druckoffset
-
 
122
    PORTB = 0x01; // LED_Rot
103
 
123
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
104
        // set LED ports as output
124
    DDRD  |=0x80; // J7
105
        DDRB |= (1<<DDB1)|(1<<DDB0);
Line 125... Line 106...
125
   
106
        ROT_ON;
Line 126... Line 107...
126
        PORTD = 0xF7; // LED
107
        GRN_OFF;
-
 
108
 
-
 
109
        // disable watchdog
-
 
110
    MCUSR &=~(1<<WDRF);
Line 127... Line 111...
127
 
111
    WDTCSR |= (1<<WDCE)|(1<<WDE);
128
   
112
    WDTCSR = 0;
-
 
113
 
-
 
114
    BeepTime = 2000;
-
 
115
 
129
    MCUSR &=~(1<<WDRF);
116
        PPM_in[CH_THRUST] = 0;
130
    WDTCSR |= (1<<WDCE)|(1<<WDE);
117
        StickYaw = 0;
-
 
118
        StickRoll = 0;
-
 
119
        StickPitch = 0;
-
 
120
 
-
 
121
    ROT_OFF;
-
 
122
 
131
    WDTCSR = 0;
123
        // initalize modules
132
 
124
        LED_Init();
133
    beeptime = 2000;
125
    TIMER0_Init();
-
 
126
    TIMER2_Init();
-
 
127
        USART0_Init();
-
 
128
 
-
 
129
        #if defined (__AVR_ATmega644P__)
-
 
130
        if (BoardRelease == 11) USART1_Init();
134
 
131
        #endif
-
 
132
 
-
 
133
    RC_Init();
-
 
134
        ADC_Init();
-
 
135
        I2C_Init();
-
 
136
 
135
        StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0;
137
        #ifdef USE_KILLAGREG
-
 
138
        MM3_Init();
136
 
139
        #endif
Line 137... Line 140...
137
    ROT_OFF;
140
        #ifdef USE_NAVICTRL
138
   
141
        SPI_MasterInit();
139
    Timer_Init();
142
        #endif
140
        UART_Init();
143
        #if !defined (USE_KILLAGREG) && !defined (USE_NAVICTRL)
141
    rc_sum_init();
144
        MK3MAG_Init();
142
        ADC_Init();
145
        #endif
143
        i2c_init();
146
 
Line 144... Line -...
144
        SPI_MasterInit();
-
 
145
   
-
 
146
        sei();
-
 
147
 
-
 
148
    VersionInfo.Hauptversion = VERSION_HAUPTVERSION;
147
 
149
    VersionInfo.Nebenversion = VERSION_NEBENVERSION;
148
        // enable interrupts global
150
    VersionInfo.PCKompatibel = VERSION_KOMPATIBEL;
-
 
151
   
-
 
152
        printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_HAUPTVERSION, VERSION_NEBENVERSION,VERSION_INDEX + 'a');
-
 
153
        printf("\n\r==============================");
-
 
154
        GRN_ON;
-
 
155
 
-
 
156
#define EE_DATENREVISION 70 // wird angepasst, wenn sich die EEPROM-Daten geändert haben
-
 
157
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION)
-
 
158
        {
-
 
Line 159... Line 149...
159
          printf("\n\rInit. EEPROM: Generiere Default-Parameter...");
149
        sei();
160
          DefaultKonstanten1();
150
 
161
          for (unsigned char i=0;i<6;i++)  
151
    VersionInfo.Major = VERSION_MAJOR;
162
      {
152
    VersionInfo.Minor = VERSION_MINOR;
163
       if(i==2) DefaultKonstanten2(); // Kamera
153
    VersionInfo.PCCompatible = VERSION_COMPATIBLE;
164
       if(i==3) DefaultKonstanten3(); // Beginner
154
 
-
 
155
        printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_MAJOR, VERSION_MINOR,VERSION_INDEX + 'a');
-
 
156
        printf("\n\r==============================");
-
 
157
        GRN_ON;
-
 
158
 
-
 
159
        // Parameter set handling
165
       if(i>3)  DefaultKonstanten2(); // Kamera
160
        ParamSet_Init();
-
 
161
 
166
       WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
162
    if(GetParamWord(PID_ACC_PITCH) > 1023)
167
      }
163
     {
168
          eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], 3); // default-Setting
164
       printf("\n\rACC not calibrated!");
169
          eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION);
165
     }
170
        }
166
 
171
 
167
        //wait for a short time (otherwise the RC channel check won't work below)
172
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
168
        timer = SetDelay(500);
173
     {
169
        while(!CheckDelay(timer));
174
       printf("\n\rACC nicht abgeglichen!");
170
 
175
     }
171
 
176
       
172
        #if !defined (USE_KILLAGREG) && !defined (USE_NAVICTRL)
-
 
173
        printf("\n\rSupport for MK3MAG Compass");
-
 
174
        #endif
-
 
175
 
-
 
176
 
-
 
177
        if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)
-
 
178
         {
-
 
179
           printf("\n\rCalibrating air pressure sensor..");
-
 
180
           timer = SetDelay(1000);
-
 
181
       SearchAirPressureOffset();
-
 
182
           while (!CheckDelay(timer));
-
 
183
       printf("OK\n\r");
-
 
184
        }
-
 
185
 
-
 
186
        #ifdef USE_KILLAGREG
-
 
187
        printf("\n\rSupport for MicroMag3 Compass");
-
 
188
        #if defined (__AVR_ATmega644P__)
177
        ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
189
        if(BoardRelease == 10)
Line 178... Line 190...
178
    printf("\n\rBenutze Parametersatz %d", GetActiveParamSetNumber());
190
        {
179
 
191
                printf("\n\rSupport for GPS at 1st UART");
180
   
192
        }
181
        if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
193
        else
182
         {
194
        {
183
           printf("\n\rAbgleich Luftdrucksensor..");
195
                printf("\n\rSupport for GPS at 2nd UART");
184
           timer = SetDelay(1000);  
196
        }
185
       SucheLuftruckOffset();
197
        #else // (__AVR_ATmega644__)
186
           while (!CheckDelay(timer));
198
                printf("\n\rSupport for GPS at 1st UART");
187
       printf("OK\n\r");
199
        #endif
188
        }
200
        #endif
189
       
201
 
190
        SetNeutral();
202
        SetNeutral();
-
 
203
 
191
 
204
        ROT_OFF;
192
        ROT_OFF;
-
 
-
 
205
 
193
   
206
    BeepTime = 2000;
194
    beeptime = 2000;
207
    ExternControl.Digital[0] = 0x55;
195
    ExternControl.Digital[0] = 0x55;   
-
 
196
 
208
 
197
   
209
 
198
        printf("\n\rSteuerung: ");
210
        printf("\n\rControl: ");
199
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
211
        if (ParamSet.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
200
        else printf("Neutral");
-
 
201
       
212
        else printf("Neutral");
202
        printf("\n\n\r");
213
 
-
 
214
        printf("\n\n\r");
203
               
215
 
-
 
216
    LCD_Clear();
204
    LcdClear();
217
 
-
 
218
    I2CTimeout = 5000;
205
    I2CTimeout = 5000;
219
 
206
    WinkelOut.Orientation = 1;
220
        while (1)
207
        while (1)
221
        {
208
        {
222
        if(UpdateMotor)      // control interval
209
       
223
        {
210
                if(UpdateMotor)      // ReglerIntervall
224
                        UpdateMotor=0; // reset Flag, is enabled every 2 ms by isr of timer0
211
            {
225
                        //PORTD |= (1<<PORTD4);
212
                    UpdateMotor=0;
226
            MotorControl();
213
//PORTD |= 0x08;
227
                        //PORTD &= ~(1<<PORTD4);
214
            if(WinkelOut.CalcState) CalMk3Mag();
228
 
215
            else MotorRegler();  
-
 
-
 
229
                        SendMotorData();
216
//PORTD &= ~0x08;
230
 
-
 
231
            ROT_OFF;
-
 
232
 
-
 
233
            if(PcAccess) PcAccess--;
-
 
234
            else
-
 
235
            {
-
 
236
               DubWiseKeys[0] = 0;
-
 
237
               DubWiseKeys[1] = 0;
-
 
238
                           ExternControl.Config = 0;
-
 
239
               ExternStickPitch= 0;
-
 
240
               ExternStickRoll = 0;
-
 
241
               ExternStickYaw = 0;
-
 
242
            }
-
 
243
 
-
 
244
            if(!I2CTimeout)
-
 
245
            {
-
 
246
                                I2CTimeout = 5;
-
 
247
                                I2C_Reset();
-
 
248
                                if((BeepModulation == 0xFFFF) && MotorsOn)
-
 
249
                                {
-
 
250
                                        BeepTime = 10000; // 1 second
-
 
251
                                        BeepModulation = 0x0080;
-
 
252
                                }
-
 
253
                        }
-
 
254
                        else
-
 
255
                        {
217
            SendMotorData();
256
                                I2CTimeout--;
218
            ROT_OFF;
-
 
219
            if(PcZugriff) PcZugriff--;
-
 
220
             else
-
 
221
              {
-
 
222
               DubWiseKeys[0] = 0;
-
 
223
               DubWiseKeys[1] = 0;
257
                                ROT_OFF;
224
                           ExternControl.Config = 0;
-
 
225
               ExternStickNick = 0;
-
 
226
               ExternStickRoll = 0;
-
 
227
               ExternStickGier = 0;
-
 
228
              }
-
 
229
            if(SenderOkay)  SenderOkay--;
-
 
230
            if(!I2CTimeout)
-
 
231
                {
-
 
232
                 I2CTimeout = 5;
-
 
233
                 i2c_reset();
-
 
234
                  if((BeepMuster == 0xffff) && MotorenEin)
-
 
235
                   {
-
 
236
                    beeptime = 10000;
-
 
237
                    BeepMuster = 0x0080;
-
 
238
                   }
258
                        }
239
                }
-
 
240
            else        
-
 
241
                {
-
 
242
                 I2CTimeout--;
-
 
243
                 ROT_OFF;
259
 
244
                }
260
                        if(SIO_DEBUG && (!UpdateMotor || !MotorsOn))
245
            if(SIO_DEBUG && (!UpdateMotor || !MotorenEin))
261
                        {
246
              {
262
                                USART0_TransmitTxData();
-
 
263
                                USART0_ProcessRxData();
247
               DatenUebertragung();
264
                        }
248
               BearbeiteRxDaten();
265
                        else USART0_ProcessRxData();
249
              }
266
 
250
              else BearbeiteRxDaten();
267
                        if(CheckDelay(timer))
251
         if(CheckDelay(timer))
268
                        {
252
            {
-
 
253
            if(UBat < EE_Parameter.UnterspannungsWarnung)
269
                if(UBat < ParamSet.LowVoltageWarning)
254
                {    
-
 
255
                  if(BeepMuster == 0xffff)
270
                {
256
                   {
271
                                        if(BeepModulation == 0xFFFF)
257
                    beeptime = 6000;
272
                                        {
258
                    BeepMuster = 0x0300;
273
                                                BeepTime = 6000; // 0.6 seconds
259
                   }
274
                        BeepModulation = 0x0300;
260
                }
275
                                        }
-
 
276
                }
261
/*           if(SendVersionToNavi)
277
                                #ifdef USE_NAVICTRL
-
 
278
                                SPI_StartTransmitPacket();
-
 
279
                                SendSPI = 4;
262
              {
280
                                #endif
263
               SPI_StartTransmitPacket(SPI_CMD_VERSION);//#
281
                                timer = SetDelay(20); // every 20 ms
264
               SendVersionToNavi = 0;
282
            }