Rev 294 |
Go to most recent revision |
Blame |
Last modification |
View Log
| RSS feed
#include <avr/boot.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "main.h"
#include "timer0.h"
#include "uart0.h"
#include "uart1.h"
#include "fat16.h"
#include "led.h"
#include "menu.h"
#include "printf_P.h"
#include "analog.h"
#include "ubx.h"
#include "button.h"
#ifdef USE_FOLLOWME
int16_t UBat
= 120;
#endif
#define GPS_RX_TIMEOUT 0x0001
int main
(void)
{
static uint16_t GPS_Timer
= 0;
static uint16_t Error
= 0;
// disable interrupts global
cli
();
// disable watchdog
MCUSR
&=~
(1<<WDRF
);
WDTCSR
|= (1<<WDCE
)|(1<<WDE
);
WDTCSR
= 0;
// initalize modules
LED_Init
();
LEDRED_ON
;
TIMER0_Init
();
USART0_Init
();
UBX_Init
();
USART1_Init
();
ADC_Init
();
Button_Init
();
// enable interrupts global
sei
();
LEDRED_OFF
;
#ifdef USE_FOLLOWME
LEDGRN_ON
;
#endif
// try to initialize the FAT 16 filesystem on the SD-Card
Fat16_Init
();
#ifdef USE_SDLOGGER
printf("\r\n\r\nHW: SD-Logger");
#endif
#ifdef USE_FOLLOWME
printf("\r\n\r\nHW: Follow-Me");
#endif
printf("\r\nFollow Me\n\rSoftware:V%d.%d%c ",VERSION_MAJOR
, VERSION_MINOR
, VERSION_PATCH
+ 'a');
printf("\r\n------------------------------");
printf("\r\n");
#ifdef USE_FOLLOWME
BeepTime
= 2000;
#endif
LCD_Clear
();
GPS_Timer
= SetDelay
(1000);
while (1)
{
// check for button action
if(GetButton
())
{
//BeepTime = 200;
Fat16_Init
();
}
// restart ADConversion if ready
if(ADReady
)
{
DebugOut.
Analog[0] = Adc0
;
DebugOut.
Analog[1] = Adc1
;
DebugOut.
Analog[2] = Adc2
;
DebugOut.
Analog[3] = Adc3
;
DebugOut.
Analog[4] = Adc4
;
DebugOut.
Analog[5] = Adc5
;
DebugOut.
Analog[6] = Adc6
;
DebugOut.
Analog[7] = Adc7
;
#ifdef USE_FOLLOWME
// AVcc = 5V --> 5V = 1024 counts
// the voltage at the voltage divider reference point is 0.8V less that the UBat
// because of the silicon diode inbetween.
// voltage divider R2=10K, R3=3K9
// UAdc4 = R3/(R3+R2)*UBat= 3.9/(3.9+10)*UBat = UBat/3.564
UBat
= (3 * UBat
+ (64 * Adc4
) / 368) / 4;
DebugOut.
Analog[8] = UBat
;
#endif
ADReady
= 0;
ADC_Enable
(); // restart ad conversion sequence
}
if(GPSData.
Status == NEWDATA
)
{
Error
&= ~GPS_RX_TIMEOUT
; // clear possible error
GPS_Timer
= SetDelay
(1000); // reset timeout
if(CheckGPSOkay
>= 5)
{
// trigger transmission of FollowMe message here.
CheckGPSOkay
= 0;
}
GPSData.
Status = PROCESSED
;
}
else // invalid or already processed
{
if(CheckDelay
(GPS_Timer
))
{
Error
|= GPS_RX_TIMEOUT
;
}
}
USART0_ProcessRxData
();
USART0_TransmitTxData
();
}
return (1);
}