TCCR1B = 0x00; //stop timerTCNT1H = 0;TCNT1L = 0;
ICR1 = ((Xtalfrequency/8) / 2100); //2100hz carrier generator value 878 for 14.7Mhz
OCR1B = ((Xtalfrequency/8) / 2100)/2; // ICR1 / 2 for %50 PWM waves
TCCR1A = 0x22;
TCCR1B = 0x1A; //start timer
modem_bit = 0;while (modem_bit<18) //wait for all bit waves {
if ((modem_bit%2==0) && ((PINB & (1 2))) ) // wait for 1 on PWM output.
{
if (modem_bit==0) // start bit
{
TCNT1H = 1; // this values creates small delay for increasing the wave width
TCNT1L = 180; // and AFSK decoder can detect this big waves to 1, other small(2100hz) waves 0
}
if (modem_bit>1)
{
if (modem[modem_byte] & (1((modem_bit-2)/2))) // if bit of bte is 1, change the wave width for 1 on AFSK
{
TCNT1H = 1; // this values creates small delay for increasing the wave width
TCNT1L = 180; // and AFSK decoder can detect this big waves to 1, other small(2100hz) waves 0
}
}
modem_bit++;
}
if ((modem_bit%2==1) && (!(PINB & (1 2)))) // wait for 0 on PWM output
{
modem_bit++;
}
}
#include <NewSoftSerial.h>
// Serial output to FrSky wit NewSoftSerial INVERTED
#define RXPIN_F 4
#define TXPIN_F 5
NewSoftSerial FrSkySerialout(RXPIN_F, TXPIN_F, true);
#define DEBUG 2
unsigned long fix_age;
float flat, flon, falt;
int intalt,framecounter;
char char_lat[4];
char char_lon[4];
char char_alt[2];
char gooddata;
long dt36ms,timenow,timeold36ms;
void setup()
{
FrSkySerialout.begin(9600);
framecounter=0;
if(DEBUG>=1) Serial.begin(9600);
flat = 1.234;
flon = 5.678;
falt = 333.888;
intalt = falt;
gooddata='Y';
}
void loop()
{
memcpy(char_lat, &flat, sizeof (flat));
memcpy(char_lon, &flon, sizeof (flon));
memcpy(char_alt, &intalt, sizeof (intalt));
timenow = micros();
dt36ms = timenow - timeold36ms;
// 36ms Loop
if(dt36ms > 36000)
{
if(framecounter%2==0)
{
FrSkySerialout.print("X");
for(int i=0;i<4;i++) FrSkySerialout.print(char_lat[i]);
FrSkySerialout.print(char_lon[0]);
}
if(framecounter%2==1)
{
for(int i=1;i<4;i++) FrSkySerialout.print(char_lon[i]);
for(int i=0;i<2;i++) FrSkySerialout.print(char_alt[i]);
FrSkySerialout.print(gooddata);
}
framecounter++;
if(framecounter==32) framecounter=0;
timeold36ms = micros();
}
}
#include <NewSoftSerial.h>
#include "TinyGPS.h"
// Define TinyGPS parser
TinyGPS gps;
#define DEBUG 1
// Serial input from GPS with HW Serial, due to timing limits at high data rates
#define SERIALSPEED 115200
// Serial Debug-Output
#define RXPIN_G 3
#define TXPIN_G 2
NewSoftSerial serialDebugOut(RXPIN_G, TXPIN_G);
// Serial output to FrSky wit NewSoftSerial INVERTED
#define RXPIN_F 4
#define TXPIN_F 5
NewSoftSerial FrSkySerialout(RXPIN_F, TXPIN_F, true);
unsigned long fix_age;
float flat, flon, falt;
int intalt,framecounter;
char char_lat[4];
char char_lon[4];
char char_alt[2];
char gooddata;
long dt36ms,timeold36ms;
void setup()
{
serialDebugOut.begin(SERIALSPEED);
FrSkySerialout.begin(9600);
Serial.begin(SERIALSPEED);
framecounter=0;
timeold36ms=0;
flat = 1.234;
flon = 5.678;
falt = 333.888;
intalt = falt;
}
void loop()
{
if (Serial.available())
{
uint8_t c = Serial.read();
if(DEBUG==1) serialDebugOut.print(c);
if (gps.encode(c))
{
gps.f_get_position(&flat, &flon, &fix_age);
falt = gps.f_altitude(); // +/- altitude in meters
intalt = falt;
if(fix_age <= 1000)
{
gooddata='Y';
if(DEBUG==2)
{
serialDebugOut.print(flat);
serialDebugOut.print(" ");
serialDebugOut.print(flon);
serialDebugOut.print(" ");
serialDebugOut.println(intalt);
}
}
else
{
gooddata='N';
}
}
}
dt36ms = micros() - timeold36ms;
// 36ms Loop
if(dt36ms > 36000)
{
memcpy(char_lat, &flat, sizeof (flat));
memcpy(char_lon, &flon, sizeof (flon));
memcpy(char_alt, &intalt, sizeof (intalt));
if(framecounter%2==0)
{
FrSkySerialout.print("X");
for(int i=0;i<4;i++) FrSkySerialout.print(char_lat[i]);
FrSkySerialout.print(char_lon[0]);
}
if(framecounter%2==1)
{
for(int i=1;i<4;i++) FrSkySerialout.print(char_lon[i]);
for(int i=0;i<2;i++) FrSkySerialout.print(char_alt[i]);
FrSkySerialout.print(gooddata);
}
framecounter++;
if(framecounter==32) framecounter=0;
timeold36ms = micros();
}
}