Subversion Repositories Projects

Rev

Rev 297 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 297 Rev 303
1
#include <avr/boot.h>
1
#include <avr/boot.h>
2
 
2
 
3
#include <avr/io.h>
3
#include <avr/io.h>
4
#include <avr/interrupt.h>
4
#include <avr/interrupt.h>
5
 
5
 
6
#include "main.h"
6
#include "main.h"
7
#include "timer0.h"
7
#include "timer0.h"
8
#include "uart0.h"
8
#include "uart0.h"
9
#include "uart1.h"
9
#include "uart1.h"
10
#include "fat16.h"
10
#include "fat16.h"
11
#include "led.h"
11
#include "led.h"
12
#include "menu.h"
12
#include "menu.h"
13
#include "printf_P.h"
13
#include "printf_P.h"
14
#include "analog.h"
14
#include "analog.h"
15
#include "ubx.h"
15
#include "ubx.h"
16
#include "button.h"
16
#include "button.h"
17
 
17
 
18
#ifdef USE_FOLLOWME
18
#ifdef USE_FOLLOWME
19
int16_t UBat = 120;
19
int16_t UBat = 120;
-
 
20
int16_t Zellenzahl = 0;
-
 
21
int16_t PowerOn = 0;
-
 
22
int16_t i = 0;
-
 
23
int16_t delay = 0;
20
#endif
24
#endif
21
 
25
 
22
#define GPS_RX_TIMEOUT  0x0001
26
#define GPS_RX_TIMEOUT  0x0001
23
 
27
 
24
 
28
 
25
int main (void)
29
int main (void)
26
{
30
{
27
        static uint16_t GPS_Timer = 0;
31
        static uint16_t GPS_Timer = 0;
28
        static uint16_t Error = 0;
32
        static uint16_t Error = 0;
29
 
33
 
30
        // disable interrupts global
34
        // disable interrupts global
31
        cli();
35
        cli();
32
 
36
 
33
        // disable watchdog
37
        // disable watchdog
34
    MCUSR &=~(1<<WDRF);
38
    MCUSR &=~(1<<WDRF);
35
    WDTCSR |= (1<<WDCE)|(1<<WDE);
39
    WDTCSR |= (1<<WDCE)|(1<<WDE);
36
    WDTCSR = 0;
40
    WDTCSR = 0;
37
 
41
 
38
        // initalize modules
42
        // initalize modules
39
        LED_Init();
43
        LED_Init();
40
        LEDRED_ON;
44
        LEDRED_ON;
41
    TIMER0_Init();
45
    TIMER0_Init();
42
        USART0_Init();
46
        USART0_Init();
43
        UBX_Init();
47
        UBX_Init();
44
        USART1_Init();
48
        USART1_Init();
45
        ADC_Init();
49
        ADC_Init();
46
        Button_Init();
50
        Button_Init();
47
        // enable interrupts global
51
        // enable interrupts global
48
        sei();
52
        sei();
49
 
53
 
50
        LEDRED_OFF;
54
        LEDRED_OFF;
51
        #ifdef USE_FOLLOWME
55
        #ifdef USE_FOLLOWME
52
        LEDGRN_ON;
56
        LEDGRN_ON;
53
        #endif
57
        #endif
54
 
58
 
55
        // try to initialize the FAT 16 filesystem on the SD-Card
59
        // try to initialize the FAT 16 filesystem on the SD-Card
56
        Fat16_Init();
60
        Fat16_Init();
57
 
61
 
58
        #ifdef USE_SDLOGGER
62
        #ifdef USE_SDLOGGER
59
        printf("\r\n\r\nHW: SD-Logger");
63
        printf("\r\n\r\nHW: SD-Logger");
60
        #endif
64
        #endif
61
        #ifdef USE_FOLLOWME
65
        #ifdef USE_FOLLOWME
62
        printf("\r\n\r\nHW: Follow-Me");
66
        printf("\r\n\r\nHW: Follow-Me");
63
        #endif
67
        #endif
64
        printf("\r\nFollow Me\n\rSoftware:V%d.%d%c ",VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a');
68
        printf("\r\nFollow Me\n\rSoftware:V%d.%d%c ",VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a');
65
        printf("\r\n------------------------------");
69
        printf("\r\n------------------------------");
66
        printf("\r\n");
70
        printf("\r\n");
67
 
71
 
68
 
72
 
69
        #ifdef USE_FOLLOWME
73
        #ifdef USE_FOLLOWME
70
        BeepTime = 2000;
74
        //BeepTime = 2000;
71
        #endif
75
        #endif
72
 
76
 
73
    LCD_Clear();
77
    LCD_Clear();
74
 
78
 
75
        GPS_Timer = SetDelay(1000);
79
        GPS_Timer = SetDelay(1000);
76
        while (1)
80
        while (1)
77
        {
81
        {
78
                // check for button action
82
                // check for button action
79
                if(GetButton())
83
                if(GetButton())
80
                {
84
                {
81
                        //BeepTime = 200;
85
                        BeepTime = 200;
82
                        Fat16_Init();
86
                        Fat16_Init();
83
 
87
 
84
                }
88
                }
85
 
89
 
86
                // restart ADConversion if ready
90
                // restart ADConversion if ready
87
                if(ADReady)
91
                if(ADReady)
88
                {
92
                {
89
                        DebugOut.Analog[0] = Adc0;
93
                        DebugOut.Analog[0] = Adc0;
90
                        DebugOut.Analog[1] = Adc1;
94
                        DebugOut.Analog[1] = Adc1;
91
                        DebugOut.Analog[2] = Adc2;
95
                        DebugOut.Analog[2] = Adc2;
92
                        DebugOut.Analog[3] = Adc3;
96
                        DebugOut.Analog[3] = Adc3;
93
                        DebugOut.Analog[4] = Adc4;
97
                        DebugOut.Analog[4] = Adc4;
94
                        DebugOut.Analog[5] = Adc5;
98
                        DebugOut.Analog[5] = Adc5;
95
                        DebugOut.Analog[6] = Adc6;
99
                        DebugOut.Analog[6] = Adc6;
96
                        DebugOut.Analog[7] = Adc7;
100
                        DebugOut.Analog[7] = Adc7;
97
 
101
 
98
                        #ifdef USE_FOLLOWME
102
                        #ifdef USE_FOLLOWME
99
                        // AVcc = 5V --> 5V = 1024 counts
103
                        // AVcc = 5V --> 5V = 1024 counts
100
                        // the voltage at the voltage divider reference point is 0.8V less that the UBat
104
                        // the voltage at the voltage divider reference point is 0.8V less that the UBat
101
                        // because of the silicon diode inbetween.
105
                        // because of the silicon diode inbetween.
102
                        // voltage divider R2=10K, R3=3K9
106
                        // voltage divider R2=10K, R3=3K9
103
                        // UAdc4 = R3/(R3+R2)*UBat= 3.9/(3.9+10)*UBat = UBat/3.564
107
                        // UAdc4 = R3/(R3+R2)*UBat= 3.9/(3.9+10)*UBat = UBat/3.564
104
                        UBat = (3 * UBat + (64 * Adc4) / 368) / 4;
108
                        UBat = (3 * UBat + (64 * Adc4) / 368) / 4;
105
                        DebugOut.Analog[8] = UBat;
109
                        DebugOut.Analog[8] = UBat;
-
 
110
                       
-
 
111
                        // check for zellenzahl
-
 
112
                        if(PowerOn < 100)
-
 
113
                        {
-
 
114
                                if(UBat<=84) Zellenzahl = 2;
-
 
115
                                else Zellenzahl = 3;
-
 
116
                                PowerOn++;
-
 
117
                        }
-
 
118
                        DebugOut.Analog[16] = Zellenzahl;
-
 
119
                        DebugOut.Analog[17] = PowerOn;
-
 
120
                       
-
 
121
                        //show recognised Zellenzahl to user
-
 
122
                        if(i < Zellenzahl && PowerOn >= 100 && BeepTime == 0 && delay > 1000)
-
 
123
                        {
-
 
124
                                BeepTime = 100;
-
 
125
                                i++;
-
 
126
                                delay = 0;
-
 
127
                        }
-
 
128
                        if(delay < 1500) delay++;
-
 
129
                       
-
 
130
                        // monitor battery undervoltage
-
 
131
                        if(UBat < Zellenzahl * 31 && PowerOn >= 100) BeepTime = 200;
106
                        #endif
132
                        #endif
107
                        ADReady = 0;
133
                        ADReady = 0;
108
                        ADC_Enable(); // restart ad conversion sequence
134
                        ADC_Enable(); // restart ad conversion sequence
109
                }
135
                }
110
 
136
 
111
 
137
 
112
                if(GPSData.Status == NEWDATA)
138
                if(GPSData.Status == NEWDATA)
113
                {
139
                {
114
                        Error &= ~GPS_RX_TIMEOUT;       // clear possible error
140
                        Error &= ~GPS_RX_TIMEOUT;       // clear possible error
115
                        GPS_Timer = SetDelay(1000); // reset timeout
141
                        GPS_Timer = SetDelay(1000); // reset timeout
116
                        if(CheckGPSOkay >= 5)
142
                        if(CheckGPSOkay >= 5)
117
                        {
143
                        {
118
                                // trigger transmission of FollowMe message here.
144
                                // trigger transmission of FollowMe message here.
119
 
145
 
120
                                CheckGPSOkay = 0;
146
                                CheckGPSOkay = 0;
121
                        }
147
                        }
122
                        GPSData.Status = PROCESSED;
148
                        GPSData.Status = PROCESSED;
123
                }
149
                }
124
                else // invalid or already processed
150
                else // invalid or already processed
125
                {
151
                {
126
                        if(CheckDelay(GPS_Timer))
152
                        if(CheckDelay(GPS_Timer))
127
                        {
153
                        {
128
                                Error |= GPS_RX_TIMEOUT;
154
                                Error |= GPS_RX_TIMEOUT;
129
                        }
155
                        }
130
                }
156
                }
131
 
157
 
132
                USART0_ProcessRxData();
158
                USART0_ProcessRxData();
133
                USART0_TransmitTxData();
159
                USART0_TransmitTxData();
134
    }
160
    }
135
        return (1);
161
        return (1);
136
}
162
}
137
 
163
 
138
 
164